考虑一台带有3个NIC的机器。 两座桥是活跃的; 从eth1到eth0的vlan,从eth3到eth0的另一个vlan。
接口:
auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet manual auto eth0.4 allow-hotplug eth0.4 iface eth0.4 inet manual vlan-raw-device eth0 auto eth0.100 allow-hotplug eth0.100 iface eth0.100 inet manual vlan-raw-device eth0 auto eth1 allow-hotplug eth1 iface eth1 inet manual auto eth3 allow-hotplug eth3 iface eth3 inet manual auto bri4 iface bri4 inet static bridge_ports eth0.4 eth1 address 192.168.4.1 network 192.168.4.0 netmask 255.255.255.0 auto bri100 iface bri100 inet static bridge_ports eth0.100 eth3 address 192.168.100.4 network 192.168.100.0 netmask 255.255.255.0 gateway 192.168.100.3 dns-nameservers 192.168.100.3
所有这一切都有效。 我现在希望将所有从bri4到net的stream量都进行NAT转换。 (因为这是网关的地方)。
我是这样做的:
iptables -t nat -A POSTROUTING -o bri100 -j MASQUERADE
这对于bri4stream量也是100%,但NAT开始发生在从eth3桥接到eth0.100(即两个bri100组件)的stream量上。 这当然是完全不需要的,正在造成我的VoIP服务器的混乱。 显然,iptables正在解释-o bri100,以便在bri100成员中包含桥接stream量。
我如何伪装从bri4到bri100而不是在bri100的组件之间? POSTROUTING中没有-i选项。
在POSTROUTING您可以使用-s来匹配您在内部或外部使用的IP地址范围,以决定是否执行SNAT / MASQUERADE 。 如果您的LAN具有公用IP地址的主机和只有私有地址的主机,这是非常有用的。
在你的具体情况下,虽然看起来这两个范围都是私有的,但并没有什么意义。 如果stream量正在离开您的networking,则两个范围都需要NAT。 如果不离开您的networking,则不需要NAT。
默认情况下,linux通过iptables传递网桥stream量(或ip6stream量的ip6tables)。 有这样的有效的用例,但很多时候它是一个PITA比帮助更多。
你可以通过sysctls禁用这个function
sysctl -w net.bridge.bridge-nf-call-iptables = 0 sysctl -w net.bridge.bridge-nf-call-ip6tables = 0