iptables forward DNAT转发

1.环境:(3台)
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core) 
client           192.168.157.41
iptables       192.168.157.42
server          192.168.157.43
2.关掉firewalld(3台)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
3.下载iptables并清空现有规则(3台)
[root@localhost ~]# yum -y install iptables iptables-services
[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -F -t nat
[root@localhost ~]# service iptables save
[root@localhost ~]# systemctl restart iptables
4.server主机上搭建测试服务
[root@localhost ~]# yum -y install nginx
5.在做好上面的条件下,我们修改主机,马上就不能用xshell了

  • 对client进行修改 (桥接)

  • 对iptables进行修改 (桥接/nat1)


  • 对server进行修改 (nat1)


6.在防火墙上做ip转发
net.ipv4.ip_forward = 1
sysctl -p
做DNAT转发:
iptables -t nat -A PREROUTING -i ens33 -d 172.16.0.1 -p tcp --dport  80 -j DNAT --to-destination 192.168.0.10
所有的iptables修改需要保存 :
service iptables save
7.清除client和server主机的防火墙策略
iptables -F
iptables -F -t nat
service iptables save
systemctl restart iptables
8.访问测试(访问路由外网ip)
curl 172.16.0.1
总结:client要能ping通路由内网网卡ip/server要能ping通路由外网网卡ip 表示网络配置ok
           剩下的就是iptables了,不要忘记清空client和server主机的iptables并保存(service iptables save)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值