Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 2 tasks
PramSin opened this issue Apr 22, 2024 · 8 comments
Open
1 of 2 tasks

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

PramSin opened this issue Apr 22, 2024 · 8 comments
Labels

Comments

@PramSin
Copy link

PramSin commented Apr 22, 2024

Windows Version

Microsoft Windows [Version 10.0.22631.3447]

WSL Version

2.1.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

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)":

  • Host: 172.16.0.1
  • VM: 172.16.0.2

Use mirrored networkingMode

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

[experimental]
ignoredPorts=22
hostAddressLoopback=true
  1. 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
  1. 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<global>
        inet6 fe80::87e2:fb75:1d53:b934  prefixlen 64  scopeid 0x20<link>
        inet6 2001:da8:8001:7553:eadb:26d5:2317:5c28  prefixlen 64  scopeid 0x0<global>
        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<host>
        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<host>
        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?

Copy link

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 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
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
Copy link
Author

PramSin commented Apr 22, 2024

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

Copy link

Diagnostic information
Multiple log files found

@PramSin
Copy link
Author

PramSin commented May 22, 2024

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

@jcrben
Copy link

jcrben commented Aug 6, 2024

@PramSin try these commands:

  • sudo ip route del 0.0.0.0/1 dev eth2
  • sudo ip route del 128.0.0.0/1 dev eth2

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

@CatalinFetoiu
Copy link
Collaborator

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
Copy link

this is the same
#11115 (comment)

@M4ndr0id
Copy link

https://github.com/M4ndr0id/WSL-HyperV-fix.git
use this to enable forwarding between virtual switches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants