Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Attempt to fix networking issues described in https://github.com/microsoft/WSL/issues/3438
# Attempt to fix broken network in WSL2.0
$guest_ip = bash -c "/sbin/ifconfig eth0 | egrep -o 'inet [0-9\.]+' | cut -d ' ' -f2"
Write-Output "Guest IP IS: $guest_ip"
$gateway_ips = Get-NetIPAddress -InterfaceAlias "vEthernet (WSL)" | select IPAddress
$gateway_ip = $gateway_ips[1].IPAddress
Write-Output "Gateway (local WSL adapter) IP is: $gateway_ip"
bash -c "sudo ifconfig eth0 netmask 255.255.240.0"
bash -c "sudo ip route add default via $gateway_ip"
@jordansissel

This comment has been minimized.

Copy link

commented Aug 12, 2019

Attempting to reduce this to something that can be run from WSL directly:

 echo '(Get-NetIPAddress -InterfaceAlias "VEthernet (WSL)" | select -last 1).IPAddress' |powershell.exe -NoProfile -NoLogo | grep 192 | tr -d '\r' | read gateway; sudo ifconfig eth0 netmask 255.255.240.0; sudo ip route add default via $gateway; echo "Set gateway to $gateway"
@ConradMearns

This comment has been minimized.

Copy link

commented Aug 26, 2019

Hmm, both failed for me on build 190816
SIOCSIFNETMASK: Cannot assign requested address
the bash script fails the same but also says that the Command line is not complete

@dzhenway

This comment has been minimized.

Copy link

commented Oct 6, 2019

echo '(Get-NetIPAddress -InterfaceAlias "VEthernet (WSL)" | select -last 1).IPAddress' |powershell.exe -NoProfile -NoLogo | grep 192 | tr -d '\r' | read gateway; sudo ifconfig eth0 netmask 255.255.240.0; sudo ip route add default via $gateway; echo "Set gateway to $gateway"

echo '(Get-NetIPAddress -InterfaceAlias "VEthernet (WSL)" | select -last 1).IPAddress' |powershell.exe -NoProfile -NoLogo | grep 192 | tr -d '\r' | read gateway; sudo ifconfig eth0 netmask 255.255.240.0; sudo ip route add default via $gateway; echo "Set gateway to $gateway"
powershell.exe: command not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.