Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ubuntu under windows subsystem for linux 2 (wsl2) has no internet access

i had an ubuntu under wsl 1 working fine and connecting to the internet

Just by upgrading to wsl2 , I can't ping google.com from bash

but i cand ping if i downgrad to wsl1

here the issue:[WSL2] No network 路 Issue #4731 路 microsoft/WSL


I tried this but not working

Step 1 : open Hyper-V manager as admin

enter image description here

Step 2 : select Virtual Switch Manager From Actions

enter image description here

Step 3 : select WLS

enter image description here

Step 4 : select External Network chose and adapter connect to the internet

enter image description here


my windows ipconfig Ethernet adapter vEthernet (WSL):

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::30a4:2612:6ee3:2390%142
   IPv4 Address. . . . . . . . . . . : 192.168.0.103
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Form ubuntu ping 192.168.0.103

xxxxxxxxx@xxxxxxxxxxx:~$ ping 192.168.0.103
PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
From 172.22.131.55 icmp_seq=1 Destination Host Unreachable
From 172.22.131.55 icmp_seq=2 Destination Host Unreachable

Form ubuntu ip route

xxxxxxxxx@xxxxxxxxxxx:~$ ip route
default via 172.22.128.1 dev eth0 
172.22.128.0/20 dev eth0  proto kernel  scope link  src 172.22.131.55

Form ubuntu tried sudo ip route add default via 192.168.0.103

xxxxxxxxx@xxxxxxxxxx:~$ sudo ip route add default via 192.168.0.103
RTNETLINK answers: Network is unreachable
like image 253
Mohamed Elrashid Avatar asked Jun 16 '20 10:06

Mohamed Elrashid


People also ask

Can you run Ubuntu desktop on WSL2?

But, unfortunately, WSL2 is only a lightweight virtual machine, and you cannot have all those background processes running like a full Ubuntu OS (ex. systemd). Hence, you may not be able to access all Ubuntu settings or run certain apps (ex.

Does WSL2 require virtualization?

While WSL 2 uses Microsoft's Hyper-V as a hypervisor under the hood to run the utility VM, it does not require you to enable Windows' Hyper-V role or feature; WSL works perfectly fine without it.


2 Answers

I was having similar issue. I already tried most of the fixes mentioned in the issues section of its github repo. But, none worked for me permanently.

To temporarily gain access, I created a function which seemed to work for me.

net_activate() {
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
}

I saved it in .bashrc file. Every time I needed to connect, I ran this command.

Yesterday, I was a bit frustrated with this issue and did many things, and now everything is running fine without calling that function.

So, here's the list of thing I did in sequence:

  • Uninstalled all the VPNs I had, and removed their adapters manually.
  • Removed all the Network Adapters (not only VPN, but all listed, including hidden ones) from Device Manager
  • Ran CCleaner and did a custom clean with every check-boxes selected.
  • Did Network Reset. (To do this, simply press "Win + S" and type "network reset")

After restarting my PC, internet in WSL2 was working completely fine.

like image 60
sgalpha01 Avatar answered Oct 17 '22 09:10

sgalpha01


##This a a hack (hot fix) not a permanent solution

Inside ubuntu i had to :

  • add manual ip assignment to network adapter
  • My router Dynamic ip rang 100-200
  • My ip address is 192.168.0.103/255.255.255.0
  • My ip address is 192.168.0.103/24

note you have to enable external network in the wsl hyper-v network virtual switch (see step 1 to 4 in the question )

bash commands :


sudo ip a flush dev eth0
sudo ip a add 192.168.0.5/24 dev eth0
sudo ip r add default via 192.168.0.1

you have to repeat theses command every restart of the vm (or you can script it)

##Ref. :

  • [WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) 路 Issue #4150 路 microsoft/WSL

enter image description here

Note : there is about 14 issues open on the subject of wsl networking so i don't suggest enabling it (on 2020-06-17 maybe it will be better after the issues close)

  • WSL 2 Network configuration 路 Issue #4919 路 microsoft/WSL

  • WSL IP address & Subnet is never deterministic (Constantly changing) 路 Issue #4467 路 microsoft/WSL

  • [WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) 路 Issue #4150 路 microsoft/WSL

  • Questions: implementation of WSL 2 networking 路 Issue #4346 路 microsoft/WSL

  • [WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) 路 Issue #4150 路 microsoft/WSL

  • [WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) 路 Issue #4150 路 microsoft/WSL

  • shayne/go-wsl2-host: Automatically update your Windows hosts file with the WSL2 VM IP address

  • Can not connect to internet in WSL 2 路 Issue #4275 路 microsoft/WSL

  • [WSL2] No network 路 Issue #4731 路 microsoft/WSL

  • [WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) 路 Issue #4150 路 microsoft/WSL

  • Missing network connection in WSL2 after last (windows) update 路 Issue #5414 路 microsoft/WSL

  • No internet connectivity from WSL2/Ubuntu 路 Issue #4926 路 microsoft/WSL

  • Issues 路 microsoft/WSL

  • shayne/go-wsl2-host: Automatically update your Windows hosts file with the WSL2 VM IP address

like image 33
Mohamed Elrashid Avatar answered Oct 17 '22 07:10

Mohamed Elrashid