我給您一個新的主意:不要更改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
