::先停掉wsl实例 wsl --shutdown ::重新拉起,启动ssh服务 wsl -u root -d Ubuntu-20.04 service ssh start :: 固定IP wsl -u root ip addr | findstr "192.168.120.181" > nul if !errorlevel! equ 0 ( echo wsl ip has set ) else ( wsl -u root ip addr add 192.168.120.181/24 broadcast 192.168.120.0 dev eth0 label eth0:1 echo set wsl ip success: 192.168.120.181 )
::windows作为wsl的宿主,在wsl的固定IP的同一网段也给安排另外一个IP ipconfig | findstr "192.168.120.100" > nul if !errorlevel! equ 0 ( echo windows ip has set ) else ( netsh interface ip add address "vEthernet (WSL)" 192.168.120.100 255.255.255.0 echo set windows ip success: 192.168.120.100 )