Created
February 11, 2021 02:18
-
-
Save Spongman/cadc1fcad0a892ca664362d5a4fa6854 to your computer and use it in GitHub Desktop.
reset WSL2 NIC
This file contains hidden or 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
# 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