Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No internet connection on WSL Ubuntu (Windows Subsystem for Linux) [closed]

Recently I installed WSL Ubuntu 18.04 on my Windows machine, but nothing seems to work properly, because I have no internet access.
I tried a few commands and sudo apt update says 'Connection failed' and ping google.com literally takes forever as you can see in this screenshot:


I also checked nano /etc/resolv.conf and made sure that the nameservers are right, completely disabled Kaspersky and its firewall, disabled Hyper-V, reinstalled WSL a few times and even disabled Windows Defender. Nothing helped.

So do you have any ideas what the issue could be here?

like image 788
LPT0 Avatar asked Jun 10 '20 23:06

LPT0


People also ask

How do you fix the Windows Subsystem for Linux optional component is not enabled please enable it and try again?

The Windows Subsystem for Linux optional component is not enabled: Open Control Panel -> Programs and Features -> Turn Windows Feature on or off -> Check Windows Subsystem for Linux or using the PowerShell cmdlet mentioned at the beginning of this article.


Video Answer


2 Answers

The reason this error occurs is because Windows automatically generates resolv.conf file with wrong nameserver.

To resolve this issue, follow the following steps.

  1. Locate the file by running the following command:

    sudo nano /etc/resolv.conf

You will see the following in the file:

# 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 
  1. Change the nameserver value to 8.8.8.8 and save the file. You should now be able to connect to the internet.
like image 60
Jeffrey Kilelo Avatar answered Sep 22 '22 14:09

Jeffrey Kilelo


Open Command Prompt as an Administrator and type these commands:

netsh winsock reset  netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns 

Reboot your machine.

https://github.com/microsoft/WSL/issues/3438#issuecomment-410518578

like image 26
Sam Avatar answered Sep 24 '22 14:09

Sam