Created
April 21, 2022 12:43
-
-
Save antriver/d32431b1626a9074830c6e53936ec0f8 to your computer and use it in GitHub Desktop.
Sets the WSL instance to a static IP address of 192.168.50.2 (from https://github.com/microsoft/WSL/issues/4210#issuecomment-856482892)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wsl -d Ubuntu -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0 | |
wsl -d Ubuntu -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0 | |
wsl -d Ubuntu -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0 | |
wsl -d Ubuntu -u root echo nameserver 1.1.1.1 ^> /etc/resolv.conf | |
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment