If you use Linux in Windows using WSL (Windows Subsystem for Linux) and you’ve come across this article, you’re probably having an issue where your Linux image can’t get connected to the internet. If you try to perform updates, ping, or any other DNS-related task that requires the system to resolve a hostname, you might find that your Linux image can’t resolve anything.
How To Fix No Internet Connection in WSL
While logged into your Linux image, you can open a Terminal window or continue if you’re using the command line interface. This method should work for all flavors of WSL Linux including Ubuntu, Debian, and Kali.
- Run the command: sudo nano /etc/resolv.conf
- Enter your sudo password
- Look for a line that might be similar to nameserver x.x.x.x
- Change the x.x.x.x to a public DNS server like Quad9 184.108.40.206, Cloudflare 220.127.116.11, or Google 18.104.22.168
- Use Control X to exit and Y to save changes
You should now be able to perform updates, ping, or any other internet-related tasks you want to do within your Linux image. You also might need to open an admin command prompt and run wsl –shutdown and restart your Linux image.
Reset Network To Fix No Internet Connection in WSL
In an admin command prompt or Powershell, run these commands:
- wsl –shutdown
- netsh winsock reset
- netsh int ip reset all
- netsh winhttp reset proxy
- ipconfig /flushdns
Press the Windows key and search for Network Reset, go to the setting and click Reset Now. Finally, restart Windows
Permanently Fix Resolv.conf From Being Overwritten
- Perform the steps above to change the nameserver in /etc/resolv.conf
- Run these two commands which will create a /etc/wsl.conf file and add a few settings:
sudo bash -c ‘echo “[network]” > /etc/wsl.conf’
sudo bash -c ‘echo “generateResolvConf = false” >> /etc/wsl.conf’
- In an admin command prompt, run wsl –shutdown
- Restart your WSL Linux image and you should still have internet access