Skip to content

Instantly share code, notes, and snippets.

@Spongman
Created February 11, 2021 02:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spongman/cadc1fcad0a892ca664362d5a4fa6854 to your computer and use it in GitHub Desktop.
Save Spongman/cadc1fcad0a892ca664362d5a4fa6854 to your computer and use it in GitHub Desktop.
reset WSL2 NIC
# the NAME of the WSL distro: `wsl.exe -l -v`
$distro = "centos7"
# the NAME of the Windows Network Interface: `powershell.exe Get-NetAdapter`
$iface = "LAN"
# static IP address for wsl interface
$address = "192.168.1.3/24"
$gateway = "192.168.1.1"
wsl.exe --shutdown
#wsl.exe -d $distro ip a
Get-NetAdapter | Where-Object -Property Name -Like vEthernet* | Disable-NetAdapter -confirm:$false
Disable-NetAdapter -name $iface -confirm:$false
Disable-NetAdapterBinding -name $iface -componentid vms_pp
Get-VMNetworkAdapter -ManagementOS | Where-Object -Property SwitchName -EQ WSL | Remove-VMNetworkAdapter
Set-VMSwitch wsl -SwitchType Internal
Enable-NetAdapter -name $iface
Set-VMSwitch WSL -NetAdapterName $iface
wsl.exe -d $distro -u root bash -c "ip a flush dev eth0; ip r del default; ip addr add $address dev eth0; ip r add default via $gateway"
#wsl.exe -d $distro -u root bash -c "dhclient ; ip a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment