Monday 31 December 2018

windows 10 WSL ubuntu unable to ping anything


I cannot ping any website when I am using WSL for windows 10. I'm running Ubuntu 18.04 in WSL.


--- google.com ping statistics ---
14 packets transmitted, 0 received, 100% packet loss, time 38567ms

is the result when I try ping google.com I am using windows 10 with IPv4, disabled IPv6. I can ping google.com normally without wsl on my regular command prompt


I'm running Avast internet security and when I ping google from inside the ubuntu/WSL instance this is what I see.


1: enter image description here


What do I need to do to enable pinging in WSL



Answer



First some background. One should need Windows 10 Build 17627 or higher to support Firewall with WSL connections. Here is the section from WSL release notes:



Build 17627 (Skip Ahead)


WSL



  • Windows firewall support for WSL processes. [GH 1852]

    • For example, to allow the WSL python process to listen on any port, use the elevated Windows cmd: netsh.exe advfirewall firewall add rule name=wsl_python dir=in action=allow program="C:\Users\\AppData\Local\Packages\canonicalgrouplimited.ubuntuonwindows_79rhkp1fndgsc\localstate\rootfs\usr\bin\python2.7" enable=yes

    • For additional details on how to add firewall rules, see link





Next step, find absolute path of the Linux executable that wants Internet connection. The full path can be divided into three parts:



  1. C:\Users\UserName\AppData\Local\Packages -- Path where Universal Windows Platform apps store user specific files, temporary files etc.

  2. CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs -- Path where Ubuntu 18.04 Appx package store Ubuntu usersapce files i.e. /bin, /etc, /usr and others.

  3. \bin\ping -- Linux ping binary.


Hence the whole path is:


C:\Users\UserName\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\bin\ping

You can use the following PowerShell script to get that path. Just enter ubuntu when it asks to enter Distribution name.


$DistroName=Read-Host "Enter Distribution Name"
$pacakgeName = (Get-AppxPackage *$DistroName*).PackageFamilyName
$appData = [System.Environment]::ExpandEnvironmentVariables("%LocalAppData%")
$InstallDir = $appData + "\Packages\" + $pacakgeName + "\LocalState\rootfs"
echo $InstallDir
Invoke-Item $InstallDir
Read-Host -Prompt "Press any key to continue..."

Final step, add the firewall rule. For Windows Firewall, run this command as administrator to add Outbound firewall rule.


netsh.exe advfirewall firewall add rule name=wsl_ping dir=out action=allow program= enable=yes

For Avast Firewall, follow this instruction from Avast Support. Open Settings > General > Exclusion and add the path from previous step.


Canonical answers:



No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...