microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.16k stars 803 forks source link

Cannot connect Hyper-V VMs(Default Switch) from wsl2 #11494

Open PramSin opened 4 months ago

PramSin commented 4 months ago

Windows Version

Microsoft Windows [Version 10.0.22631.3447]

WSL Version

2.1.5.0

Are you using WSL 1 or WSL 2?

Kernel Version

5.15.146.1

Distro Version

Ubuntu 22.04

Other Software

Hyper-V 10.0.22621.1

Repro Steps

I have a Hyper-V VirtualMachine connected with the VMSwitch "vEthernet (Default Switch)"(an internal switch with NAT). And it works well to access VM networking apps from host or access host networking apps from the VM.

Now I want to connect the VM from my WSL distro. I tried two approaches.

The ip address given by the "vEthernet (Default Switch)":

Use mirrored networkingMode

  1. The .wslconfig file
    
    [wsl2]
    networkingMode=mirrored
    dnsTunneling=true
    firewall=true
    autoProxy=true

[experimental] ignoredPorts=22 hostAddressLoopback=true


2. Restart wsl and try to connect the VM

ping 172.16.0.2

The result is

PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data. From 172.16.0.3 icmp_seq=1 Destination Host Unreachable From 172.16.0.3 icmp_seq=2 Destination Host Unreachable From 172.16.0.3 icmp_seq=3 Destination Host Unreachable From 172.16.0.3 icmp_seq=4 Destination Host Unreachable From 172.16.0.3 icmp_seq=5 Destination Host Unreachable ^C --- 172.16.0.2 ping statistics --- 7 packets transmitted, 0 received, +5 errors, 100% packet loss, time 6280ms pipe 4


#### Use bridged networkingMode

1. The `.wslconfig` file

[wsl2] networkingMode=bridged vmSwitch="Default Switch" ipv6=true


2. Restart wsl and try to connect the VM

ping 172.16.0.2

The result is

ping: connect: Network is unreachable


### Expected Behavior

Get the same `ping` result as the host gets.

Pinging 172.16.0.2 with 32 bytes of data: Reply from 172.16.0.2: bytes=32 time<1ms TTL=64 Reply from 172.16.0.2: bytes=32 time<1ms TTL=64 Reply from 172.16.0.2: bytes=32 time<1ms TTL=64 Reply from 172.16.0.2: bytes=32 time<1ms TTL=64

Ping statistics for 172.16.0.2: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms


### Actual Behavior

#### Use mirrored networkingMode

PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data. From 172.16.0.3 icmp_seq=1 Destination Host Unreachable From 172.16.0.3 icmp_seq=2 Destination Host Unreachable From 172.16.0.3 icmp_seq=3 Destination Host Unreachable From 172.16.0.3 icmp_seq=4 Destination Host Unreachable From 172.16.0.3 icmp_seq=5 Destination Host Unreachable ^C --- 172.16.0.2 ping statistics --- 7 packets transmitted, 0 received, +5 errors, 100% packet loss, time 6280ms pipe 4


#### Use bridged networkingMode

ping: connect: Network is unreachable


### Diagnostic Logs

The `ipconfig` result from host

Ethernet adapter vEthernet (Default Switch):

Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::2848:7b8:601d:94bf%23 IPv4 Address. . . . . . . . . . . : 172.16.0.1 Subnet Mask . . . . . . . . . . . : 255.255.240.0 Default Gateway . . . . . . . . . : 0.0.0.0


#### mirrored networkingMode

`ip addr` result from wsl2

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether b0:22:7a:f4:56:8a brd ff:ff:ff:ff:ff:ff inet 10.155.122.144/24 brd 10.155.122.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 2001:da8:8001:7553:eadb:26d5:2317:5c28/64 scope global nodad deprecated noprefixroute valid_lft forever preferred_lft 0sec inet6 2001:da8:8001:7553:a80e:c45e:91f:b896/128 scope global nodad noprefixroute valid_lft forever preferred_lft forever inet6 fe80::87e2:fb75:1d53:b934/64 scope link nodad noprefixroute valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether a4:42:3b:2d:27:c4 brd ff:ff:ff:ff:ff:ff 4: loopback0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:15:5d:7c:94:29 brd ff:ff:ff:ff:ff:ff 5: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether 00:15:5d:ce:fd:bf brd ff:ff:ff:ff:ff:ff


`ip route` result from wsl2

default via 10.155.122.1 dev eth0 proto kernel metric 35 10.155.122.0/24 dev eth0 proto kernel scope link metric 291 10.155.122.1 dev eth0 proto kernel scope link metric 35


`ifconfig` result from wsl2

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.155.122.144 netmask 255.255.255.0 broadcast 10.155.122.255 inet6 2001:da8:8001:7553:a80e:c45e:91f:b896 prefixlen 128 scopeid 0x0 inet6 fe80::87e2:fb75:1d53:b934 prefixlen 64 scopeid 0x20 inet6 2001:da8:8001:7553:eadb:26d5:2317:5c28 prefixlen 64 scopeid 0x0 ether b0:22:7a:f4:56:8a txqueuelen 1000 (Ethernet) RX packets 7 bytes 526 (526.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 14 bytes 1232 (1.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 8 bytes 1804 (1.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 1804 (1.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

loopback0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 00:15:5d:7c:94:29 txqueuelen 1000 (Ethernet) 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


Seems the mirrored networkingMode didn't clone the VMNetAdapters into the wsl2 distro. So how can I find my VMs from wsl? 

#### birdged networkingMode

`ip addr` result from wsl2

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: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 5e:bb:f6:9e:ee:fa brd ff:ff:ff:ff:ff:ff


`ip route` result from wsl2 (null)

`ifconfig` result from wsl2

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 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



Seems that the bridged networkingMode is not working at all. But I do like it. Any way I can turn it on properly? 
github-actions[bot] commented 4 months ago

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs Download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-wsl-logs.ps1) in an **administrative powershell prompt**: ``` Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1 Set-ExecutionPolicy Bypass -Scope Process -Force .\collect-wsl-logs.ps1 ``` The scipt will output the path of the log file once done. Once completed please upload the output files to this Github issue. [Click here for more info on logging](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method) If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

PramSin commented 4 months ago

The network log for the mirrored mode WslNetworkingLogs-2024-04-22_11-00-25.zip

The network log for the bridged mode WslNetworkingLogs-2024-04-22_11-02-54.zip

github-actions[bot] commented 4 months ago
Diagnostic information ``` Multiple log files found ```
PramSin commented 3 months ago

This issue is still not solved. Can any maintainer give me some feedback?

jcrben commented 2 weeks ago

@PramSin try these commands:

You might need to run ip route to see which one to run

CatalinFetoiu commented 1 week ago

thanks for attaching the logs. sorry for the delay following up on this

at the moment this is not supported when using mirrored networking mode

mirrored mode allows communication between WSL and the Windows host using 127.0.0.1 or using an IPv4 address assigned to the Windows host, but not communication with another VM running on Windows

shigenobuokamoto commented 1 week ago

this is the same https://github.com/microsoft/WSL/issues/11115#issuecomment-2292426024