Saturday, May 18, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  35] [ 0]  / answers: 1 / hits: 41005  / 2 Years ago, tue, november 29, 2022, 2:19:09

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?


More From » networking

 Answers
5

I found this solution here


sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

[#1417] Wednesday, November 30, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
attagjump

Total Points: 272
Total Questions: 127
Total Answers: 124

Location: Taiwan
Member since Fri, Sep 17, 2021
3 Years ago
attagjump questions
;