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
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.
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-NetNatreturns no results:When trying to set up a new NAT rule, I get a seemingly unrelated error: