同一个网段的两个 ip 无法互相 ping 通,可能是什么原因呢

2022-07-22 11:48:48 +08:00
 NeoZephyr

我有两台虚拟机

cdp: 192.168.64.5

ubuntu@cdp:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:8c:10:91 brd ff:ff:ff:ff:ff:ff
    inet 192.168.64.5/24 brd 192.168.64.255 scope global dynamic enp0s1
       valid_lft 78881sec preferred_lft 78881sec
    inet6 fd96:bec8:dc5e:d1c1:5054:ff:fe8c:1091/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 2591889sec preferred_lft 604689sec
    inet6 fe80::5054:ff:fe8c:1091/64 scope link 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:ee:b9:4f:99 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
ubuntu@cdp:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.64.1    0.0.0.0         UG    100    0        0 enp0s1
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.64.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s1
192.168.64.1    0.0.0.0         255.255.255.255 UH    100    0        0 enp0s1

lab: 192.168.64.6

ubuntu@lab:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:eb:e8:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.64.6/24 brd 192.168.64.255 scope global dynamic enp0s1
       valid_lft 78849sec preferred_lft 78849sec
    inet6 fd96:bec8:dc5e:d1c1:5054:ff:feeb:e87b/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 2591990sec preferred_lft 604790sec
    inet6 fe80::5054:ff:feeb:e87b/64 scope link 
       valid_lft forever preferred_lft forever
3: dum0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether 4a:c8:c0:64:e9:97 brd ff:ff:ff:ff:ff:ff
    inet 192.168.64.10/24 brd 192.168.64.255 scope global dum0
       valid_lft forever preferred_lft forever
    inet6 fe80::48c8:c0ff:fe64:e997/64 scope link 
       valid_lft forever preferred_lft forever
ubuntu@lab:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.64.1    0.0.0.0         UG    100    0        0 enp0s1
192.168.64.0    0.0.0.0         255.255.255.0   U     0      0        0 dum0
192.168.64.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s1
192.168.64.1    0.0.0.0         255.255.255.255 UH    100    0        0 enp0s1

然后我的主机 ip 是 192.168.64.1 。两台虚拟机是可以与主机互相连通的,但是两台虚拟机之间无法联通,出现 ping 超时的情况

而且,从两台虚拟机 ping 公网 ip ,比如百度,是可以通的。我用 arp 命令查看了一下,发现两台虚拟机都获取到了对方的 mac 地址

ubuntu@cdp:~$ arp -a
_gateway (192.168.64.1) at f6:d4:88:98:8c:64 [ether] on enp0s1
? (192.168.64.6) at 52:54:00:eb:e8:7b [ether] on enp0s1

而且,两台机器的 iptables 没有拦截的规则

2988 次点击
所在节点    Linux
13 条回复
Phiiiil
2022-07-22 12:02:39 +08:00
cat /proc/sys/net/ipv4/icmp_echo_ignore_all

看看两台虚拟机是否关闭了 ping
pocketz
2022-07-22 12:02:56 +08:00
路由追踪什么结果?
DarkCat123
2022-07-22 12:54:39 +08:00
192.168.64.1 是一台什么机器? 自己的 linux 服务器的话,是不是没有开转发。
`echo "1" > /proc/sys/net/ipv4/ip_forward`
NeoZephyr
2022-07-22 13:05:10 +08:00
@Phiiiil 并没有啊

```
ubuntu@lab:~$ cat /proc/sys/net/ipv4/icmp_echo_ignore_all
0
```

```
ubuntu@cdp:~$ cat /proc/sys/net/ipv4/icmp_echo_ignore_all
0
```
NeoZephyr
2022-07-22 13:08:57 +08:00
@pocketz 是 traceroute 吗


ubuntu@cdp:~$ traceroute 192.168.64.6
traceroute to 192.168.64.6 (192.168.64.6), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
NeoZephyr
2022-07-22 13:10:52 +08:00
@DarkCat123

192.168.64.1 是我的 macOS 主机,192.168.64.5 和 192.168.64.6 是我主机上的两个虚拟机
riverskyfang
2022-07-22 13:34:05 +08:00
ifconfig dum0 down
nothingistrue
2022-07-22 13:37:46 +08:00
网关 192.168.64.1 ,是从你的宿主机上虚拟的网关,跟真是路由器网关可能会有区别,具体不能只看虚拟机上的网络配置,要看宿主机上的虚拟化配置。
NeoZephyr
2022-07-22 13:46:50 +08:00
@riverskyfang

wow! 可以了!这是为什么?因为 ip 冲突吗,我是为了测试,所以才自己加了一个虚拟网卡





ubuntu@lab:~$ sudo ip link set dum0 down
ubuntu@lab:~$
ubuntu@lab:~$
ubuntu@lab:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:eb:e8:7b brd ff:ff:ff:ff:ff:ff
inet 192.168.64.6/24 brd 192.168.64.255 scope global dynamic enp0s1
valid_lft 74516sec preferred_lft 74516sec
inet6 fd96:bec8:dc5e:d1c1:5054:ff:feeb:e87b/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 2591986sec preferred_lft 604786sec
inet6 fe80::5054:ff:feeb:e87b/64 scope link
valid_lft forever preferred_lft forever
3: dum0: <BROADCAST,NOARP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 4a:c8:c0:64:e9:97 brd ff:ff:ff:ff:ff:ff
ubuntu@lab:~$
ubuntu@lab:~$
ubuntu@lab:~$
ubuntu@lab:~$ ping 192.168.64.5
PING 192.168.64.5 (192.168.64.5) 56(84) bytes of data.
64 bytes from 192.168.64.5: icmp_seq=1 ttl=64 time=4.84 ms
64 bytes from 192.168.64.5: icmp_seq=2 ttl=64 time=0.601 ms
^C
--- 192.168.64.5 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1022ms
rtt min/avg/max/mdev = 0.601/2.722/4.844/2.121 ms
riverskyfang
2022-07-22 13:59:13 +08:00
@NeoZephyr
lab 这台机器上的 192.168.64.0 子网包从 dum0 出去了,你已经贴了你的路由
NeoZephyr
2022-07-22 14:03:59 +08:00
@riverskyfang 嗯,是的

所以说 dum0 这个网卡有问题,没有工作,对吧
huobazi
2022-07-22 16:08:09 +08:00
目标主机可以禁 Ping 的
raysonx
2022-07-23 04:28:39 +08:00
@NeoZephyr dummy interface 有点类似于 loopback ,你可以设置为 /32 掩码来做本地测试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/867960

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX