Post

WSL2: Temporary Failure in Name Resolution

This post is from 2021 and may be out of date. Newer WSL versions offer dnsTunneling=true under [wsl2] in .wslconfig, which fixes many DNS problems without editing resolv.conf.

from GitHub: Windows Terminal Issue 5420, GitHub: Windows Terminal Issue 5256

In WSL2, run:

1
2
3
4
5
6
7
8
# remove existing resolv.conf symlink that is pointing to a wrong nameserver
sudo rm /etc/resolv.conf
# create a new resolv.conf with a correct nameserver
sudo bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
# stop wsl from regenerating resolv.conf symlink
sudo bash -c 'printf "[network]\ngenerateResolvConf = false" > /etc/wsl.conf'
# make current resolv.conf immutable so that wsl does not delete it
sudo chattr +i /etc/resolv.conf

In powershell, run

1
2
wsl --shutdown
wsl
This post is licensed under CC BY 4.0 by the author.