将流量从物理接口转发到 docker 0 -> 到 docker 容器 eth0

将流量从物理接口转发到 docker 0 -> 到 docker 容器 eth0

我有一个带有 2 个接口卡的 Ubuntu 16.04 桌面。我正在尝试将流量从 Windows 计算机路由到 Ubuntu 计算机的 enp6s0 接口。我已经使用以太网电缆连接了 Windows 机器和 Ubuntu 16.04。

从 Ubuntu 机器的物理接口,我想将相同的流量转发到 docker0(172.17.0.1) 和 docker 容器(172.17.0.2)。

根据我当前的设置,* 我有 docker 容器- 网桥这样它就有2个接口。 eth1是根据ns3项目ip地址配置的。

root@c246ffcf5054:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02  
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:107 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:12491 (12.4 KB)  TX bytes:1802 (1.8 KB)

eth1      Link encap:Ethernet  HWaddr 12:34:88:5d:61:bd  
          inet addr:10.0.0.2  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1066938 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1432799 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1169075120 (1.1 GB)  TX bytes:2534973873 (2.5 GB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:151 errors:0 dropped:0 overruns:0 frame:0
          TX packets:151 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12768 (12.7 KB)  TX bytes:12768 (12.7 KB)

Ubuntu 机器有以下 IP 地址。

docker0   Link encap:Ethernet  HWaddr 02:42:fd:06:5f:68  
          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::42:fdff:fe06:5f68/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25096 errors:0 dropped:0 overruns:0 frame:0
          TX packets:47902 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1342650 (1.3 MB)  TX bytes:76227846 (76.2 MB)

enp5s0    Link encap:Ethernet  HWaddr 68:05:ca:26:6f:0a  
          inet addr:192.168.0.16  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2601:641:481:2020:6a05:caff:fe26:6f0a/64 Scope:Global
          inet6 addr: fe80::6a05:caff:fe26:6f0a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:193989 errors:0 dropped:0 overruns:0 frame:0
          TX packets:109541 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:216544575 (216.5 MB)  TX bytes:12131093 (12.1 MB)
          Interrupt:16 Memory:fbce0000-fbd00000 

enp6s0    Link encap:Ethernet  HWaddr f4:6d:04:1a:76:40  
          inet addr:192.168.100.3  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::f66d:4ff:fe1a:7640/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10064 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4933 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:798388 (798.3 KB)  TX bytes:504172 (504.1 KB)
          Interrupt:18 

我能够从 Ubuntu 机器和 docker 容器 ping Windows 机器。我可以docker 0使用下面的 iptable 从 Windows 机器 ping 和 docker 容器。但是当我在 docker conatiner 中运行 tcpdump 时,没有流量。有人可以帮我解决这个问题吗?谢谢你!

iptables -t nat -I PREROUTING -i enp6s0 -p tcp -j DNAT --to-destination 172.17.0.1

在此输入图像描述

相关内容