有台双网卡的 centos 。
eth0 的外网 IP 为:35.68.21.210 ,内网 IP 为:172.31.11.120 ; eth1 的外网 IP 为:3.112.105.71 ,内网 IP 为:172.31.6.9 。网关都是 172.31.0.1 (慎重考虑起见,真实外网 IP 不是所写的)
现在需要实现的是:将访问 eth0 和 eth1 的 80 端口流量都转发到后端一台服务器的 80 端口。
采用 iptables 实现:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 后端 IP
iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE
默认路由是 eth0
在执行上述操作后,eth0 转发是正常的,访问 http://35.68.21.210 ,可以得到正常的返回。
但 eth1 不能转发。(感觉是路由的原因)
当前路由表如下:
[root@ip-172-31-11-120 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ip-172-31-0-1.a 0.0.0.0 UG 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth1
将默认路由设置为 eth1:
route add default gw 172.31.0.1 dev eth1
执行后,eth1 转发是正常的,但 eth0 转发又不正常。
因为对计算机网络和路由这块没怎么研究,希望能得到专业人士的指导。不胜感谢!
eth0 的外网 IP 为:35.68.21.210 ,内网 IP 为:172.31.11.120 ; eth1 的外网 IP 为:3.112.105.71 ,内网 IP 为:172.31.6.9 。网关都是 172.31.0.1 (慎重考虑起见,真实外网 IP 不是所写的)
现在需要实现的是:将访问 eth0 和 eth1 的 80 端口流量都转发到后端一台服务器的 80 端口。
采用 iptables 实现:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 后端 IP
iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE
默认路由是 eth0
在执行上述操作后,eth0 转发是正常的,访问 http://35.68.21.210 ,可以得到正常的返回。
但 eth1 不能转发。(感觉是路由的原因)
当前路由表如下:
[root@ip-172-31-11-120 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default ip-172-31-0-1.a 0.0.0.0 UG 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth1
将默认路由设置为 eth1:
route add default gw 172.31.0.1 dev eth1
执行后,eth1 转发是正常的,但 eth0 转发又不正常。
因为对计算机网络和路由这块没怎么研究,希望能得到专业人士的指导。不胜感谢!