解决办法
找到 /etc/resolv.conf,可以看到如下内容
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.23.199.1
1
2
3
4
注意看上面那句话,意思是,这个文件是wsl自动生成的,如果要停止生成这个文件,需要将下面的配置添加到 /etc/wsl.conf下面;我还是太年轻了,当我按照上面说的那样照做之后,并且将nameserver 改为 8.8.8.8,TMD重启之后,nameserver 还是172.23.199.1,已经快崩溃了。可以看下当时我wsl.conf 和 resolv.conf 的配置:
# wsl.conf
[network]
generateResolvConf = false
1
2
3
# resolv.conf
nameserver 8.8.8.8
1
2
终极解决办法
sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'