-
Notifications
You must be signed in to change notification settings - Fork 822
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
Choose which physical Nic to be used with the WSL. #4799
Comments
At least, now we can't do it. LxssManager.dll does everything for us. |
I see, thank you for your answering me :) |
This one is arguably a restatement #4150. |
Windows 11 22H2 build 22621 (Pro version at least) # RunAs Administrator
# settings
$switchName="StaticIPs"
$submaskCidrBits=24
$winIp="192.168.10.1"
$wslIp="192.168.10.2"
# WSL path for WSLAttachSwitch.exe, will be downloaded via curl
$exeFile="/mnt/c/Windows/System32/WSLAttachSwitch.exe"
# set / check firewal rules
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow
Get-NetFirewallHyperVVMSetting -PolicyStore ActiveStore -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}'
# create a virtual switch and create the IP address of the windows host
New-VMSwitch -SwitchName $switchName -SwitchType Internal
$netadapter=Get-Netadapter | where-Object Name -Like "*$switchName*"
New-NetIPAddress -PrefixLength $submaskCidrBits -InterfaceIndex $netadapter.ifIndex -IPAddress $winIp
# out of scope / optional : connect other HyperV machines to the VMSwitch
# download WSLAttachSwitch
$cmd = "curl -L -o $exeFile https://github.com/dantmnf/WSLAttachSwitch/releases/download/latest/WSLAttachSwitch.exe"
wsl -u root bash -c $cmd
## UNCOMMENT THIESE LINES IF YOU WANT TO TEST BEFORE MAKING PERMANENT CHANGES
## # attach switch to vm
## $cmd = "sudo $exeFile $switchName"
## wsl bash -c $cmd
## # assign static IP to vm
## $cmd = "sudo ip addr add $wslIp dev eth1"
## wsl bash -c $cmd
## # all the machines connected to $switchName can ping / communicate with each other
## permanent changes using /etc/rc.local and /etc/wsl.conf
# create or append commands to /etc/rc.local
$cmd = "[ ! -f /etc/rc.local ] && echo '#!/bin/sh -e' > /etc/rc.local"
wsl -u root bash -c $cmd
# assign switch to WSL vm
$cmd = "echo $exeFile $switchName | sudo tee -a /etc/rc.local"
wsl bash -c $cmd
# assign ip address to WSL vm
$cmd = "echo 'ip addr add $wslIp dev eth1' >> /etc/rc.local"
wsl -u root bash -c $cmd
# make sure /etc/rc.local is loaded on boot via /etc/wsl.conf
wsl -u root bash -c "sudo chmod u+x /etc/rc.local"
wsl -u root bash -c "echo '[boot]' >> /etc/wsl.conf "
wsl -u root bash -c "echo 'command=/etc/rc.local' >> /etc/wsl.conf "
# Enjoy all machines connected to the switch being able to communicate with each other ! |
Please find below a more textual description of the above script :
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow
Get-NetFirewallHyperVVMSetting -PolicyStore ActiveStore -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}'
File #!/bin/sh -e
/mnt/c/Windows/System32/WSLAttachSwitch.exe VirtualSwitch
# bonus : assign ip address
# ip addr add 192.168.0.2 dev eth1 File [boot]
command=/etc/rc.local Gist in french : https://gist.github.com/micheldiemer/e32a294cd484eff7bcd362bf8f3330b3#file-wsl_hyperv_switch-md |
Hi. Can you please collect networking logs by following the instructions below? |
Is your feature request related to a problem? Please describe.
No.
Describe the solution you'd like
I want to use my wireless card for WSL networking, and my ethernet card for Host networking (windows).
Describe alternatives you've considered
I've tried to set a new external virtual switch, but that didn't work.
I'm using Wsl 2.
The text was updated successfully, but these errors were encountered: