$ 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
The solutions found online helped me fix the issue in my home network, but DNS resolution would still not work when using my laptop at the office. This is what seemed to work:
It turned out that /etc/resolv.conf in WSL 1 had a special entry "search our-company-domain.de" (and some ipv4 and ipv6 addresses). One of the ips is the address of our central server. I guess I will also have to turn of the automatic generation of resolv.conf.