1、wsl-ip.bat脚本
@echo on
REM 先关闭虚拟子系统
wsl --shutdown
REM 以下的Ubuntu为第2步查到的Linux子系统名称
REM IP地址根据自己的需要配置
wsl -d Ubuntu-18.04 -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0
wsl -d Ubuntu-18.04 -u root ip addr add 172.30.208.2/24 broadcast 172.30.208.255 dev eth0
wsl -d Ubuntu-18.04 -u root ip route add 0.0.0.0/0 via 172.30.208.1 dev eth0
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 172.30.16.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 172.30.16.0/24;"
REM 启动对应Linux系统
wt -p Ubuntu-18.04
2、service.sh
sudo service ssh --full-restart ## 将该命令保存为service.sh
标签:172.30,默认设置,18.04,ip,WSL,wsl,Ubuntu,Ubuntu18.04
From: https://www.cnblogs.com/kikyoqiang/p/17433310.html