11

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

2 Answers2

3

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\<UserName>\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=<path_to_ping> enable=yes

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

Canonical answers:

Biswapriyo
  • 11,584
0

I had the same issue where a local internet ip was set up in my wsl, and restarting caused it to be re-added....

I found launching from powershell with debian.exe was better than with wsl.exe for some unknown reason: I did check, and it is the same instance.

Resolved this by modifying two files: sudo nano /etc/resolv.conf needed the nameserv removed and changed to 1.1.1.1 or 8.8.8.8 (probably would be okay to remove it all together, may even be okay to keep it--still testing--.

So, it should look like this:

nameserv 1.1.1.1

And it's also worth noting I had to do this:

cd /etc
sudo nano resolv.conf

Because sudo nano /etc/resolv.conf resulted in "directory does not exist" errors at the bottom of nano.

The second one might be the only one that was necessary: I used sudo nano /etc/wsl.conf and had to add

[network]
generateResolvConf = false

You could also add permissions so you won't need to use sudo just to ping....

which ping
sudo visudo
your_username ALL=(ALL) NOPASSWD: etc/bin/ping 

You add the third line to the visudo file. Yes, you need the full address of the executable which is seen via which.

Wolfpack'08
  • 1,364