前段时间给自己的win10桌面电脑配置了wsl,今天在连接vpn访问公司内网,在wsl中通过npm install来安装公司某项目的npm包发现公司域名存在dns解析问题。

解决方法

dnsfix () { /mnt/c/Windows/system32/ipconfig.exe /all | grep --color=auto "DNS Servers" | cut -d ":" -f 2 | grep --color=auto -e '^ [0-9]' | sed 's/^/nameserver/' | sudo tee /etc/resolv.conf > /dev/null }

将上面代码放到.zshrc文件中,执行 source .zshrc,再执行dnsfix命令更新dns即可。

参考