@echo off
setlocal enabledelayedexpansion
::先停掉可能在跑的wsl实例
wsl –shutdown ubuntu
if !errorlevel! equ 0 (
::检查WSL有没有我需要的IP
wsl -u root ip addr | findstr “192.168.3.100” > nul
if !errorlevel! equ 0 (
echo wsl ip has set
) else (
::IP不存在则绑定IP
wsl -u root ip addr add 192.168.3.100/24 broadcast 192.168.3.255 dev eth0 label eth0:1
echo set wsl ip success: 192.168.3.100
)
::检查宿主机有没有我需要的IP
ipconfig | findstr “192.168.3.200” > nul
if !errorlevel! equ 0 (
echo windows ip has set
) else (
::IP不存在则绑定IP
netsh interface ip add address “vEthernet (WSL)” 192.168.3.200 255.255.255.0
echo set windows ip success: 192.168.3.200
)
)
::为主机设置SSH转发端口
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=192.168.3.100 connectport=22
pause
setlocal enabledelayedexpansion
::先停掉可能在跑的wsl实例
wsl –shutdown ubuntu
if !errorlevel! equ 0 (
::检查WSL有没有我需要的IP
wsl -u root ip addr | findstr “192.168.3.100” > nul
if !errorlevel! equ 0 (
echo wsl ip has set
) else (
::IP不存在则绑定IP
wsl -u root ip addr add 192.168.3.100/24 broadcast 192.168.3.255 dev eth0 label eth0:1
echo set wsl ip success: 192.168.3.100
)
::检查宿主机有没有我需要的IP
ipconfig | findstr “192.168.3.200” > nul
if !errorlevel! equ 0 (
echo windows ip has set
) else (
::IP不存在则绑定IP
netsh interface ip add address “vEthernet (WSL)” 192.168.3.200 255.255.255.0
echo set windows ip success: 192.168.3.200
)
)
::为主机设置SSH转发端口
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=192.168.3.100 connectport=22
pause
© 版权声明
文章版权归作者所有,未经允许请勿转载。