- 论坛徽章:
- 2
|
本帖最后由 love5783 于 2016-07-12 16:03 编辑
召唤大神~,场景如下:
我有一台物理主机(4块网卡),可以介入到办公网。物理机上起了一些虚拟机,配置私网IP地址,走的桥接网卡br0,br0走eth0。
物理机的eth1上有办公网IP地址10.10.10.2, 虚拟机的IP地址是20.20.20.2。我想做个NAT,让办公网用户访问10.10.10.2这个IP可以访问到20.20.20.2这个虚拟机。
我添加的iptables规则如下(ip_forward已打开,iptables中其他表没有规则):- [root@vps-1 ~]# iptables -t nat -nvL
- Chain PREROUTING (policy ACCEPT 27709 packets, 2459K bytes)
- pkts bytes target prot opt in out source destination
- 0 0 DNAT all -- * * 0.0.0.0/0 10.10.10.2 to:20.20.20.2
- Chain POSTROUTING (policy ACCEPT 54096 packets, 3964K bytes)
- pkts bytes target prot opt in out source destination
- 0 0 SNAT all -- * * 20.20.20.2 0.0.0.0/0 to:10.10.10.2
- Chain OUTPUT (policy ACCEPT 30363 packets, 1825K bytes)
- pkts bytes target prot opt in out source destination
- 0 0 DNAT all -- * * 0.0.0.0/0 10.10.10.2 to:20.20.20.2
复制代码 现在的问题是,从办公网来访问10.10.10.2的流量根本就不走nat的PREROUTING链,可以看到数据包为0。
而如果我把10.10.10.2地址设置到br0上,再用这个iptables,nat就会生效。
我怀疑是多网卡导致的,但是并不明白原理,希望大神们帮忙分析解答,谢谢。
补充:
物理机的路由表如下:- [root@vps-1 ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
- 20.20.20.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
- 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
- 169.254.0.0 0.0.0.0 255.255.0.0 U 1006 0 0 br0
- 0.0.0.0 10.10.10.254 0.0.0.0 UG 0 0 0 eth1
复制代码 虚拟机的网关是20.20.20.254,这个ip是设置在物理主机br0上的。 |
|