WSL DNS issues

Sometimes my WSL's DNS changed to something weird and it stopped resolving.

/etc/resolv.conf contains the relevant nameservers, usually when WSL breaks this contains some 172. something IP that is not resolving properly.

You can change the nameserver section but that will not keep the settings for a while as WSL reapplies it.

To fix, you need to add the following to /etc/wsl.conf

[network]
generateResolvConf = false

This will stop the WSL from updating the DNS entries on the next WSL boot.

You need to turn it off and start it again using this in an Elevated Powershell: wsl --shutdown After that, open WSL again and the DNS should not be automatically modified.

Now remove the symlink that is the previous /etc/resolv.conf:

sudo rm /etc/resolv.conf

And then create it again and save:

nameserver 8.8.8.8

From now on the DNS entry should stay as is.

© Copyright 2019-2021 by Theocharis Ledakis.