wsl 设置静态ip遇到的一些问题 (安装好后不能联网)

今天安装完 ubuntu 24.04 后不能联网,ping 不通百度

在Windows中的C:\Users目录下创建一个.wslconfig文件

[wsl2]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

wsl 执行

sudo nano /etc/sudoers

找到 %sudo   ALL=(ALL:ALL) ALL, 在它下面添加一行,添上面不管用,hyn 换成你的用户名

hyn ALL=(ALL) NOPASSWD: ALL

配置开机便设置 dns 服务器

sudo nano ~/.bashrc

在文件最后加入下面内容 

sudo sh -c 'echo "nameserver 8.8.8.8
 nameserver 8.8.4.4" > /etc/resolv.conf'

 保存并关闭 wsl,在 cmd 下执行

wsl --shutdown

再启动,可以用 ip addr 查下 ip,ping www.baidu.com

ping 通了

你可能感兴趣的:(tcp/ip,网络协议,网络)