#环境说明:Centos7
#ip地址:主机A:192.168.10.100 主机B:172.16.0.103
firewall A: ens32:10.0.0.101 ens33:192.168.10.101
firewall B: ens32:10.0.0.102 ens33:172.16.0.103
环境准备:
1.在firewall A和firewall B添加两块网卡
2.在firewall A和firewall B上开启路由转发
vim /etc/sysctl.conf
#加上下面一行
net.ipv4.ip_forward=1
3.将主机A和主机B的网关分别指向对应的firewall
4.删除firewall上的默认路由
设置iptables规则:
1.firewall A
iptables -t nat -A POSTROUTING -s 192.168.10.100/32 -j MASQUERADE
iptables -t nat -A PREROUTING -d 10.0.0.101 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.10.100:80
2.firewall B
iptables -t nat -A POSTROUTING -s 172.16.0.103-j MASQUERADE
iptables -A PREROUTING -d 10.0.0.102 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.103:80
测试访问: