wsl2 设置固定ip

我给您一个新的主意:不要更改IP,而是添加指定的IP。

在Windows 10中,以管理员权限运行CMD或Powershell,然后执行以下两个命令:

::在Ubuntu中添加IP地址192.168.50.16,名为eth0:1

wsl -d Ubuntu-20.40 -u root ip addr add 192.168.50.16/24 broadcast 192.168.50.255 dev eth0 label eth0:1

::在Win10中添加IP地址192.168.50.88

netsh interface ip add address "vEthernet (WSL)" 192.168.50.88 255.255.255.0

将来,访问Ubuntu时将使用192.168.50.16,访问Win10时将使用192.168.50.88。
您可以将上述两行命令另存为.bat文件,然后将其放入引导区,并使其每次自动执行。

 

https://github.com/microsoft/WSL/issues/4210#issuecomment-648570493

 

上一篇:linux配置静态ip


下一篇:1. 安装Ubuntu并更改网卡ip地址