开启WSL2的网络镜像模式

powershell -NoProfile -Command "$p=Join-Path $env:USERPROFILE '.wslconfig'; @('[wsl2]','networkingMode=mirrored','dnsTunneling=true','autoProxy=true','','[experimental]','hostAddressLoopback=true') | Set-Content -Path $p -Encoding ASCII; Get-Content $p" && wsl --shutdown

设置默认登陆用户为root(注意替换发行版名称)

wsl -d Ubuntu-26.04 -u root -e bash -c "grep -q '\[user\]' /etc/wsl.conf && sed -i '/\[user\]/!b;n;cdefault=root' /etc/wsl.conf || printf '[user]\ndefault=root\n' >> /etc/wsl.conf" ; wsl --shutdown ; wsl -d Ubuntu-26.04

如果没有一次成功,记得再关闭一下

wsl --shutdown

2026-07-02T10:23:48.png

最后修改:2026 年 09 月 08 日
如果觉得我的文章对你有用,请随意赞赏