$ 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
I was able to resolve by configuring a DNS in .yaml file for Netplan located /etc/netplan I created a static IP as well in the process but it is not necessary:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.121.221/24
gateway4: 192.168.121.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
I followed instruction out of the following link: https://linuxize.com/post/how-to-configure-static-ip-address-on-ubuntu-20-04/