我正在尝试在两台服务器(服务器 A 和服务器 B)之间创建静态路由,我创建了从服务器 B 到服务器 A 的静态路由,这样我就可以 ping 到服务器 A 中的 docker 容器。
服务器A详细信息:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000
link/ether 06:4e:7a:ff:c5:b8 brd ff:ff:ff:ff:ff:ff
inet 172.31.124.249/20 brd 172.31.127.255 scope global dynamic eth0
valid_lft 2327sec preferred_lft 2327sec
inet6 fe80::44e:7aff:feff:c5b8/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:7b:af:4d:e5 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
服务器B详细信息:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000
link/ether 06:35:26:6c:2d:02 brd ff:ff:ff:ff:ff:ff
inet 172.31.126.46/20 brd 172.31.127.255 scope global dynamic eth0
valid_lft 2729sec preferred_lft 2729sec
inet6 fe80::435:26ff:fe6c:2d02/64 scope link
valid_lft forever preferred_lft forever
我做了什么?
我在服务器 B 上创建了静态 ip 路由:
sudo ip route add 172.17.0.0/24 via 172.31.124.249 dev eth0
该命令之后的路由表如下:
ip route show
default via 172.31.112.1 dev eth0
172.17.0.0/24 via 172.31.124.249 dev eth0
172.31.112.0/20 dev eth0 proto kernel scope link src 172.31.126.46
当我尝试从服务器 BI ping 服务器 A 中的 docker 容器时,没有得到任何响应:
ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
^C
--- 172.17.0.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms
关于为什么会发生这种情况有什么想法吗?