-
-
Save andrewvc/fe22397c554ac3e6255681bfc864e62e to your computer and use it in GitHub Desktop.
# 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" |
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
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
RTNETLINK answers: File exists
Attempt to fix broken network in WSL2.0
$guest_ip = bash -c "ip a show 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 ip a add 192.168.0.1/255.255.240.0 dev eth0"
bash -c "sudo ip route add default via $gateway_ip"
Attempting to reduce this to something that can be run from WSL directly: