WSL2 network unreachable [closed]
Asked Answered
L

7

32

A couple of weeks ago, WSL suddenly could not reach any IP addresses nor resolve any domains. Even internal network IPs are not reachable.

>lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

❯ neofetch
            .-/+oossssoo+/-.               klewis@NOTEBOOK-KLEWIS
        `:+ssssssssssssssssss+:`           ----------------------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 20.04.1 LTS on Windows 10 x86_64
    .ossssssssssssssssssdMMMNysssso.       Kernel: 5.4.72-microsoft-standard-WSL2
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 1 hour, 20 mins
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 1405 (dpkg)
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.8
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Adwaita [GTK3]
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Icons: Adwaita [GTK3]
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Terminal: Windows Terminal
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: Intel i7-7820HK (8) @ 2.903GHz
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Memory: 968MiB / 5942MiB
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Font: Cantarell 11 [GTK3]
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.
❯ ifconfig

❯ ccat /etc/resolv.conf
nameserver 9.9.9.9
nameserver 8.8.8.8

❯ ccat /etc/wsl.conf
[user]
default=klewis

# Now make it look like this and save the file when you're done:
[automount]
root = /
options = "metadata"

[network]
generateResolvConf = false
❯ ping 127.0.0.1
ping: connect: Network is unreachable
❯ ping 192.168.0.1
ping: connect: Network is unreachable
❯ ping 8.8.8.8
ping: connect: Network is unreachable
❯ ping google.com
ping: google.com: Temporary failure in name resolution
❯ nslookup google.com 9.9.9.9
net.c:536: probing sendmsg() with IP_TOS=b8 failed: Network is unreachable
;; connection timed out; no servers could be reached

❯ ip route
Error: ipv4: FIB table does not exist.
Dump terminated

❯ ip addr show
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 86:9a:be:53:f0:44 brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 1e:ff:ad:a4:c4:a7 brd ff:ff:ff:ff:ff:ff
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:15:5d:b7:f4:da brd ff:ff:ff:ff:ff:ff
C:\> ipconfig
Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #7
   Physical Address. . . . . . . . . : 00-15-5D-E5-0C-1B
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::1962:7d4e:a75e:8d62%78(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.16.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 1308628317
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-27-B3-1F-34-9C-B6-D0-DD-8C-CF
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled
>sudo ip route add default via 192.168.16.1
Error: Nexthop has invalid gateway.

I have looked through GH and found solutions that worked for others. Things I have tried:

  • netsh winsock reset
    netsh int ip reset all
    netsh winhttp reset proxy
    ipconfig /flushdns
    
  • deleted Hyper-V virtual adapters and restarting to let Windows rebuild

  • Changed where the Virtual Switch connects to in Hyper-V Virtual Switch Manager from Internal Network to External Network

  • Ensured %TEMP% is not compressed

  • Ensured no file nor folder under %TEMP% were compressed

  • Ensured no firewall was running

  • https://github.com/microsoft/WSL/issues/4926

  • https://github.com/microsoft/WSL/issues/4731

  • turned off Generation of resolv.conf and add gateway, 9.9.9.9 and 8.8.8.8 to resolv.conf

Lillielilliputian answered 23/2, 2021 at 17:56 Comment(8)
Technically, I think this should be on Super User or Unix & Linux Stack, but I know it's kind of hard to argue that since this one that you've seen lives here. Upvoted the question because you definitely have done your research. Wish I had some ideas for you.Brussels
I actually sat on this for about a day, debating whether to put it here. Also debated cross-posting, but the protocol droids (pun intended) here can be brutal when you violate SO etiquette.Lillielilliputian
I noticed you did end up cross-posting, which I can understand after this amount of time without an answer here. But I would recommend that you reference the cross-posting in both questions. Also would be nice if you requested answers go to one of the two questions (probably the SU one at this point) so that efforts aren't split. Or maybe just delete this one at this point given the re-post at SU?Brussels
for me https://mcmap.net/q/445508/-wsl2-network-unreachable-closed workedShush
I was able to replicate this issue when I sharing internet with "mobile hotspot", if you are sharing your ethernet connection that may cause the network conflicts. If you are not sharing your network with "mobile hotspot" just dismiss my comment.Coolie
Very strange, but in my case it was "Ensured no file nor folder under %TEMP% were compressed". Spent half a day debugging it, but I skimmed over your list in the question once again and checked my TEMP and it start working immediately.Rotenone
No matter what I tried wsl2 could not reach internet. wsl 2 has virtual networks problems. So I just downgraded to wsl 1. wsl --set-version 1 wsl --unregister Ubuntu wsl --install -d Ubuntu wsl -s UbuntuGca
For me enabling mirrored networking mode solved the connectivity issues: Edit %UserProfile%\.wslconfig to include: [wsl2] networkingMode=mirrored Then restart distributions with wsl --shutdown.Anorak
L
1

As of build 19042.1052, this is working again with no changes from my end. I am unsure as to the actual cause, but since I can no longer reproduce it, further troubleshooting seems moot.

Lillielilliputian answered 19/7, 2021 at 14:8 Comment(1)
So glad to hear you got it working! I'm sure that was frustrating in the interim. Hopefully this means that Microsoft found and fixed some issue in the networking and that we'll see (cross our fingers) fewer failures in this area going forward.Brussels
P
58

Running below command(and accessing the console again) fixed the "Network Unreachable" issue for me

wsl --shutdown
Provenance answered 6/7, 2021 at 6:4 Comment(7)
It worked as my machine didn't terminate successfullyRepublican
same. worked for me. (run command in windows)Titanate
This worked for me as well, how come such solution isn't mentioned at other places?Incidental
it works for me too, thanks.Burnside
Incredible, that worked like a charm !!Darmstadt
Was not suffient for me, but a full reboot did the job.Trochelminth
wsl --shutdown and Restart-Computer did the trick!Symphonize
W
29

I just got this situation resolved on my computer. My background was :

  1. I'm using WSL2
  2. Tried on Ubuntu 16.04 and Ubuntu 20.04
  3. I still can't connect to the internet when on a VPN

Step 1 : Figure out your local Gateway address on Windows

Wireless LAN adapter Wi-Fi:



Connection-specific DNS Suffix  . : home.sercomm
   IPv4 Address. . . . . . . . . . . : 192.168.1.69
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.254 <-- this is what we care about

Step 2 : create a /etc/wsl.conf file with the following content

cat /etc/wsl.conf
# Enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
[network]
generateResolvConf = false

Step 3 : delete the symlink to /run/resolvconf/resolv.conf on /etc/resolv.conf

cd /etc/
sudo rm resolv.conf

Step 4 : also delete /run/resolvconf/resolv.conf, why not?

cd /run
sudo rm resolvconf/resolv.conf

Step 5 : create a custom /etc/resolv.conf that will contain your Gateway address sudo vi /etc/resolv.conf

and paste this (with your Gateway address as seen in step 1)

nameserver 192.168.1.254

Step 6 : Open powershell and restart wsl

wsl --shutdown

Step 7 : ping google.com At this point, assuming your resolv.conf wasn't wiped automatically by the system, and you still preserve the configurations we added on step 5, you should be able to reach the internet.

Thanks, and don't hesitate on contacting me if you have an issue.

Wretch answered 7/5, 2021 at 4:46 Comment(8)
Thanks, but it didn't work but I went ahead and tried it again. Still didn't work... I am now on my second computer and it is doing it on that one as well. (╯°□°)╯︵ ┻━┻Lillielilliputian
is your /etc/resolv.conf staying or is it being overwritten?Wretch
it is definitely staying. -rw-r--r-- 1 root root 23 May 7 16:47 resolv.confLillielilliputian
may I see the contents? also, did you make sure step 3 and 4 (deleting symlink and file from /run/) were performed?Wretch
nameserver 192.168.0.1 $ ll /run total 4 drwxr-xr-x 8 root root 160 May 10 08:55 . drwxr-xr-x 18 root root 4096 May 10 08:25 .. drwxrwxrwt 2 root root 40 May 10 08:25 lock drwxr-xr-x 2 root root 40 May 10 08:25 mount drwxrwxrwt 2 root root 40 May 10 08:25 shm drwx--x--x 3 root root 60 May 10 08:55 sudo drwxr-xr-x 2 root root 40 May 10 08:25 user drwxr-xr-x 2 root root 60 May 10 08:25 WSL $ cd /etc $ ll resolv.* -rw-r--r-- 1 root root 23 May 7 16:47 resolv.confLillielilliputian
After trying countless other complicated fixes to get networking going in WSL2, this worked perfectly! Thank you!Iso
This is a good solution. I found that adding [network] generateResolvConf = false nameserver X.X.X.X in /etc/wsl.conf is enough. It will take precedence over whatever is set in /etc/resolv.confOpenfaced
For me I simply set it to Cloudflare's DNS server nameserver 1.1.1.1Byler
B
19

Update: While this didn't work for the OP, it continues to gain a few upvotes here and there. Based on what I know now, this particular answer likely works for certain users because their Swap disk is compressed or encrypted in %TEMP% (a.k.a. ..\AppData\Local\Temp under your Windows user profile). This is something that the OP had ruled out for their system, but if disabling swap works for you, then make sure your %TEMP% in Windows is neither compressed nor encrypted.


Hmm, you didn't mention WSL Github issue #5437 nor #6427, so here's something else to try:

Disable swap by adding:

[wsl2]
swap=0

to %userprofile%\.wslconfig

Seems to be the solution for a lot of people in this comment. Came across this when searching for "FIB table does not exist" "hyper-v"

Exit WSL, then (from PowerShell or CMD):

wsl --shutdown
Brussels answered 23/2, 2021 at 20:23 Comment(4)
Actually, sorry. In reading those two issues more closely, disabling swap seems to only be a solution when there's no IP address. Yours more closely resembles the problem in #6427, which is unresolved. There are a few more suggestions, but they seem to mirror what you've already tried (%temp% compression).Brussels
#6427 though, he can get out, but there is an issue with name resolution. I can't even see localhost. I hadn't seen those though, so thanks for a couple more to watch.Lillielilliputian
saved days! there was no such file. I created it and did a wsl --shutdownShush
YES! After trying EVERYTHING, this works! For the record, my disk is neither compressed, nor is it encrypted. I even made sure to uncompress my entire home directory. I tried nearly everything in many threads, github issues, scripts and articles... and THIS did it! I have no idea why Ubuntu on WSL2 shuts down all network interfaces like this, when it "detects" a compressed disk. Another reason to not use swap in Linux. Thanks!Gibeonite
Q
5

In addition to Juan Carlos Martinez Carrillo I had to run this command to set my eth0 correctly in my WSL2 environment.

sudo ifconfig eth0 inet <your_ip_address> netmask <your_netmask> broadcast <your_braodcast_ip>

So let's say take the example above and you have 192.168.1.254 as your default gateway on Windows, then the command should look like this:

sudo ifconfig eth0 inet 192.168.1.42 netmask 255.255.255.0 broadcast 192.168.1.255

Then shutdown and restart WSL with

wsl.exe --shutdown

in a Windows terminal.

Quinary answered 3/8, 2021 at 15:40 Comment(0)
A
1

From your ip output you can see:

1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 86:9a:be:53:f0:44 brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 1e:ff:ad:a4:c4:a7 brd ff:ff:ff:ff:ff:ff
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:15:5d:b7:f4:da brd ff:ff:ff:ff:ff:ff

There as it says the eth0 is down(closed, not working), so you have to start it by typing ip link set eth0 up to start it and reboot wsl by typing wsl --shutdown in windows then start the wsl again.

Alexiaalexin answered 18/7, 2021 at 14:31 Comment(1)
distro specific settings like this are very unlikely to span across multiple distros. Therefore this isn't likely to be the solution.Lillielilliputian
L
1

As of build 19042.1052, this is working again with no changes from my end. I am unsure as to the actual cause, but since I can no longer reproduce it, further troubleshooting seems moot.

Lillielilliputian answered 19/7, 2021 at 14:8 Comment(1)
So glad to hear you got it working! I'm sure that was frustrating in the interim. Hopefully this means that Microsoft found and fixed some issue in the networking and that we'll see (cross our fingers) fewer failures in this area going forward.Brussels
U
0

I used to have this problem and tried everything without luck! but found the solution this morning.

I had DHCP on my main adapter in Windows and for some reasons in past I had to enable dhcpstaticipcoexistence and add some static IPs to the same adapter.

Anyway, removing those and disabling dhcpstaticipcoexistence seem to have fixed the problem.

On a privileged console:

netsh interface ipv4 set interface "<YOUR-INTERFACE-NAME>" dhcpstaticipcoexistence=disable

netsh interface ipv4 delete address "<YOUR-INTERFACE-NAME>" <STATIC-IP-HERE>

and then shutdown wsl: wsl --shutdown

Undercroft answered 8/7, 2021 at 23:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.