WSL2 is unable to connect to the Internet and find the host address. Due to this, we are unable to access any server using the WSL2, which defeats the purpose of installing Linux in the first place. So, in this post, we will discuss what to do when WSL2 says No Internet Access and is unable to resolve the host address.
Fix WSL2 No Internet Access; Unable to resolve host address
If WSL2 has no Internet Access and is unable to resolve the host address, follow the solutions mentioned below.
- Check your Internet Connection and bandwidth
- Run Network & Internet troubleshooter on Windows
- Shutdown WSL and reset network protocols
- Check the hostname and host file
- Check the resolv.conf file
Let us discuss them in detail.
1] Check your Internet Connection and bandwidth
First of all, we need to check and make sure that there is nothing wrong with the Internet. For that, use one of the free Internet speed testers. If you find that the bandwidth is low, power cycle your router and if that doesn’t work, contact your ISP and ask them to resolve the issue.
2] Run Network and Internet troubleshooter on Windows
If your Internet speed is not an issue, go ahead and run the Network and Internet troubleshooter from the Get Help app. It will detect what’s wrong with your network and then provide you with a remedy. Once your network issue is resolved, go ahead and try WSL. It should work now.
3] Shutdown WSL and reset network protocols
Next up, we need to shut down the Windows Subsystem for Linux and then reset the network protocols that could have been causing this issue in the first place. To do so, you can run the following commands one by one in the Command Prompt (as an admin).
wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns
Once done, check if the issue is resolved.
4] Check the hostname and host file
We need to ensure that the entry of your computer is mentioned in the host file along with the local domain. But first, we need to check the name of the machine. For that, open Settings and go to System > About.
Once you know the name of the computer, open Command Prompt and go to WSL. Then run the following command.
nano /etc/hostname
Input your machine name in capital letters, specifically the one we received earlier. Then remove any information other than your machine name.
Now, run.
nano /etc/hosts
The hosts file should have two rows similar to the ones mentioned below.
127.0.0.1 localhost.localdomain localhost
127.0.1.1 DESKTOP-SOMETHING
Finally, save and exit from the file.
5] Check the resolv.conf file
Windows automatically generates resolv.conf file, but sometimes with the wrong nameserver. We need to check the file and make sure that the nameserver is set to 8.8.8.8, which is Google Public DNS and is free to use. To do the same, follow the steps given below.
First of all, locate the file by running the following command.
sudo nano /etc/resolv.conf
You might see the following entry.
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/resolv.conf # [network] # generateResolvConf = false nameserver xxx.xx.xx
Update the nameserver value to 8.8.8.8 and save the file. You will then be able to connect to the Internet. To prevent WSL from resetting this file when opening future terminals, run the following commands if you are currently connected to the Internet.
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
Finally, check if the issue is resolved.
That’s it!
Read: WSL is not working or starting in Windows 11
How do I fix WSL2 internet problems?
If you are having issues with WSL2’s internet, first of all, check if your host Windows computer is having proper Internet. you can do that using a free Internet speed tester. If there is no issue with your network, reboot your computer along with the router. If you still encounter the same issue, check out the aforementioned guide.
Read: How to update WSL Kernel on Windows 11
How to fix Unable to resolve host?
WSL might fail to resolve the host if the hostname is either not updated or incorrect in the /etc/hosts file. To fix this, update the hostname or FQDN of the Archiving server in the /etc/hosts file and save the changes. Once you have updated the hosts file, try using the sudo command again, and it should work without any issues.
Also Read: How to Run .sh or Shell Script file in Windows 11.