为什么无法将公共IP转发到docker NAT ip

时间:2016-04-21 08:38:44

标签: networking docker iptables

例如,在物理机上:

# ip addr
5: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ..
    inet 10.32.230.90/24 scope global eth2
       valid_lft forever preferred_lft forever
    inet 10.32.230.61/24 scope global secondary eth2
       valid_lft forever preferred_lft forever
8: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 
    link/ether 02:42:65:1b:b0:25 brd ff:ff:ff:ff:ff:ff
    inet 172.17.42.1/16 scope global docker0

“10.32.230.90”是本机的主要IP,“10.32.230.61”是辅助添加“ip addr add 10.32.230.61/24 dev eth2”。

创建一个名为IP = 172.17.0.10的docker实例后,我添加以下规则以将本机IP与辅助IP连接:

# iptables -A POSTROUTING -j MASQUERADE
# iptables -t nat -A PREROUTING -d 10.32.230.61 -j DNAT --to 172.17.0.10
# echo 1 > /proc/sys/net/ipv4/ip_forward

但它不起作用,因为外部PC仍无法访问10.32.230.61,但可以访问10.32.230.90。解决方案是什么?

(From a certain PC, which IP is, for example, 10.32.230.95)
# ping 10.32.230.90
PING 10.32.230.90 (10.32.230.90) 56(84) bytes of data.
64 bytes from 10.32.230.90: icmp_seq=1 ttl=52 time=280 ms
64 bytes from 10.32.230.90: icmp_seq=2 ttl=52 time=336 ms
^C
# ping 10.32.230.61
(Timeout..)

我确信没有IP冲突:10.32.230.61未被任何其他主机使用。

0 个答案:

没有答案