我有一个 Windows(Windows 10 Enterprise 20H2)网络接口,其静态地址设置为 192.168.1.6。
在 Hyper-V 管理器中,我将 WSL 虚拟交换机设置为连接到“外部网络”,并选择上面提到的接口。
在 WSL2 中我已经安装了“Ubuntu 20.04”。
启动 WSL2 后,我建立了一个桥接器:
sudo ip link add br0 type bridge stp_state 0
sudo ip link set eth0 master br0
sudo ip addr add 192.168.1.254/20 dev br0
sudo ip link set br0 up
我从这里下载了 QEMU 映像:https://people.debian.org/~aurel32/qemu/armhf/(标准版本)并像这样运行:
qemu-system-arm -M vexpress-a9 -kernel /home/lesz/qemu/vmlinuz-3.2.0-4-vexpress -initrd /home/lesz/qemu/initrd.img-3.2.0-4-vexpress -drive if=sd,file=/home/lesz/qemu/debian_wheezy_armhf_standard.qcow2 -append "root=/dev/mmcblk0p2 console=ttyAMA0" -nographic -m 1024 -net nic -net bridge,br=br0
当系统启动时我以 root 身份登录并设置静态 IP:
ip addr add 192.168.1.7/20 dev eth0
在 QEMU 上:
root@debian-armhf:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.7/20 scope global eth0
inet6 fe80::5054:ff:fe12:3456/64 scope link
valid_lft forever preferred_lft forever
root@debian-armhf:~# ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
From 192.168.1.7 icmp_seq=1 Destination Host Unreachable
From 192.168.1.7 icmp_seq=2 Destination Host Unreachable
From 192.168.1.7 icmp_seq=3 Destination Host Unreachable
^C
--- 192.168.1.6 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3015ms
pipe 3
root@debian-armhf:~# ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.1.254: icmp_req=1 ttl=64 time=3.83 ms
64 bytes from 192.168.1.254: icmp_req=2 ttl=64 time=0.592 ms
64 bytes from 192.168.1.254: icmp_req=3 ttl=64 time=0.380 ms
^C
--- 192.168.1.254 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 0.380/1.601/3.831/1.579 ms
在 Ubuntu(WSL2)上
ip addr show
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: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether ce:d0:ba:27:16:6e brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 42:bf:b8:9e:48:29 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 00:15:5d:ae:f5:a6 brd ff:ff:ff:ff:ff:ff
5: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
6: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
12: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:15:5d:ae:f5:a6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.254/20 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:feae:f5a6/64 scope link
valid_lft forever preferred_lft forever
37: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UNKNOWN group default qlen 1000
link/ether fe:d4:42:b8:cd:dd brd ff:ff:ff:ff:ff:ff
inet6 fe80::fcd4:42ff:feb8:cddd/64 scope link
valid_lft forever preferred_lft forever
ip route
192.168.0.0/20 dev br0 proto kernel scope link src 192.168.1.254
cat /proc/sys/net/ipv4/ip_forward
1
ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
64 bytes from 192.168.1.6: icmp_seq=1 ttl=128 time=0.316 ms
64 bytes from 192.168.1.6: icmp_seq=2 ttl=128 time=0.308 ms
64 bytes from 192.168.1.6: icmp_seq=3 ttl=128 time=0.350 ms
^C
--- 192.168.1.6 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2115ms
rtt min/avg/max/mdev = 0.308/0.324/0.350/0.018 ms
ping 192.168.1.7
PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data.
64 bytes from 192.168.1.7: icmp_seq=1 ttl=64 time=0.884 ms
64 bytes from 192.168.1.7: icmp_seq=2 ttl=64 time=0.557 ms
64 bytes from 192.168.1.7: icmp_seq=3 ttl=64 time=0.457 ms
^C
--- 192.168.1.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2058ms
rtt min/avg/max/mdev = 0.457/0.632/0.884/0.182 ms
在 Windows 上:
Ethernet adapter vEthernet (WSL):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::15d3:b518:25fa:e782%24
IPv4 Address. . . . . . . . . . . : 192.168.1.6
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
PS C:\> ping 192.168.1.7
Pinging 192.168.1.7 with 32 bytes of data:
Reply from 192.168.1.6: Destination host unreachable.
Request timed out.
Request timed out.
Ping statistics for 192.168.1.7:
Packets: Sent = 3, Received = 1, Lost = 2 (66% loss),
Control-C
PS C:\> ping 192.168.1.254
Pinging 192.168.1.254 with 32 bytes of data:
Reply from 192.168.1.254: bytes=32 time<1ms TTL=64
Reply from 192.168.1.254: bytes=32 time<1ms TTL=64
Reply from 192.168.1.254: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.1.254:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
附加信息:
似乎仅在一个方向上阻止了流量 - 即 QEMU 回答了 ARP 请求,但是 ARP 答复没有到达 Windows 上的物理接口(同时 QEMU 的 ARP 请求根本没有得到答复):
在 Ubuntu 上:
sudo tcpdump -i eth0
09:27:05.392576 ARP, Request who-has 192.168.1.6 tell 192.168.1.7, length 28
09:27:06.392751 ARP, Request who-has 192.168.1.6 tell 192.168.1.7, length 28
09:27:07.393210 ARP, Request who-has 192.168.1.6 tell 192.168.1.7, length 28
09:27:18.197496 ARP, Request who-has 192.168.1.7 tell 192.168.1.6, length 28
09:27:18.198072 ARP, Reply 192.168.1.7 is-at 52:54:00:12:34:56 (oui Unknown), length 28
09:28:19.206009 ARP, Request who-has 192.168.1.7 tell 192.168.1.6, length 28
09:28:19.206558 ARP, Reply 192.168.1.7 is-at 52:54:00:12:34:56 (oui Unknown), length 28
当我使用 Wireshark 连接到 Windows 上的 WSL 接口时,看不到针对 192.168.1.7 的 ARP 请求。
有人能说出这个设置有什么问题吗?如何让 Windows 和 QEMU 互相看到并 ping 对方?为什么我可以通过桥接接口从 Ubuntu(WSL2)访问两个接口(QEMU 和 Windows),但 ping 不通?