Fixed: Temporary failure in name resolution in WSL2

· 2 min read
Fixed: Temporary failure in name resolution in WSL2

DNS resolution not working in WSL2? Getting messages like "Temporary failure in name resolution" or "Temporary failure resolving..."?

Issue:

abhijit@AwsJunkie:~$ ping www.AwsJunkie.com
ping: www.AwsJunkie.com: Temporary failure in name resolution
abhijit@AwsJunkie:~$ sudo apt update
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
Building dependency tree
Reading state information... Done
57 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

Fix:

Manually add nameserver 8.8.8.8 to /etc/resolv.conf

abhijit@AwsJunkie:~$ sudo nano /etc/resolv.conf
nameserver 8.8.8.8

Turn off  generateResolvConf in /etc/wsl.conf

abhijit@AwsJunkie:~$ sudo nano /etc/wsl.conf
[network]
generateResolvConf = false

Verify

abhijit@AwsJunkie:~$ ping www.AwsJunkie.com
PING www.AwsJunkie.com (172.64.80.1) 56(84) bytes of data.
64 bytes from 172.64.80.1 (172.64.80.1): icmp_seq=1 ttl=57 time=16.1 ms
64 bytes from 172.64.80.1 (172.64.80.1): icmp_seq=2 ttl=57 time=15.5 ms
64 bytes from 172.64.80.1 (172.64.80.1): icmp_seq=3 ttl=57 time=17.9 ms
^C
--- www.AwsJunkie.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 15.451/16.491/17.941/1.056 ms
abhijit@AwsJunkie:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
113 packages can be upgraded. Run 'apt list --upgradable' to see them.

References