WSL: Can not connect to internet in WSL 2

This happen on almost all official WSL distros (suse, debian, ubuntu) . I have not tried kali yet but i think the result will be the same.

This is the report on ubuntu:

  • Windows build number: 10.0.18932.1000

  • What you’re doing and what’s happening:

    • try to run sudo apt-get update
  • What’s wrong / what should be happening instead:

    • Error message:

    Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease Temporary failure resolving ‘archive.ubuntu.com’ Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease Temporary failure resolving ‘security.ubuntu.com’ Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Temporary failure resolving ‘archive.ubuntu.com’ Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Temporary failure resolving ‘archive.ubuntu.com’ Reading package lists… Done

    • This seem like a dns issue, this is the content of my resolv.conf:

    # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf: # [network] # generateResolvConf = false nameserver 172.22.64.1

    • Run ipconfig from cmd and overwrite resolv.conf with the dns I get from ipconfig. Run apt-get update again. Host name can be resolved now, but get another error:

    Err:1 http://security.ubuntu.com/ubuntu bionic-security InRelease Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.31), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.24), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out …

    • Try disable firewall, still the same error. I only use window defender, no other antivirus.

    • I convert my distro back to WSL 1 and every network command work fine. The content of resolv.conf in WSL 1 is surprisingly the same as when I overwrite the one in WSL 2

    • Expected: commands that require internet work as WSL 1

  • Strace of the failing command, if applicable: can’t, strace has not been installed yet beacause no internet. (I run strace on debian and got the command not found error, so I think ubuntu doesn’t have them pre installed too). The log is quite long (3k+ lines) so I put them in a file: apt-strace.log

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 96
  • Comments: 195 (4 by maintainers)

Most upvoted comments

I had the same issue too. network unreachable, and nothing can connect.

The following resolved my issues:

# ifconfig eth0 netmask 255.255.240.0
# ip route add default via <WSL ethernet address>    

(For me, ipconfig shows the WSL virtual eth address as 192.168.64.1.


Explanation:

I noticed that my $ ip addr didn’t quite match my \>ipconfig:

$ ip addr show eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:db:c0:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.76.46/24 brd 192.168.76.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fedb:c0c6/64 scope link tentative
       valid_lft forever preferred_lft forever

versus

 ipconfig                                                                                                                                                                                                                                                                                                                                                                                                                         Windows IP Configuration


Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::f513:b32c:60d5:1200%87
   IPv4 Address. . . . . . . . . . . : 192.168.64.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Virtual ethernet has subnet mask 255.255.240.0.

So the first line changes it to the correct subnet mask.

# ifconfig eth0 netmask 255.255.240.0

For the second line, when I ran ip route, I saw:

$ ip route
192.168.64.0/20 dev eth0  proto kernel  scope link  src 192.168.76.46

Which basically means that only the 192.168.64.0/20 range is routable. Hence why network unreachable for a lot of the commands. So the second one simply adds 192.168.64.1 as the default gateway for all routes:

# ip route add default via 192.168.64.1

Where the 192.168.64.1 matches the output of the windows ipconfig command for the WSL ipv4 address.

I don’t know if this is the 100% correct approach, but it certainly fixes this issue for me.

I think the problem is because I had another virtual machine in Hyper-V (Docker For Windows), and there was another network adapter with the name br-25ddfb4f166c and eth0 with the wrong ip. I uninstalled Docker For Windows and restarted the LxssManager (net stop LxssManager, net start LxssManager) service, and now the adapter is working normally. It may be some conflict with adapters from other virtual machines.

The following fixed my problem:

Upon examining the contents of /etc/resolv.conf, I discovered the file seemed to have been overwritten or corrupted. It contained nothing but a single line of #@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#...

Using sudo, I overwrote the contents of the file with the following: # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line. nameserver 169.237.250.250 nameserver 169.237.1.250

Saved, restarted WSL, and it worked like a charm.

My file was corrupted but fixing it, didnt get my internet connectivity back. Before WSL crashed a few times when deleting huge folders (node_modules). Maybe thats what corrupted that file.

What helped was the following: On cmd execute:

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

in WSL:

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

found in #3438

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto ‘Ethernet adapter vEthernet (WSL):’
  3. Copy ‘Subnet Mask’
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ’ IPv4 Address’
  5. Goto wsl and run sudo ip route add default via ' IPv4 Address'

none of this helped but answer on stackoverflow helped

https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

none of this helped but answer on stackoverflow helped

https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

Thanks this works for me too. I’m facing connection issue after downloading github desktop for windows.

Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.

How is this issue “closed” when it’s clearly still a problem for lots of people and there is no definitive fix?

In my case it was a DNS resolving issue. I edited my /etc/resolv.conf file deleted all existing lines and added only this one:

nameserver 8.8.8.8

@samscott89 the ip address match with the ip in ipconfig but I still cannot ping or use curl. Hope MS address this issue asap because it is a blocker issue that prevent many user from trying and testing WSL 2

I have a similar issue. Strangely it worked when I first convert to WSL2, but no longer works after a reboot.

For me, the windows hosts generates a WSL ethernet card:

    IP: 192.168.112.1
    Mask: 255.255.240.0

For the WSL ubuntu, ifconfig shows this:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.114.176  netmask 255.255.255.0  broadcast 192.168.114.255
    inet6 fe80::215:5dff:fe2e:c311  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:2e:c3:11  txqueuelen 1000  (Ethernet)
    RX packets 379  bytes 37421 (37.4 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 13  bytes 1006 (1.0 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

when I try to use ping 192.168.112.1, it comes back with connect: Network is unreachable.

I feel the problem is with the netmask, but not sure how to deal with it given the DHCP.

You are right, looks like this is a dupe of https://github.com/Microsoft/WSL/issues/3438

Try this:

$ sudo ifconfig eth0 netmask 255.255.240.0
$ sudo ip route add default via 192.168.112.1

Where 192.168.112.1 and 255.255.240.0 are the IP and netmask you got on the WSL interface (run ipconfig on windows and look for the WSL entry).

Including nameserver 192.168.1.1 in my /etc/resolv.conf seemed to do the work.

The following fixed my problem:

Upon examining the contents of /etc/resolv.conf, I discovered the file seemed to have been overwritten or corrupted. It contained nothing but a single line of #@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#...

Using sudo, I overwrote the contents of the file with the following: # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line. nameserver 169.237.250.250 nameserver 169.237.1.250

Saved, restarted WSL, and it worked like a charm.

I met same issue on 19041.329 with ubuntu 20.04.

got workaround from #5437 :

edit %userprofile%\.wslconfig (create if not already exist) and add below option:

[wsl2]
swap=0

@df3l0p I’ve experienced exactly the same behaviour. Networking didn’t work only in WSL 2, after downgrading Ubuntu to WSL 1 the connectivity issue didn’t persist. As @michidk suggested above - I have overwritten the DNS settings with a public DNS server by running

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

which fixed the issue.

I’ve just upgraded Windows to version 2004 (OS Build 19041.264) today to test out the new WSL 2.

EDIT: the issue comes back after restart. To fix it permanently: https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6

Note: originally /etc/resolv.conf was a symbolic link to /run/resolv/resolv.conf. Creating a resolv.conf file in /run/resolv didn’t fix this issue as it got deleted after invoking wsl --shutdown and restarting Ubuntu. I had to sudo rm /etc/resolv.conf and recreate the file as the gist says.

My case it is unable to ping to any of the addresses from WSL 2 when I connect to VPN (Cisco Anyconnect VPN client). I am running Windows 10 Enterprise Version 2004 (OS Build 19041.264)

It did work after conversion from WSL1 to 2 and before reboot. After reboot it screwed up. As i could see the default route is to reach the gateway on the host, that itself failed. Hence it is the main reason for failure.

Tried multiple things and ended up uninstalling WSL2. Afterwards I faced no issues with WSL1. When i checked the difference WSL1 is using windows routes instead of bridging with a dedicated host interface.

I think MS screwed the routing with VPN enabled!

Same case for me. A Workaround that works for the moment…

  1. With Cisco Anyconnect VPN client - Disconnected
  2. Windows +R write ‘cmd’
  3. wsl --shutdown
  4. Connect VPN with CISCO client
  5. Start WSL
  6. ping www.google.es OK
  7. git clone for private server OK

The problem happened again. Restarting LxssManager does not resolve.

using sudo bash -c ‘echo “nameserver 8.8.8.8” > /etc/resolv.conf’ sudo bash -c ‘echo “nameserver 8.8.4.4” >> /etc/resolv.conf’ after connecting my VPN worked perfectly!

+1 for @erickucl solution.

I just had this problem today. I’m commenting to underline that this is still an ongoing issue.


Windows build: 18363.1139 Docker For windows: v19.03.13 (with WSL2 based engine)

Additional note: I’m using vscode with both WSL2 and docker. (maybe there’s a link ?)

For anyone still struggling I have found that allowing incoming traffic on the public profile in the firewall instantly makes DNS resolution work in WSL without having to make any changes to /etc/resolv.conf or having to create /etc/wsl.conf file.

Windows Defender Firewall with Advanced Security -> Windows Defender Firewall Properties -> Public Profile -> Inbound Connections set to Allow.

My company uses Firewall to block certain ports which causes this issue. When I set this to allow all inbound connections DNS resolution inside WSL starts working instantly.

the only thing that worked for me is https://stackoverflow.com/a/54460886/4740149

  • First disable systemd-resolved service. sudo systemctl disable systemd-resolved.service

  • Stop the service sudo systemctl stop systemd-resolved.service

  • Remove the link to /run/systemd/resolve/stub-resolv.conf in /etc/resolv.conf sudo rm /etc/resolv.conf

  • Add a manually created resolv.conf in /etc/ sudo vim /etc/resolv.conf

  • Add your prefered DNS server there nameserver 208.67.222.222

for me the workaround of adding a custom nameserver has been working perfectly for the last couple of months. As of today, I no longer have internet either with or without that workaround. What’s changed?

also, why is this ticket ‘closed’? Given the number of people responding, it’s pretty clear that there is not yet a clear solution or consistent workaround for the issue here.

none of this helped but answer on stackoverflow helped

https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

Thanks, that worked for me!

** By far the easiest solution that worked for me!

Turn off Fast Start-Up in the System Settings -> Shut-down Settings. Then reboot. That’s it. found the solution here… https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/

The following fixed my problem: Upon examining the contents of /etc/resolv.conf, I discovered the file seemed to have been overwritten or corrupted. It contained nothing but a single line of #@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#... Using sudo, I overwrote the contents of the file with the following: # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line. nameserver 169.237.250.250 nameserver 169.237.1.250 Saved, restarted WSL, and it worked like a charm.

My file was corrupted but fixing it, didnt get my internet connectivity back. Before WSL crashed a few times when deleting huge folders (node_modules). Maybe thats what corrupted that file.

What helped was the following: On cmd execute:

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

in WSL:

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

found in #3438

using

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

after connecting my VPN worked perfectly!

@samscott89 ip route add default via give me a RTNETLINK answers: File exists . How can I make it work?

Step1:
run this command on powershell windows Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses | Foreach-Object { "nameserver $_" } Step 2: copy the output of this command Step 3: go to wsl and type sudo vi /etc/resolv.conf Step 4: comment the existing name server and paste the copied lines from step 2 Step 5: save and exit the file. Step 6: ping the desired domain name and verify the connection.

Disconnect from VPN, close WSL and reopen it

To elaborate on https://github.com/microsoft/WSL/issues/4275#issuecomment-695068842, Windows Update KB4023057 introduced the possibility to file compression before updates when system is running on low storage.

This update […] may take steps to free up disk space on your device if you do not have enough disk space to install Windows updates. […] To help free up disk space, this update may compress files in your user profile directory so that Windows Update can install important updates. When files or folders are compressed, they appear as having two blue arrows overlaid on the icon.

That includes %Appdata% (Local, LocalLow, Roaming) and subsequently %Temp%, if the distro’s files are compressed it won’t initialize and if %Temp% is compressed, you won’t have an internet connection.

To decompress folders (and files inside), right click on folder properties and under advanced uncheck all boxes related to allowing compression and reboot after.

I don’t have any sort of VPN enabled and I’m getting this.

@rakeshraimca Go to net-tools and download binary package of your architecture.

Then in wsl go to /mnt/c/Users/user_name/Downloads (it may be any directory) and execute

sudo dpkg -i net-tools-etc-etc-etc_architecture.deb

After that ifconfig should appear in your system

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto ‘Ethernet adapter vEthernet (WSL):’
  3. Copy ‘Subnet Mask’
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ’ IPv4 Address’
  5. Goto wsl and run sudo ip route add default via ' IPv4 Address'

problem is there is no connectivity and ifconfig command not found in wsl… what to do?

For me, it was Norton’s Smart Firewall causing this. I disabled it and problem was solved.

Have you tried turning off Fast Start-Up in the System Settings -> Shut-down Settings? I’ve written up the instructions here: https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/

The simple procedure that works is to modify the c:\users%USERPROFILE%.wslconfig file to be: [wsl2] memory=8GB swapFile=0 swap=0

For some reason someone at microsoft changed the name of the swap config parameter. Stragely, when swapfile is defined. network works like a whistle.

Microsoft: Please decouple swalfile from network. And consider supporting both names for the swap.

In my case it was a DNS resolving issue. I edited my /etc/resolv.conf file deleted all existing lines and added only this one:

nameserver 8.8.8.8

Thanks, I tried everything without success until adding this nameserver 😃

Fixed it by using following content in these files. If files don’t exist by default, just create them with given content.

# /etc/resolv.conf
nameserver 8.8.8.8
# /etc/wsl.conf
[network]
generateResolvConf = false

Shutdown WSL and open it again:

wsl --shutdown

Any progress ?

Hi,

I had the same issue … i was reading similar issues in many forums. I am using Windows 10.

This is the solution that worked for me:

  1. First check your ethernet connection for WSL

image

  1. Check out the network status for vEthernet (WSL )

image

For me initially the received was 0 or some low values like 1 or 2 . TO fix this we have to :

  1. Open Hyper V Manager > Virtual Switch Manager
  2. Select WSL and set the Network to External and choose the appropriate Network adapter that is connected to internet

image

  1. If your are good till now, you should see sent and received packets going up. Like the one in step 2. (When i checked out the connection properties > Ip V4 : Ip address and DNS was set to configure automatically)

Remaining fix have to be done in your Linux env. I have Ubuntu 20.04 installed.

  1. Open Ubuntu 20.04

  2. set the network ip address and netmask: sudo ifconfig eth0 <ip_address> netmask <net_mask> This ip_address should be same as the IP address you got for WSL Adapter. You can see these values by running an ipconfig /all from cmd image

  3. Once this is done, if you try to ping an internal ip address you should be able to reach it, but if you try to ping an external address the request will fail stating that there is no route to host.

  4. We have to add a route to external IPs as follows : sudo ip route add default via <your router ip> for me my router ip was 192.168.0.1

  5. Finally we have to update our resolver. But WSL2 automatically regenerates /etc/resolv.conf so we have to disable this first. To do so: vi /etc/wsl.conf and put the following content in there:

[network] generateResolvConf = false

  1. After this, you have to restart the linux system : Open a power shell in windows in admin mode and issue:

wsl --shutdown

This will shutdown all the linux instances

  1. now remove resolve.conf and recreate it with the following content:

rm /etc/resolv.conf recreate it with the following content

nameserver 202.88.238.3 nameserver 8.8.8.8

  1. Now if u try to ping google.com it should fail (because u have to repeat step 2 , every time u restart …this is still a WIP for me 😉 , if u know to fix it please share that info) . Once u set the ip and mask properly and ping google.com again. You should get the response.

Thats it! Let me know if it works out for you

I created this because of the need to rerun it now for every new distro created … https://github.com/aaronlks/wsl2-19041-fixDNS/blob/master/fixdns.sh

sudo chmod 666 /etc/resolv.conf
echo "nameserver 208.67.222.222" >> /etc/resolv.conf
echo "nameserver 208.67.220.220" >> /etc/resolv.conf
sudo chmod 755 /etc/resolv.conf

sudo touch /etc/wsl.conf
sudo chmod 666 /etc/wsl.conf
echo "[network]" >> /etc/wsl.conf
echo "generateResolvConf = false" >> /etc/wsl.conf
sudo chmod 755 /etc/wsl.conf

hope this gets fixed eventually =)

My case it is unable to ping to any of the addresses from WSL 2 when I connect to VPN (Cisco Anyconnect VPN client). I am running Windows 10 Enterprise Version 2004 (OS Build 19041.264)

It did work after conversion from WSL1 to 2 and before reboot. After reboot it screwed up. As i could see the default route is to reach the gateway on the host, that itself failed. Hence it is the main reason for failure.

Tried multiple things and ended up uninstalling WSL2. Afterwards I faced no issues with WSL1. When i checked the difference WSL1 is using windows routes instead of bridging with a dedicated host interface.

I think MS screwed the routing with VPN enabled!

It was NordVPN for me, uninstalled. Works fine.

It is not a traditional VM so no. You can see it via hcsdiag.exe and container powershell apis though.

Thanks for the info. Anecdotally, it does feel like its related to docker networking.

I seem to have found an acceptable workaround. At login, it takes a while for docker to fully initialize. With that, I added a WSL2 process that uses networking at startup which finishes before docker is initialized. Specifically I’m exporting DISPLAY and loading an X window.

Working so far.

As @alekzg just disconnect VPN, close WSL and re-open it. I can’t believe this hasn’t been fixed yet. Anyone want to work on this fix together and get it pushed?

Hello all,

For me the issue was happening when I connected to my work’s VPN a bit too fast just after starting my computer (I guess I didn’t give the wsl2 service enough time to be loaded with correct network settings) At the time WSL 2 internet was working fine only when I disconnected from my work’s VPN.

I was able to solve this by disconnecting the VPN then restart LxssManager windows service and reconnect to the VPN again.

To restart this service you can do it from interface: search services, open, right click LxssManager in the service list and restart Or by powershell as admin command line: Get-Service LxssManager | Restart-Service

For me this happens after change my PC internet, I was using Wi-Fi and now I’m using internet cable.

I think I solved this just uninstalling docker, restarting my pc and after that it was working again. So I reinstalled the docker and it was Ok.

I believe this is fixed with the latest builds and this issue can be closed.

My issue was my anti-virus firewall. I disabled it and WSL 2 network was working again. Now, I just need to figure out which exceptions to provide, so I can re-enable my firewall.

Windows Version

image

Windows WSL Version

>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Docker Version (with WSL 2 integration and Kubernetes)

image

Seems like there are mutiple issues out there in regards to this “same issue”. I read through much of them and with the help of my IT department we came up with a solution I’ve stated at #4246 here.

So I just worked with my IT Department on coming up with a fix. Here’s what we found out and how we corrected it.

When you connect to Cisco Anyconnect WSL2 will NAT to the highest priority Ethernet Adapter. A newer version of Cisco Anyconnect from the Windows Store seems to correct this; however, it doesn’t support Dual Factor Authentication. So to correct this we used a script that I saw mentioned elsewhere.

Steps:

Restart Computer (or begin from fresh start) Login to Computer, Connect via Cisco AnyConnect Run a script from Powershell that includes the follow (Note: your adapter name may need to be changed on Line 2 in quotes) Get-NetIPInterface -InterfaceAlias “vEthernet (WSL)” | Set-NetIPInterface -InterfaceMetric 1 $VPNInterfaceName = “Ethernet 3” Get-NetIPInterface -InterfaceAlias $VPNInterfaceName | Set-NetIPInterface -InterfaceMetric 5001 Once that’s been completed open WSL and you should be good to go, unless there is something else causing further issues that I had not experienced. I hope this helps, as we spent several days attempting to track down the cause.

Edit: Be sure if you have “Ubunut/WSL” set as your default profile in Windows Terminal, that you run the script prior to starting WSL. So if Ubuntu/WSL is your default, set your default to PowerShell, or switch over to PowerShell, run the command wsl --shutdown, then execute the above script, then reopen Ubuntu/WSL.

This issue was resolved on my machine by uninstalling the CheckPoint VPN client. Microsoft Windows [Version 10.0.19041.84]

I likewise had interference caused by CheckPoint VPN. Uninstalling it fixed my issue. Now I need to put it on a VM

I am on 10.0.18970.1005 and I had to do following 3 steps to solve this problem.

  1. Set correct subnet mask sudo ifconfig eth0 netmask <Ethernet (WSL) subnet mask)> e.g: sudo ifconfig eth0 netmask 172.22.208.1
  2. Set default gateway sudo ip route add default via <Ethernet (WSL) IPv4)> e.g sudo ip route add default via 172.22.208.1
  3. Change DNS entry in /etc/resolv.conf with 8.8.8.8

Having the same issue on Build 18965

Good call on the subnet mask, I’ll get that fixed.

I had just to uninstall Docker for Windows, restart and the internet started working again in WSL 2! Note that I’ve uninstalled all virtualization applications last week, except for Hyper-V.

It is not a traditional VM so no. You can see it via hcsdiag.exe and container powershell apis though.

You need to make sure that traffic from the network interface in your Linux distro inside WSL2 is routed to the WSL virtual network adapter on your Windows host. If it gets routed anywhere else, you don’t get any connectivity to anything outside the Linux vm. Check your routes with route print on the Windows host.

VPN connections are notorious for messing that up. I wrote a post about the problem and how you can work around it here: https://janovesk.com/wsl/2022/01/21/wsl2-and-vpn-routing.html

I can’t believe windows… This needs to be fixed, wasted my whole morning on this. A simple VPN disconnect and reboot of WSL fixes it. wth going on here.

In my case it was a DNS resolving issue. I edited my /etc/resolv.conf file deleted all existing lines and added all nameserver which is listed in IPv4 DNS Servers: (under network connection details) image

none of this helped but answer on stackoverflow helped https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

That also worked for me.

Just wondering (need time to research) what’s the effect of those steps. Some considerations:

  1. didn’t perform a windows reboot after installing the linux distro (ubuntu20)
  2. right after installing the linux distro, DNS resolved fine, but no access to (i.e.) ubuntu repos. (BTW, DNS is configured by default as the WSL gateway, should be the beforehand referred “IPv4 Address” from ipconfig’s output >> that will refer the request to your Windows (acting as gateway) and then to your internet router and so on; if changed to 8.8.8.8 you’re using google’s DNS… in fact reaching the internet).
  3. Docker desktop is installed, though never used it. Didn’t reinstall or so

Curious if the final “shutdown /r” from stackoverflow was the one that did the trick, may never know.

Went through a bunch of solutions. Nothing worked. Found out the problem was my %temp% folder (C:\Users\username\AppData\Local\Temp) was compressed. I uncompressed it and that fixed it immediately.

This solved my issue as well, thanks!

Compression likely kicked in after a reboot with low disk space, and apparently that is causing all sorts of problems. Before I encountered the internet problem, I had to solve a similar issue that prevented WSL to start due to a compression of %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited\LocalState, which prevented WSL to start. Link to that particular issue for reference.

Uninstalling Docker desktop worked for me. Not a good solution though.

i’ve got no internet access in a newly installed ubuntu subsystem.

also running 19041.329.

Should the IPs of the subsystem and the virtual adaptor on the host be on the same subnet? they’re not in my case.

Finally I solved my problem. I had to set the WSL adapter to ‘External Network’ in Hyper-V Manager and configure the IP address in WSL2 to work with the bridged adapter. I’ll be happy to write up the steps for anyone who is still stuck on this, or see my comment here.

For the record, this is now fixed for me on build 18932.

But the problem returned on 19037 and the previous solution doesn’t work

I got same issue on 18963.1000, WSL2. And @samscott89’s approach works properly.

If you don’t have ifconfig command like me, use below commands:

# ip addr  # check if the current address is unmatched
# ip addr del 192.168.89.250/24 dev eth0  # unmatched address of eth0
# ip addr add 192.168.80.250/20 dev eth0  # new matched address
# ip route add default via 192.168.80.1  # address of WSL2 adapter on Windows

For the record, this is now fixed for me on build 18932.

WSL settings -> Networking Mode-> VirtioProxy resolved it for me thanks

To my astonishment resetting my router and dsl modem fixed this. I had not had to reset my router/modem in at least 6 months before this.

none of this helped but answer on stackoverflow helped https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

Thanks, that worked for me!

What worked for me was a combination of the above, and in Hyper-V Manager I made sure the switch was set to “Internal Network” (was Private Network). Don’t set it to “External Network”. I found that creates a bridge and then neither the host nor the guest have internet. image

Hi! I’ve been dealing with this problem for a while, I’ve tried every solution possible with no results. The only solution that finally fixed it was completely uninstalling Checkpoint VPN, I even tried to stop every service related to Checkpoint but what solved it at the end was uninstalling it. I even had a ping running in the background and as soon as I uninstalled Checkpoint the ping started to respond.

check this solution. It worked for me after trying all the above suggestions. Answer here.

I have questions regarding the potential solution provided. Basically, I don’t know which commands get typed within Windows environment using powershell or cmd versus which get typed within the WSL environment. Could you clarify please?

ifconfig eth0 netmask 255.255.240.0 <-- type in powershell/cmd or in the WSL ?

ip route add default via <WSL ethernet address> <-- type in powershell/cmd or WSL?

I ask because the ip route command was not recognized by powershell or cmd, and when typed into the WSL (I had to use sudo, so that’s also worth mentioning above for us newbies), I get “RTNETLINK answers: File exists”

In my case, I disabled Hyper-V then it worked finally!

Windows Defender Firewall with Advanced Security -> Windows Defender Firewall Properties -> Public Profile -> Inbound Connections set to Allow.

This works for me. Many thanks!

none of this helped but answer on stackoverflow helped

https://stackoverflow.com/a/64057835/1319799

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset
shutdown /r 

This is worked for me

** By far the easiest solution that worked for me!

Turn off Fast Start-Up in the System Settings -> Shut-down Settings. Then reboot. That’s it. found the solution here… https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/

This works for me! Thank you!

from my perspective, many are reporting this as an issue while the actual root cause isn’t the same at all.

I don’t know why but disabling Mobile Hotspot fixed it for me.

  1. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask'

ifconfig is a no-go on some builds until you’re able to get internet access and install net-tools.

Steps From @samscott89

  1. Open CMD.exe (windows not wsl) run ipconfig
  2. Goto ‘Ethernet adapter vEthernet (WSL):’
  3. Copy ‘Subnet Mask’
  4. Goto wsl and run sudo ifconfig eth0 netmask 'Subnet Mask' 5 Goto cmd and copy ’ IPv4 Address’
  5. Goto wsl and run sudo ip route add default via ' IPv4 Address'

problem is there is no connectivity and ifconfig command not found in wsl… what to do?

You probably forgot to add nameserver ‘IPv4 Address’ to your /etc/resolv.conf in wsl so you don’t manage to resolve names to IPs try to ping 8.8.8.8 and check if it works

@df3l0p I’ve experienced exactly the same behaviour. Networking didn’t work only in WSL 2, after downgrading Ubuntu to WSL 1 the connectivity issue didn’t persist. As @michidk suggested above - I have overwritten the DNS settings with a public DNS server by running

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

which fixed the issue.

I’ve just upgraded Windows to version 2004 (OS Build 19041.264) today to test out the new WSL 2.

EDIT: the issue comes back after restart. To fix it permanently: https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6

Note: originally /etc/resolv.conf was a symbolic link to /run/resolv/resolv.conf. Creating a resolv.conf file in /run/resolv didn’t fix this issue as it got deleted after invoking wsl --shutdown and restarting Ubuntu. I had to sudo rm /etc/resolv.conf and recreate the file as the gist says.

Thank you, it works for me.

Hi, I’m able to connect to the “web” in example via curl, using this

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

But it’s impossible to use python pip. How solve this issue?

Thank you

@Laynkulan @Rogn I can’t uninstall CheckPoint VPN or disable Avast since this is a company machine.

Do you want what the problem is, so I can direct the IT?

@vluzrmos I found a better solution with restarting the service “LxssManager” from Windows task list. It is faster than rebooting the system and you keep everything opened. Only my WSL-connected VS Code needs a restart afterwards.

Here you can find a discussion about that topic: https://superuser.com/questions/1126721/rebooting-ubuntu-on-windows-without-rebooting-windows

i was upgrad to 19536.1000, but still not working. and i also reboot multi times.

#update after i run those lines in powershell as administrator, the wsl2 network become normal, dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

then reboot .

after reboot, it’s look like working correct.

and actually, i already install wsl before upgrade to 19536.1000.


my another pc is 19041.1 , and i use netsh winsock reset resolve the wsl2 network issue on 19041.1

and 19041.1 has the same problem , the previous solution doesn’t work too.

hi @rm-bergmann

Try this https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6 Thats work for me, but still must disable my firewall

Same sort of problem on 18990. Edit: problem is still there in 189950.

My subnet mask and IP route are set correctly automatically.

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::39ac:1623:faa1:5a4e%64
   IPv4 Address. . . . . . . . . . . : 172.19.48.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

And on WSL

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.50.111  netmask 255.255.240.0  broadcast 172.19.63.255
        inet6 fe80::215:5dff:feb4:8c78  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:b4:8c:78  txqueuelen 1000  (Ethernet)
        RX packets 468  bytes 85367 (85.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 142  bytes 11761 (11.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
default via 172.19.48.1 dev eth0
172.19.48.0/20 dev eth0 proto kernel scope link src 172.19.50.111

If I try to ping outside the computer, I can’t receive the packets back, but it resolves the ip address.

PING google.com (172.217.20.110) 56(84) bytes of data.
^C
--- google.com ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4167ms

Edit: No other AV or firewall is installed on the system except Windows Security

feedback submitted

If you’re seeing this error could you help us by taking some networking logs when you’re trying to access the internet?

Instructions on how to do so are here. Thanks!

If you’re seeing this error could you help us by taking some networking logs when you’re trying to access the internet?

Instructions on how to do so are here. Thanks!

Because there are some people have this bug in Build 18965 , I will reopen it.

ah, i just updated to insider 18963. the issue seems to be fixed in this build.

ipconfig :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter
   Physical Address. . . . . . . . . : 00-15-5D-DB-C8-62
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::99bf:aeb5:cdf6:d3d3%47(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.21.176.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 788534621
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-23-A6-3A-23-20-47-47-77-68-96
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1

ip a:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 4a:67:0b:ea:41:95 brd ff:ff:ff:ff:ff:ff
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:97:ad:4d brd ff:ff:ff:ff:ff:ff
    inet 172.21.183.22/16 brd 172.21.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fe97:ad4d/64 scope link
       valid_lft forever preferred_lft forever

ip route:

default via 172.21.176.1 dev eth0
172.21.0.0/16 dev eth0 proto kernel scope link src 172.21.183.22

@samscott89 ip route add default via give me a RTNETLINK answers: File exists . How can I make it work?

You might be fine without the second step then. After applying that step, I see:

$ ip route
default via 192.168.64.1 dev eth0
192.168.64.0/20 dev eth0  proto kernel  scope link  src 192.168.76.46

Where 192.168.64.1 should match whatever ipconfig showed as the WSL ip address.

You will probably need (at least) both lines. If the first line is already there, then either you are good to go, or the issue is elsewhere