I have been having network issues with WSL 2 and VPN. Outside of WSL2 my Internet works fine over the VPN. Inside of WSL2 I cannot connect to anything, either within the VPN boundaries or the outside Internet. Ping to 8.8.8.8 does not work (100% packet loss), the same for local destinations. Traceroute does not make a single hop and just hangs.
I have tried switching to WSL 1, which breaks my Docker and does not fix my Networking issues.
I also tried changing the "InterfaceMetric" in Powershell, ie.:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "PANGP Virtual Ethernet Adapter"} | Set-NetIPInterface -InterfaceMetric 6000
This lets me ping 8.8.8.8 without issue, but I'm unable to use commands like git or curl.
During my quest to find the answer to this I have heard many tales of partial functionality after repeated reboots, flipping between WSL 1 and WSL 2, but no solution that provides a fix that will let me move on.
Any help?
CodePudding user response:
I have faced the same issue, and gone through the exact same experience, mostly because I am you and you are me, but I have come across a solution that appears to work consistently. It is based on this blog post by Jan Ove Skogheim. I went through the steps manually, taking the time to pore through the wall of IP addresses and finding the:
- WSL IP address
- WSL subnet mask
- VPN adapter IP address
- VPN adapter’s interface index
And putting them together in a single 'route delete' command, and after (passionately) executing it about 8 times (to which, each time Powershell responded 'Ok!', but didn't do what I asked) the route was finally deleted.
I flipped back to my WSL2 window and lo' and behold my connection was restored!
But, wait, there's more...
The manual searching through a faceful of text in Powershell (elevated) is no easy Autumn kayak ride around the bayou, while sipping a margarita. Its somewhat painful trying to kick-start my brain into remembering the last 5 or 6 digits of multiple IP addresses, or even worse, cut-and-pasting each one into a notepad window so I can put together the route delete
command by hand.
And, since I have already waded out here into the muck and am knee-deep in the mess, I might as well go on a bit longer, so that somebody else might have an easy afternoon...I worked through some not-so-elegant Powershell commands to pull those variables out and put them in a command for you.
Now, mind you, cut-and-paste may not work because your VPN adapter or your WSL Interface might be named differently but I think if you fiddle with it a little bit, there might be something useful in this conglomeration of code.
Powershell commands:
# get Internet info for WSL adapter, but grep the line with subnet and then use regex to get
# the subnet ip and the subnet mask
$wsl_info = netsh interface ip show address "vEthernet (WSL)" | findstr "Subnet Prefix"
$results = $wsl_info -match 'Subnet Prefix:\s (.*)\/.*\(mask\s(.*)\)'
$wsl_network_dest_ip = $Matches[1]
$wsl_subnet_mask = $Matches[2]
echo "WSL destination IP = $wsl_network_dest_ip"
echo "WSL subnet mask = $wsl_subnet_mask"
# Get VPN Ethernet adapter IP
$vpn_info = netsh interface ip show address "Ethernet 2" | findstr "IP Address"
$results = $vpn_info -match 'IP Address:\s (.*)'
$vpnadapter_ip = $Matches[1]
echo "VPN Eth Adapter IP = $vpnadapter_ip"
# Get VPN adapter’s interface index (May need to change VPN adapter -InterfaceDescription with your own here. You can get it from ipconfig /all)
$vpn_ifIndex = Get-NetAdapter -InterfaceDescription "PANGP Virtual Ethernet Adapter" | Select -ExpandProperty "ifIndex"
echo "VPN ifIndex value = $vpn_ifIndex"
echo 'Attempting to delete route...'
$result = ''
$x = 1
while ($result -ne 'The route deletion failed: Element not found.') {
echo "Try $x..."
route delete $wsl_network_desk_ip mask $wsl_subnet_mask 0.0.0.0 if $vpn_ifIndex
Start-sleep -s 1
$x
}
echo 'Done'
I'm sure Microsoft will get this patched up soon, but until then I hope this might help someone.
CodePudding user response:
just use vpnkit it solves all vpn issues