为网桥设置 iptables,重定向 dns 流量

为网桥设置 iptables,重定向 dns 流量

我正在尝试将网桥上的 DNS 流量转发到本地 DNS 服务器,但没有成功。作为思考练习,我决定阻止所有流量,但这也不起作用。这是我的设置:

#/etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual
iface eth1 inet manual

#allow-hotplug br0
auto br0
iface br0 inet static
bridge_ports eth0 eth1
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1

结果sudo iptables -L(MAC 地址分别为 eth0 和 eth1):

Chain INPUT (policy DROP)
target     prot opt source               destination         
DROP       udp  --  anywhere             anywhere             udp dpt:domain
DROP       tcp  --  anywhere             anywhere             tcp dpt:domain
DROP       all  --  anywhere             anywhere             MAC 10:6A:FD:32:07:7F
DROP       all  --  anywhere             anywhere             MAC B7:23:EC:30:BE:B7

Chain FORWARD (policy DROP)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere      

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere 

结果ifconfig

br0       Link encap:Ethernet  HWaddr 10:6A:FD:32:07:7F 
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: 2602:30a:c038:f980::3ec/128 Scope:Global
          inet6 addr: fe80::129a:ddff:fe41:907d/64 Scope:Link
          inet6 addr: 2602:30a:c038:f980:6806:dd7b:14eb:a2b0/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:558 errors:0 dropped:0 overruns:0 frame:0
          TX packets:83 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:39900 (38.9 KiB)  TX bytes:11753 (11.4 KiB)

eth0      Link encap:Ethernet  HWaddr B7:23:EC:30:BE:B7
          inet addr:169.254.199.229  Bcast:169.254.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:60265 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53413 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:52083764 (49.6 MiB)  TX bytes:12746138 (12.1 MiB)

eth1      Link encap:Ethernet  HWaddr 10:6A:FD:32:07:7F 
          inet addr:169.254.166.137  Bcast:169.254.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:52904 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:11527039 (10.9 MiB)  TX bytes:53215987 (50.7 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:200 errors:0 dropped:0 overruns:0 frame:0
          TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:14428 (14.0 KiB)  TX bytes:14428 (14.0 KiB)  

这只是我不确定的部分,eth0并且eth1收到了随机 IP 地址。

连接设置:

Router -> (eth0)Server(eth1) -> Switch -> devices

服务器是我尝试丢弃所有数据包的地方。但连接到 eth1 的设备能够发送和接收所有流量。我的实际目标是将所有 DNS 流量转发到本地 DNS 服务器。

答案1

通过网桥的流量不一定通过 netfilter。检查 sysctl 的值net.bridge.bridge-nf-call-iptables;如果是0,那么问题就出在这里 — 将其设置为1,一切就都好了。

在内核 3.18 或更高版本中,您可能需要加载模块br_netfilter才能使上述 sysctl 可用。

相关内容