Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No internet connectivity from WSL2/Ubuntu #4926

Closed
j0057 opened this issue Feb 24, 2020 · 70 comments
Closed

No internet connectivity from WSL2/Ubuntu #4926

j0057 opened this issue Feb 24, 2020 · 70 comments

Comments

@j0057
Copy link

j0057 commented Feb 24, 2020

  • Your Windows build number: 10.0.19041.84

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

I'm getting timeouts when trying to connect to internet from a WSL2 instance. DNS works, and the WSL2 instance can see/ping the host without problem.

$ ip route
default via 172.24.64.1 dev eth0
172.24.64.0/20 dev eth0 proto kernel scope link src 172.24.66.230
$ cat /etc/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.24.64.1
$ dig +noall +answer microsoft.com
microsoft.com.          0       IN      A       13.77.161.179
microsoft.com.          0       IN      A       40.76.4.15
microsoft.com.          0       IN      A       40.112.72.205
microsoft.com.          0       IN      A       40.113.200.201
microsoft.com.          0       IN      A       104.215.148.63
$ curl -4sv -m5 https://microsoft.com/
*   Trying 13.77.161.179...
* TCP_NODELAY set
* After 2498ms connect time, move on!
* connect to 13.77.161.179 port 443 failed: Connection timed out
*   Trying 40.76.4.15...
* TCP_NODELAY set
* After 1249ms connect time, move on!
* connect to 40.76.4.15 port 443 failed: Connection timed out
*   Trying 40.112.72.205...
* TCP_NODELAY set
* After 623ms connect time, move on!
* connect to 40.112.72.205 port 443 failed: Connection timed out
*   Trying 40.113.200.201...
* TCP_NODELAY set
* After 311ms connect time, move on!
* connect to 40.113.200.201 port 443 failed: Connection timed out
*   Trying 104.215.148.63...
* TCP_NODELAY set
* After 155ms connect time, move on!
* connect to 104.215.148.63 port 443 failed: Connection timed out
* Failed to connect to microsoft.com port 443: Connection timed out
* Closing connection 0

Based on what I know about Hyper-V networking, my Internal switch may or may not route packets from the VM to the internet, but in order for packets to be routed back, the traffic from the WSL2 VM will need to be NAT'ed.

On the host, in Powershell, Get-NetNat returns no results:

PS C:\WINDOWS\system32> Get-NetIPAddress -InterfaceIndex 59 | Format-Table

ifIndex IPAddress                                       PrefixLength PrefixOrigin SuffixOrigin AddressState PolicyStore
------- ---------                                       ------------ ------------ ------------ ------------ -----------
59      fe80::xxxx:xxxx:xxxx:xxxx%59                              64 WellKnown    Link         Preferred    ActiveStore
59      172.24.64.1                                               20 Manual       Manual       Preferred    ActiveStore


PS C:\WINDOWS\system32> Get-VMSwitch -name WSL | Format-List


Name                                             : WSL
Id                                               : 32874a54-04c6-4677-a51f-77c5245345a5
Notes                                            :
Extensions                                       : {Microsoft Windows Filtering Platform, Microsoft Azure VFP Switch Extension, Microsoft NDIS Capture}
BandwidthReservationMode                         : Absolute
PacketDirectEnabled                              : False
EmbeddedTeamingEnabled                           : False
IovEnabled                                       : False
SwitchType                                       : Internal
AllowManagementOS                                : True
NetAdapterInterfaceDescription                   :
NetAdapterInterfaceDescriptions                  :
NetAdapterInterfaceGuid                          :
IovSupport                                       : False
IovSupportReasons                                :
AvailableIPSecSA                                 : 0
NumberIPSecSAAllocated                           : 0
AvailableVMQueues                                : 0
NumberVmqAllocated                               : 0
IovQueuePairCount                                : 0
IovQueuePairsInUse                               : 0
IovVirtualFunctionCount                          : 0
IovVirtualFunctionsInUse                         : 0
PacketDirectInUse                                : False
DefaultQueueVrssEnabledRequested                 : True
DefaultQueueVrssEnabled                          : False
DefaultQueueVmmqEnabledRequested                 : True
DefaultQueueVmmqEnabled                          : False
DefaultQueueVrssMaxQueuePairsRequested           : 16
DefaultQueueVrssMaxQueuePairs                    : 0
DefaultQueueVrssMinQueuePairsRequested           : 1
DefaultQueueVrssMinQueuePairs                    : 0
DefaultQueueVrssQueueSchedulingModeRequested     : StaticVrss
DefaultQueueVrssQueueSchedulingMode              : Dynamic
DefaultQueueVrssExcludePrimaryProcessorRequested : False
DefaultQueueVrssExcludePrimaryProcessor          : False
SoftwareRscEnabled                               : False
BandwidthPercentage                              : 0
DefaultFlowMinimumBandwidthAbsolute              : 0
DefaultFlowMinimumBandwidthWeight                : 0
CimSession                                       : CimSession: .
ComputerName                                     : NB-XXXXXXX
IsDeleted                                        : False
DefaultQueueVmmqQueuePairs                       : 0
DefaultQueueVmmqQueuePairsRequested              : 16

When trying to set up a new NAT rule, I get a seemingly unrelated error:

PS C:\WINDOWS\system32> New-NetNat -Name "WSLNetworkNAT" -ExternalIPInterfaceAddressPrefix 172.24.64.0/20
New-NetNat : The parameter is incorrect.
At line:1 char:1
+ New-NetNat -Name "WSLNetworkNAT" -ExternalIPInterfaceAddressPrefix 17 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_NetNat:root/StandardCimv2/MSFT_NetNat) [New-NetNat], CimException
    + FullyQualifiedErrorId : Windows System Error 87,New-NetNat
@rm-bergmann
Copy link

rm-bergmann commented Feb 24, 2020

I have the same problem, however I get this output from Get-NetNat:

Name                             : NATNetwork2
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.0.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

Name                             : NATnetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.56.102/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

Name                             : MyNATnetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 172.21.21.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

$ ip route (wsl bash)

default via 172.30.160.1 dev eth0
172.30.160.0/20 dev eth0 proto kernel scope link src 172.30.168.189

@j0057
Copy link
Author

j0057 commented Feb 25, 2020

A colleague helpfully pointed out that Symantec Endpoint Protection includes a firewall that blocks the requests from the WSL2 context. (Incidentally, Symantec EP is according to themselves "not supported" for workloads that include running VM's in Hyper-V.)

As for the NAT rules -- with the firewall temporarily disabled I can do a request to the internet, but Get-NetNAT still does not return anything, so, apparently, these NAT rules are not needed for WSL2. I'm now wondering how it does work under the hood.

@j0057
Copy link
Author

j0057 commented Feb 25, 2020

@rm-bergmann Those NAT rules you're seeing could be related to other virtual switches. You should be able to find out using Get-NetIPAddress | Format-Table and Get-NetAdapter cmdlets -- you can correlate the interfaceIndex fields.

@rm-bergmann
Copy link

@j0057 Thank you, you have helped me solve my problem that I have been debugging for over 3 months! Those NAT rules that I had there (probably from previous VM's) were conflicting with WSL2, so I removed them with Remove-NetNat and boom! WSL2 networking is fixed (in my case)!

@natronkeltner
Copy link

I ran into this for much of today on 10.0.19546. I have no NetNATs, have Windows AV, and disabled the firewall for testing. WSL1 works fine, WSL2 does not.

From inside WSL2 I could ping my host interfaces and DNS worked fine, but nothing routed.

I experimented with removing options, explicitly setting interface metrics, uninstalling and reinstalling docker, reboots, but nothing worked. I eventually found this partial workaround:

  1. Manually enable Internet Connection Sharing: right click the network adapter you want to share, properties, sharing, then enable it for vEthernet (WSL).

image

  1. The IP address for WSL now changed to some default ICS IP, 192.168.137.1. In WSL2 Ubuntu, edit the eth0 interface to be in the same subnet: ip addr add 192.168.137.10/24 dev eth0

  2. Change the default gateway (ip route delete default and ip route add default via 192.168.137.1)

  3. Change DNS (manually edit /etc/resolv.conf)

And it finally had internet. It goes back to defaults on wsl2 shutdown, of course. This also doesn't handle moving from wired to wireless.

Something is definitely broken in the Hyper-V NAT / Routing pieces for vEthernet (WSL), but I couldn't figure it out.

@j0057
Copy link
Author

j0057 commented Feb 26, 2020

@natronkeltner Small data point: when I navigate to the Sharing tab of both my uplink adapter as well as the vEthernet adapter, they say "Internet Connection Sharing has been disabled by the Network Administrator". So I'm not even sure how networking is supposed to work in WSL2!

@Sidneys1
Copy link

Sidneys1 commented Mar 9, 2020

So I went through this entire thread as well as #4731 with no solution to my problem, which is slightly different:

I am able to ping internet resources, such as google.com or 1.1.1.1, but I can't access them with wget or curl (e.g., curl -4v google.com).

I went so far as to uninstall Ubuntu-18.04, disable the Windows Feature Windows Subsystem for Linux, then re-enable/re-install. I've messed with the network address and routing settings. I've messed with Hyper-V adaptors. I've messed with Windows reserved ports and dynamic port ranges which have been an issue for me in the past. I've turned windows firewall on-off. I've rebooted about a million times. Still no-go. Some output:

$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=56 time=55.9 ms
$ curl -4v 1.1.1.1
* Rebuilt URL to: 1.1.1.1/
*   Trying 1.1.1.1...
* TCP_NODELAY set
^C

So I thought, what else is a lightweight utility VM? Windows Sandbox! So I opened that and in there I can ping, but not browse (with edge) as well... However with curl.exe I can get google.com's redirect page to www.google.com but not www.google.com itself... :(

@rm-bergmann
Copy link

I eventually found the underlying problem I had which caused my networking to break in WSL2. My previous fix (hack) to set up a network bridge didn't fix my underlying problem. I found that I had some NAT adapters from previous VM's that were set up in Hyper-V. Removing them fixed all my network issues.

In powershell I ran the cmd Get-NetNat and there were 3 NAT's listed. I shutdown WSL and I ran the Remove-NetNat cmd, which restored my networking and internet connectivity in WSL2.

@Sidneys1
Copy link

Sidneys1 commented Mar 9, 2020 via email

@Sidneys1
Copy link

Sidneys1 commented Mar 10, 2020

I finally found the underlying problem! I installed Wireshark and attached to the WSL vSwitch to see if I could diagnose the problem there and...

Turns out all the Ping replies were coming from the same MAC address - and that MAC belonged to an OpenVPN TAP NIC on my host. I uninstalled the NIC and wsl --shutdown/restarted and networking works again!

It looks like WSL2 connects to the "best looking" NIC on the host, even if that NIC isn't network-connected. They should add a wsl.conf setting to control what NIC WSL2 gets attached to.

Edit: for you poor souls finding this in 2021, disabling the NIC works as well as uninstall it!

@luxzg
Copy link

luxzg commented Mar 18, 2020

They should add a wsl.conf setting to control what NIC WSL2 gets attached to... and do that for each WSL2 distro, and allow not to use bridge, and... it is still going to worldwide distribution "as is" apparently as W10 2004. I had high hopes for WSL2, but as it stands now, I'm better off keep having few Linux VMs on my local Hyper-V. At least I know which VM is tied to which adapter, which VLAN, which subnet, and which (static!) IP.

@natronkeltner
Copy link

It took forever to figure this out so I'll document it here in case someone comes along and finds this. I used Microsoft Message Analyzer with the Hyper-V-VmSwitch and NDIS-PacketCapture providers, which will show exactly how the internal switches are routing packets.

image

This allowed me to see the outbound TCP packets, the inbound TCP responses, and that they were being filtered at the switch level due to a VLAN tag.

MessageNumber	DiagnosisTypes	Timestamp	TimeElapsed	Source	Destination	Module	Summary	
502	None	2020-03-20T16:21:09.3340883				Microsoft_Windows_Hyper_V_VmSwitch	NBL 0xFFFF90079978BA40 received from Nic 14B75DAC-3764-4D7F-84B6-8F39004014B2 (Friendly Name: WSL) in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL)	
503	None	2020-03-20T16:21:09.3340929				Microsoft_Windows_Hyper_V_VmSwitch	NBL originating from Nic 14B75DAC-3764-4D7F-84B6-8F39004014B2 (Friendly Name: WSL) was dropped in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL), Reason VLAN Filtered (Status:Unknown NTSTATUS Error code (0xE0000003))	

... was dropped in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL), Reason VLAN Filtered

My network port was slightly misconfigured and VLAN tagged packets were being sent to my system, but I had never noticed before because nothing connected to this switch port had ever cared before. Windows didn't care (and didn't show me, either, when using Wireshark/npcap). WSL1 also didn't care that inbound packets were tagged. WSL2, however, uses hyper-v switches, which do care about VLAN tags and silently drop packets that are tagged.

Fixing my network port to strip packets of VLAN tags fixed my issue and the hyper-v switches now work fine.

@mitsuka
Copy link

mitsuka commented Mar 31, 2020

In my environment, I disabled everything in the BIOS except for the interface connected to the internet.
After that, the internet connectivity was restored.

@walidshaari
Copy link

my issue was wit AVG Internet security enhanced firewall

@j0057 j0057 closed this as completed Apr 14, 2020
@anthonysomerset
Copy link

For those that use Symantec Endpoint Protection and disabling it works

the specific config that seems to get things working again without a complete disable is to allow unmatched IP traffic as per the attached screenshot
Screenshot 2020-04-15 15 43 51

@dennisameling
Copy link

Turns out all the Ping replies were coming from the same MAC address - and that MAC belonged to an OpenVPN TAP NIC on my host. I uninstalled the NIC and wsl --shutdown/restarted and networking works again!

Had the same issue here, there was a TAP NIC left from some old OpenVPN installation. Working as expected now 🚀

@oidualc
Copy link

oidualc commented May 30, 2020

For those that use Symantec Endpoint Protection and disabling it works

the specific config that seems to get things working again without a complete disable is to allow unmatched IP traffic as per the attached screenshot
Screenshot 2020-04-15 15 43 51

This is unfortunate! In my case in a work PC the damn Symantec Endpoint Protection is blocking the communications for WSL2 (not WSL though..), but on the other end I cannot modify that setting because it's blocked by the organization.
Why this is a problem only for WSL2?
And most importantly, is there anything else that can be done without touching the SEP settings?

@anthonysomerset
Copy link

anthonysomerset commented May 30, 2020 via email

@loscil412
Copy link

Hi, I solved this issue -- being able to ping addresses but not 'communicate' directly with them (in particular, github.com).

I have avast firewall turned on.
Checking the avast fw settings, a few things stood out:

The adapter description was Hyper-V Virtual Ethernet Adapter #3.

  1. My network was set as a public network. I changed it to a private network (which it is :)).

  2. In settings (a blue link under firewall profile) I set ALLOW For programs with no defined rules (i.e. programs not listed on the Application Rules page) This setting was defaulted to 'Auto-Decide'

I haven't done too much more at this point than verify that I can curl google, and git pull without issue within Ubuntu on WSL2.

I'm on build 19041.330

@samnf
Copy link

samnf commented Aug 5, 2020

For me, the "resolution" ended up being to restart my PC 🤦 ..
So make sure you try that before anything too crazy

@Karlheinzniebuhr
Copy link

Having the same issue, installed brand new ubuntu 20.04 with WSL 2 but cannot ping 8.8.8.8 nor any IP out in the internet from ubuntu

@onomatopellan
Copy link

@Karlheinzniebuhr make sure you didn't hit this bug #5437

@Karlheinzniebuhr
Copy link

Fixed by applying this #5336 (comment)

=============================================================================
FIX WSL2 NETWORKING IN WINDOWS 10
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows

@fkguo
Copy link

fkguo commented Aug 31, 2020

Fixed by applying this #5336 (comment)

=============================================================================
FIX WSL2 NETWORKING IN WINDOWS 10
cmd as admin:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Restart Windows

Thank you for the tip. I followed these steps, but unfortunately I completely lost my internet connection even for windows...

ipconfig /all shows media disconnected, and I tried methods that I found on line, but no one worked... Any clue?

@Karlheinzniebuhr
Copy link

Karlheinzniebuhr commented Aug 31, 2020 via email

@fkguo
Copy link

fkguo commented Aug 31, 2020

Do you need to set up a static IP with a specific gateway? I suspect your lan has no DHCP server and you might need to setup your previous configuration

Thanks for the quick reply. No, the previous setting was automatic. I don't need to set anything in principle...

One of the steps I followed was to netsh int ip reset reset.log as an administrator. One of the resettings failed. Don't know whether this is related or not.

@fkguo
Copy link

fkguo commented Aug 31, 2020

Issue solved: it turns out that somehow the wlan autoconfig service was not automatically started. It was fixed by
Win+R -> services.msc, and then change the startup type for WLAN AutoConfig from Manual to Automatic.

@hatranpro
Copy link

A colleague helpfully pointed out that Symantec Endpoint Protection includes a firewall that blocks the requests from the WSL2 context. (Incidentally, Symantec EP is according to themselves "not supported" for workloads that include running VM's in Hyper-V.)

As for the NAT rules -- with the firewall temporarily disabled I can do a request to the internet, but Get-NetNAT still does not return anything, so, apparently, these NAT rules are not needed for WSL2. I'm now wondering how it does work under the hood.

I confirm the issue with WSL2 is if Symantec Endpoint Protection running. I was able to connect to the internet after stopping Symantec Endpoint Protection. Thank you.

@kevingosse
Copy link

I ran into the same problem (ping working, not curl). In my case it seems it was another occurrence of #4926 (comment). I couldn't find how to capture packets from the WSL network interface in Wireshark, so I just shutdown WSL, disabled a bunch of network adapters, and ran WSL again, and it worked.

@rjudin
Copy link

rjudin commented Dec 8, 2020

Our team reports about verified workaround https://github.com/sakai135/wsl-vpnkit with window 10 build 1909, that you could try

@Adriano-Santtos
Copy link

Hi, I solved this issue -- being able to ping addresses but not 'communicate' directly with them (in particular, github.com).

I have avast firewall turned on.
Checking the avast fw settings, a few things stood out:

The adapter description was Hyper-V Virtual Ethernet Adapter #3.

  1. My network was set as a public network. I changed it to a private network (which it is :)).
  2. In settings (a blue link under firewall profile) I set ALLOW For programs with no defined rules (i.e. programs not listed on the Application Rules page) This setting was defaulted to 'Auto-Decide'

I haven't done too much more at this point than verify that I can curl google, and git pull without issue within Ubuntu on WSL2.

I'm on build 19041.330

It worked for me.
Thank you!

@kdxcxs
Copy link

kdxcxs commented Feb 12, 2021

After trying every single way mentioned above and failed, I finally manage to find a way that works for me. Just run netsh int ipv4 set dynamic tcp start=49152 num=16384 as Administrator and wsl could reach the internet.

I've set some Protocol tcp Port Exclusion Ranges before as Docker and JetBrains' IDEs could not run properly, which might just cause this issue.

@ambethell
Copy link

Our team reports about verified workaround https://github.com/sakai135/wsl-vpnkit with window 10 build 1909, that you could try

I can confirm this helped me get around SEP (14.2.RU2 MP1 build 5569 - 14.2.5569.2100) issues. The configuration for my version of SEP also had 'allow IP traffic' on unmatched IP traffic settings but the logs were still showing it blocking wsl outbound connections.

@raidenii
Copy link

raidenii commented Apr 1, 2021

Another way of allowing traffic for people use Symantec Endpoint Protection without allowing all IP traffic:
Add a firewall rule that allows IP traffic (or traffic you want, like IP protocol 1 (ICMP), 6 (TCP) and 17 (UDP)) on the Hyper-V adapter, both directions. You can find which adapter WSL2 uses in Network & Sharing Center (it will say vEthernet (WSL) in its name).

How can one do that? Apparently, symantec endpoint protection firewall rules ('security exception risks') should relate to either 1) known risks, 2) files, 3) folders, 4) extensions, or 5) web domains. (these might not be the exact terms: I am roughly translating back from my interface, which is in Portuguese).

i have tried to make an exception to wsl.exe, under Windows/System32, but it apparently did not work properly. How could one make exceptions only for certain types of IP traffic?

In my case, internet seems to be working rather properly (I can ping google.com with good results), but ubuntu's servers (for apt get update, for instance) do not work, and http addresses within command line instructions do not work either.

By adding a firewall rule on the WSL network adapter. Not the application settings, but configure firewall rules.

@ultramaks
Copy link

ultramaks commented Apr 15, 2021

Can anyone tall me what exact steps should be performed to allow WSL2 traffic from WSL2 Ubuntu to Internet trough primary host Win10 workstation?
I tried this specifying an IP address of the WSL adapter that I received from ipconfig /all but had no luck (all other settings were put as "all"). Am i missing something?

PS I have Symantec Endpoint Protection Version 14. Despite that I can successfully ping some resources
e.g. ping www.ya.ru
but when I try to sudo apt-get update I can't connect any host

PPS if I disable Symantec I have all the connectivity in Ubuntu and all works fine (docker connections. updates etc). But it's managed by my organization and it's automatically enabled after several minutes

@ExtremeGTX
Copy link

ExtremeGTX commented Apr 26, 2021

Thanks @anthonysomerset , I could also ping google.com but apt update or git clone fails :(
So I checked my Avast firewall and it was it :( More here
Goto Protection -> Firewall -> Settings -> Enable "Internet Connection sharing mode"
Now internet works!

I don't know if this option is completely safe or not, will try to find out more.

@k0psutin
Copy link

k0psutin commented May 6, 2021

I got the network working in Ubuntu 20.04 WSL2 after I unchecked IPv6 from my WLAN and VPN properties and made few changes to .conf-files.

For the .conf-files I used the solution found in #5420 (comment) to stop WSL from rewriting the nameservers.

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

These steps worked for me and I hope it helps others as well. Now I have network connection in Ubuntu everytime I launch it.

@uscwifi
Copy link

uscwifi commented Jun 30, 2021

Hi,我也遇到了这个问题,我是在更新了windows 6月份的补丁之后发现的这个问题,我参考这篇文章:ipconfig shows only "Windows IP Configuration" after upgrade to Win10
image
我卸载掉电脑上的checkpoint vpn然后重启电脑后,我的ubuntu子系统就正常了,我真是个幸运儿!😋

@brettcave
Copy link

I had a similar issue - to narrow down the problem, I avoided DNS and worked with IPs - so it was a routing / nat related issue (and because I couldn't reach my windows local network from the virtual network, DNS fails, but it's not the root cause).

Problem description: My Windows host is on network a.0.0.0/24 with a default gateway of a.0.0.1. from windows. I can ping from Windows to default gateway, or out onto the network (e.g. 8.8.8.8). I had full network functionality in WSL1 (Ubuntu 20). After WSL2 upgrade, networking was lost. From Ubuntu, was not able to ping a.0.0.1, my local network gateway (and therefore any external IP like 8.8.8.8).

Resolution:

  1. I had WSL + Virtual Machine Platform installed in Windows Features, but did not have Hyper-V components. I added all Hyper-V components and restarted.
  2. Still not able to reach local gateway. The solution posted by @Karlheinzniebuhr did the trick, but a full Network Reset was not needed (I didn't want to reconfigure VPNs and other network settings that I needed). To confirm the commands, executed from an Admin powershell / command prompt:
wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Reboot.

After that, ping to local gateway confirmed, plus ping to external IP was possible, but DNS was not working.

In Ubuntu, /etc/resolv.conf was autogenerated with a virtual network address (172.31 - the same as the WSL gateway, i.e. virtual network adapter on the Windows host). Am guessing that the DNS proxy or forwarding there was not working - I didn't resolve this by getting this dns forward / masq or whatever it is to work, but used the /etc/wsl.conf method described above to disable auto resolv config. My router / local network gateway (a.0.0.1) is a DNS forwarder, so I set up resolv.conf to use that. Not sure yet if this would affect any WSL to WSL resolution that i might need.

$ sudo -i
# cat >/etc/wsl.conf <<-EOF
[network]
generateResolvConf = false
EOF
# mv /etc/resolv.conf /etc/resolv.conf-autogen-symlink
# echo nameserver a.0.0.1 > /etc/resolv.conf
# host www.google.com
www.google.com has address x.y.z.b

1 other item worth noting, not sure if it impacted this, was that I was upgrading to WSL2 in order to get docker working in Linux. Not sure if the docker networking affected this in any way, I didn't verify networking after WSL2 before Docker installation.

HTH, happy networking.

@brettcave
Copy link

brettcave commented Jul 3, 2021

p.s. if anyone has a solution to get the generated resolv.conf working, would be great to use this so I don't have to maintain this myself - didn't see a fix or root cause on this.

$ host www.google.com 172.31.64.1 # DNS server that wsl generated for me
;; connection timed out; no servers could be reached
$ host www.google.com a.0.0.1 ("a" is my local subnet redacted).
www.google.com has address x.y.z.b
$  ping -c 1 172.31.64.1
PING 172.31.64.1 (172.31.64.1) 56(84) bytes of data.
64 bytes from 172.31.64.1: icmp_seq=1 ttl=128 time=0.334 ms

The virtual interface does respond to icmp, just no functioning resolution from it.

@108806
Copy link

108806 commented Jul 3, 2021

Nothing works for me, I have looked at the other threads too. I am using win 10.0.19043.1081.
I had to go back to the older WSL1 and older Linux distro, openSUSE-15.2 is the only one fully working on my machine currently, everything else has some DNS issues, it can ping 8.8.8.8 but can't ping google.com.

@flashadvocate
Copy link

flashadvocate commented Jul 12, 2021

Crazy idea, and it actually worked...

Why not just run VPN on the VM itself?

sudo apt-get install openconnect
sudo openconnect vpn.domain.com
# <CTRL+Z>
# bg

@lo-w
Copy link

lo-w commented Jul 23, 2021

hello, we got the same issue.
the SEP(Symantec Endpoint Protection) blocks the traffic from WSL2.
but we cannot modify the SEP settings because it's blocked by the organization.
do we having any other WA to put the way forward, thanks.
image
image

@y1rn
Copy link

y1rn commented Jul 23, 2021

hello, we got the same issue.
the SEP(Symantec Endpoint Protection) blocks the traffic from WSL2.
but we cannot modify the SEP settings because it's blocked by the organization.
do we having any other WA to put the way forward, thanks.
image
image

same issue

@lo-w
Copy link

lo-w commented Aug 9, 2021

Hi
update the latest status about who using SEP(Symantec Endpoint Protection) having this issue.
we using geek(uninstall tool) to remove the SEP totally, now everything works as expected.
BR//lo

@monigenomi
Copy link

monigenomi commented Sep 21, 2021

I think what helped for me was:

  • Uninstall all Ubuntu versions
  • Disable "Enable integration with my default WSL distro" in Docker's settings (Resources -> WSL Integration)
  • Restart computer
  • Install Ubuntu 20.04 LTS
  • Check "Ubuntu-20.04" in "Enable integration with additional distros" in mentioned Docker's settings panel (do not check "Enable integration with my default WSL distro")
  • Click "Apply & Restart"
  • Optionally restart computer again

This is provided you have WSL 2 integration enabled in docker (WSL 1 does not work for me), and ip traffic is allowed in Symantec Endpoint Protection. No editing of /etc/resolv.conf or /etc/wsl.conf was necessary

@kunzjacq
Copy link

It took forever to figure this out so I'll document it here in case someone comes along and finds this. I used Microsoft Message Analyzer with the Hyper-V-VmSwitch and NDIS-PacketCapture providers, which will show exactly how the internal switches are routing packets.

image

This allowed me to see the outbound TCP packets, the inbound TCP responses, and that they were being filtered at the switch level due to a VLAN tag.

MessageNumber	DiagnosisTypes	Timestamp	TimeElapsed	Source	Destination	Module	Summary	
502	None	2020-03-20T16:21:09.3340883				Microsoft_Windows_Hyper_V_VmSwitch	NBL 0xFFFF90079978BA40 received from Nic 14B75DAC-3764-4D7F-84B6-8F39004014B2 (Friendly Name: WSL) in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL)	
503	None	2020-03-20T16:21:09.3340929				Microsoft_Windows_Hyper_V_VmSwitch	NBL originating from Nic 14B75DAC-3764-4D7F-84B6-8F39004014B2 (Friendly Name: WSL) was dropped in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL), Reason VLAN Filtered (Status:Unknown NTSTATUS Error code (0xE0000003))	

... was dropped in switch D57EE459-57B6-4965-B86E-1906ABAECB70 (Friendly Name: WSL), Reason VLAN Filtered

My network port was slightly misconfigured and VLAN tagged packets were being sent to my system, but I had never noticed before because nothing connected to this switch port had ever cared before. Windows didn't care (and didn't show me, either, when using Wireshark/npcap). WSL1 also didn't care that inbound packets were tagged. WSL2, however, uses hyper-v switches, which do care about VLAN tags and silently drop packets that are tagged.

Fixing my network port to strip packets of VLAN tags fixed my issue and the hyper-v switches now work fine.

I think I have a similar problem: the symptom is exactly the same (DNS works but ping does not), and my physical network interface is on a VLAN. with Wireshark, when observing the vEthernet interface corresponding to the Hyper-V WSL switch, I see both the ping request and the answer. However I do not know if there is a way to make the WSL Hyper-V switch to ignore or remove the VLAN tags of incoming packets. Doas anyone know if there is a way to do this?

@jramiresbrito
Copy link

Fixed by applying this #5336 (comment)

============================================================================= FIX WSL2 NETWORKING IN WINDOWS 10 cmd as admin: wsl --shutdown netsh winsock reset netsh int ip reset all netsh winhttp reset proxy ipconfig /flushdns

Windows Search > Network Reset

Restart Windows

This worked like a charm for me in W11 and WSL2

@felipecrs
Copy link

For those using Symantec Endpoint Protection, I shared a workaround at MicrosoftDocs/WSL#1046 (comment).

Perhaps it could be useful for other firewalls as well.

@mabasic
Copy link

mabasic commented Jan 14, 2022

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.

@Nazeim
Copy link

Nazeim commented Jan 26, 2022

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.

IT WORKED, without even a reboot.

@knutov
Copy link

knutov commented Mar 27, 2022

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

works for dns and http[s], but not for ssh from wsl2 to external network

@knutov
Copy link

knutov commented Mar 27, 2022

sudo ip link set dev eth0 mtu 1350 fixes all other problems (see #4253 for details)

@ManalLiaquat
Copy link

Nothing works for me, so I gave my windows user Administrative access and reinstall the WSL and then It works like a charm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests