-
Open PowerShell as Administator. Type Get-DnsClientServerAddress (similar to ipconfig /all) Look upon Ethernet. Ignore 0.0.0.0. In my case the only IP is 192.168.1.1
-
In the bash terminal of WSL2: Append following text:
[network]
generateResolvConf = false
to /etc/wsl.conf
-
In a cmd window, run wsl --shutdown
-
Click on restart WSL2
-
Go to /etc/
-
if /etc/resolf.conf file doesn't exist, create one and go to p.9.
-
Run:
sudo lsattr resolv.conf
- If you see -i- in the result, run
sudo chattr -i resolv.conf
(removes immutable attribute)
- Put the following line in the file:
nameserver 192.168.1.1 # Change to match IP from p.1
-
sudo chattr +i resolv.conf (restoring immutable flag)
-
In a cmd window, run wsl --shutdown
-
Click on restart WSL2
-
Open WSL2 bash and type
Try something like
nslookup github.com
It should work now.
Credit: microsoft/WSL#4285 (comment)