Solve the problem that wsl cannot synchronize the dns information of the local agent

Problem I
opened the company's vpn locally and used the remote wsl plug-in of vscode to connect to wsl1. As a result, some domain names within the company could not be resolved in wsl. After checking, it turned out that wsl could not automatically synchronize the dns information of the local agent.
Wsl2 does not have this problem, and it is a pit of wsl1.

The solution is
basically to copy the dns information in windows to wsl through some scripts, such as:

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 }

Put the above code under .bashrc, source it, and then execute dnsfix to update dns.

Guess you like

Origin blog.csdn.net/xiao__jia__jia/article/details/114946351