我有两台虚拟机
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 没有拦截的规则
1
Phiiiil 2022-07-22 12:02:39 +08:00
cat /proc/sys/net/ipv4/icmp_echo_ignore_all
看看两台虚拟机是否关闭了 ping |
2
pocketz 2022-07-22 12:02:56 +08:00
路由追踪什么结果?
|
3
DarkCat123 2022-07-22 12:54:39 +08:00
192.168.64.1 是一台什么机器? 自己的 linux 服务器的话,是不是没有开转发。
`echo "1" > /proc/sys/net/ipv4/ip_forward` |
4
NeoZephyr OP @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 ``` |
5
NeoZephyr OP @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 * * * |
6
NeoZephyr OP |
7
riverskyfang 2022-07-22 13:34:05 +08:00 1
ifconfig dum0 down
|
8
nothingistrue 2022-07-22 13:37:46 +08:00
网关 192.168.64.1 ,是从你的宿主机上虚拟的网关,跟真是路由器网关可能会有区别,具体不能只看虚拟机上的网络配置,要看宿主机上的虚拟化配置。
|
9
NeoZephyr OP @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 |
10
riverskyfang 2022-07-22 13:59:13 +08:00
@NeoZephyr
lab 这台机器上的 192.168.64.0 子网包从 dum0 出去了,你已经贴了你的路由 |
11
NeoZephyr OP |
12
huobazi 2022-07-22 16:08:09 +08:00
目标主机可以禁 Ping 的
|
13
raysonx 2022-07-23 04:28:39 +08:00 via iPad
@NeoZephyr dummy interface 有点类似于 loopback ,你可以设置为 /32 掩码来做本地测试
|