On WSL 2, when I try to connect to a website, I get an issue:
$ ping www.google.com
ping: www.google.com: Temporary failure in name resolution
Now, to fix this, I had to add /etc/wsl.conf
with this content:
[network]
generateResolvConf = true
And I need to change my /etc/resolv.conf
to:
nameserver 8.8.8.8
This works fine.
However when I restart my system, when I shutdown wsl or do anything similar, /etc/resolv.conf
is overwritten with the previous value.
Of course, if I change /etc/wsl.conf
to the following and restart again:
[network]
generateResolvConf = false
The fix mentioned above is gone again.
So how do I make my changes to /etc/resolv.conf
permanent on WSL 2?
/etc/resolv.conf
is typically a symlink, and gets overwritten by NetPlan / SystemD. When it 'overwrites' the data what do you see inls -al /etc/resolv.conf
? – Thomas Ward Jun 23 '21 at 13:34lrwxrwxrwx 1 root root 29 Jan 25 17:43 /etc/resolv.conf -> ../run/resolvconf/resolv.conf
. I thought that..
was relative to my own directory, so I tried in other directories and it's still../run/resolvconf/resolv.conf
. And I see that that file currently has8.8.8.8
as value anyways. – Olivier Grégoire Jun 23 '21 at 13:38/etc/resolvconf
- somewhere in there is a 'head' file you can configure to have your primary DNS servers yourself ahead of anything set by the system - this is useful because that's how resolvconf works with dynamic network connections (Network Manager) in a base install of Ubuntu. Just for the future so they stay. Edit the head file for resolvconf, those changes are persistent. There may be OTHER items that get created underneath that but you'ill set primary DNS with that way. If that works I'll convert this to an answer – Thomas Ward Jun 23 '21 at 13:56sudo find /run -type f
, returns only/run/resolvconf/resolv.conf
and/run/sudo/ts/myusername
. There is nothing else in there. – Olivier Grégoire Jun 23 '21 at 14:24/run
- note the directory i said in my comment is/etc/resolvconf
, and is not in/run
– Thomas Ward Jun 23 '21 at 14:26/etc/resolv.conf
from the Windows host, unless disabled with the/etc/wsl.conf
mentioned. – NotTheDr01ds Jun 23 '21 at 16:49init
(PID 1) process to hook the interop between WSL and Windows. Most importantly for this question, at least, it's thatinit
on WSL (both 1 and 2) where the networking is set up. Really, there's very little "Ubuntu" involved in that side of things, especially not Systemd. – NotTheDr01ds Jun 23 '21 at 18:30resolv.conf
get overwritten, even with thewsl.conf
? If so, try removing the spaces around the equals sign (generateResolvConf=false
). It's a long shot, but an easy change to try. – NotTheDr01ds Jun 23 '21 at 18:45/run/resolvconf/resolv.conf
is now deleted when I exit/restart wsl – Olivier Grégoire Jun 24 '21 at 07:19/run/resolvconf/resolv.conf
, can you manually create your/etc/resov.conf
successfully? – NotTheDr01ds Jun 27 '21 at 15:31/run/resolvconf/resolv.conf
that was being deleted when you restarted. Was that supposed to be/etc/resolv.conf
, or is it really both that are deleted? – NotTheDr01ds Jun 27 '21 at 16:12/etc/resolv.conf
is a symlink to/run/resolvconf/resolv.conf
. It's the latter that's deleted while the first stays a symlink even when the latter is deleted. – Olivier Grégoire Jun 27 '21 at 16:24wsl --shutdown
in another CMD window and waited a few seconds. Eventually the WSL session was killed. I then restarted WSL Ubuntu and theresolv.conf
was still there. Have not yet tested whether it is retained through laptop reboots. – NeilG May 08 '23 at 00:58