dantmnf / WSLAttachSwitch

Attach the WSL2 virtual machine to a Hyper-V virtual switch.
The Unlicense
107 stars 12 forks source link

Can't Attach: not working after ran it inside WSL or in cmd/powershell #13

Open h888866j opened 4 months ago

h888866j commented 4 months ago

image

image

I have sw2 virtual switch,but after runing WSLAttachSwitch.exe "sw2", it does not change anything inside wsl2

PS C:\Users\August> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
VMware Network Adapte...8 VMware Virtual Ethernet Adapter for ...      20 Up           00-50-56-C0-00-08       100 Mbps
vEthernet (WSL)           Hyper-V Virtual Ethernet Adapter #2          67 Up           00-15-5D-85-86-CF        10 Gbps
vEthernet (sw2)           Hyper-V Virtual Ethernet Adapter #4          83 Up           00-15-5D-B7-01-01        10 Gbps
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter             53 Up           00-15-5D-F1-82-1C        10 Gbps
vEthernet (New Virtual... Hyper-V Virtual Ethernet Adapter #3          75 Up           00-15-5D-B7-01-00        10 Gbps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      14 Disconnected 64-6E-E0-A9-AD-5C         3 Mbps
VMware Network Adapte...1 VMware Virtual Ethernet Adapter for ...       6 Up           00-50-56-C0-00-01       100 Mbps
Ethernet                  Realtek PCIe GbE Family Controller            3 Disconnected 38-F3-AB-D8-FF-0C          0 bps
Wi-Fi                     Intel(R) Wi-Fi 6 AX201 160MHz                 2 Up           64-6E-E0-A9-AD-58       1.3 Gbps

PS C:\Users\August> .\Downloads\WSLAttachSwitch.exe "sw2"
PS C:\Users\August>
Tiklyt commented 3 months ago

@h888866j Try to run WSLAttachSwitch like this, without using cmd: /mnt/c/Users/August/Download/WSLAttachSwitch.exe "sw2"

asilk27 commented 3 months ago

I'm running into the same issue. I've tried many different ways running the WSLAttachSwitch.exe program.

I've tried in WSL2, CMD, PowerShell. I've used both /mnt/c and cmd.exe /c methods. They seem to go through, but when I enter 'ip link'

eth1 does not show. (I created a virtual switch in hyper manager before hand)

asilk27 commented 3 months ago

I think I solved it. Don't use the hypermanager GUI to create the virtual switch. use PowerShell.

run this command in PS to make it:

New-VMSwitch -Name sw2 -NetAdapterName ethernet

Then in the same PowerShell window, cd to where WSLAttachSwitch.exe is saved and run:

.\WSLAttachSwitch.exe "sw2"

After doing this I see eth1 in wsl2 after running: $ ip link

Cheers!