wsl2 突然没法解析域名

背景:
特殊原因使用wsl + vscode 开发python, 使用一段时间后突然无法上网了(dns解析失败), 宿主机能正常上网;
1 查看wsl配置

cat /etc/wsl.conf 
[network]
generateResolvConf = false

2 查看wsl ip配置

3 查看路由信息,找到网关地址

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.21.32.1     0.0.0.0         UG    0      0        0 eth0

4 将网关地址配置到/etc/resolv.conf, 加上dns配置

cat /etc/resolv.conf 
nameserver 172.21.32.1
nameserver 8.8.8.8
nameserver 8.8.4.4

5 测试 ping wwww.baidu.com

posted @ 2024-04-03 16:39  干炸小黄鱼  阅读(181)  评论(0编辑  收藏  举报