$ sudo apt-get update
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
Temporary failure in name rerolution
$ host google.com
;; connection timed out; no servers could be reached
The /etc/resolv.conf is the main configuration file for the DNS name resolver library. It was automatically generated by WSL. Some time there was a problem with that DNS.
- To stop automatic generation of resolv.conf, add the following entry to /etc/wsl.conf:
$ sudo cat << EOF > /etc/wsl.conf
[network]
generateResolvConf = false
EOF
- In a cmd/powershell window, run:
> wsl --shutdown
or:
> wsl --terminate <Distro>
- Restart WSL
- Create a file: /etc/resolv.conf. If it exists (even a link), replace existing one with new file.
sudo cat << EOF > /etc/resolv.conf
# Use one or many DNS servers you like
# nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 1.1.1.1
EOF
- Shutdown and restart WSL again.
cmd/powershell as admin:
> wsl --shutdown
> netsh winsock reset
> netsh int ip reset all
> netsh winhttp reset proxy
> ipconfig /flushdns
Restart Windows.
- Colten Krauter: Fix DNS resolution in WSL2
- RedHat: Chapter 27. Manually configuring the /etc/resolv.conf file
- StackExchange: How do I set my DNS when resolv.conf is being overwritten?
- TechMint: How To Set Permanent DNS Nameservers in Ubuntu and Debian
- rescenic: No network connection in any distribution under WSL 2
This mitigation will works in most of the case, but since it will enforce the DNS server to a public DNS server, DNS resolution of internal network (when using VPN or local network) will not works.
After some investigation on my side, it seems the issues comes from Windows FW. Looks like some rules was bloquing outboud or inboud DNS queries, when send from WSL2.
An easy lookup will be to disable Windows FW either globally or only for the WLS2 vEternet adapter, and try to make a DNS query again; if you've got the DNS response, the issue come from Windows FW.
You will have two choice, either take the time and effort to analyse your FW rules and fix them. or if you are lazy and does not mind to always allow DNS query, add a new inbound/outbound for it (as I've done myself):