网络命名空间 ping 失败

网络命名空间 ping 失败

我正在尝试了解网络命名空间,并为此遵循此docker中的流程邮政创建它们。我创建了一个test命名空间并移至veth-b该命名空间,但似乎无法 ping 通192.168.3.1(请注意,它192.168.2.1工作正常)。接口似乎已启动,问题可能是什么?

sudo ip link add veth-a type veth peer name veth-b
$ ifconfig -a

<other_interfaces>
veth-a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.1  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::f057:76ff:fec4:5104  prefixlen 64  scopeid 0x20<link>
        ether f2:57:76:c4:51:04  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 936 (936.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 55  bytes 8117 (7.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ sudo ip netns exec test ifconfig -a
lo: flags=8<LOOPBACK>  mtu 65536
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth-b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.1  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::58b9:ff:fecc:6fb5  prefixlen 64  scopeid 0x20<link>
        ether 5a:b9:00:cc:6f:b5  txqueuelen 1000  (Ethernet)
        RX packets 58  bytes 8762 (8.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 936 (936.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Ping 失败

$ ping 192.168.3.1
PING 192.168.3.1 (192.168.3.1) 56(84) bytes of data.
^C
--- 192.168.3.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2074ms

ping 成功

$ ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.043 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.041 ms
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.049 ms
^C64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.070 ms
$ ip route
default via 192.168.1.1 dev wlp4s0 proto dhcp src 192.168.1.138 metric 600 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 
192.168.1.0/24 dev wlp4s0 proto kernel scope link src 192.168.1.138 metric 600 
192.168.2.0/24 dev veth-a proto kernel scope link src 192.168.2.1 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 

我尝试添加一条路线 sudo ip route add 192.168.3.0/24 dev veth-a但也没有帮助。

更新 在测试网络命名空间中启动后。我不知道为什么它会抱怨 192.168.2.1 无法访问。即使没有直接 ping 到,在博客中列出的正确阶段lo启动是否重要?lo

$ ping 192.168.3.1
PING 192.168.3.1 (192.168.3.1) 56(84) bytes of data.
From 192.168.2.1 icmp_seq=1 Destination Host Unreachable
From 192.168.2.1 icmp_seq=2 Destination Host Unreachable
From 192.168.2.1 icmp_seq=3 Destination Host Unreachable
From 192.168.2.1 icmp_seq=4 Destination Host Unreachable
From 192.168.2.1 icmp_seq=5 Destination Host Unreachable
From 192.168.2.1 icmp_seq=6 Destination Host Unreachable

相关内容