DEV Community

Victor Maina
Victor Maina

Posted on

How I Fixed WSL2's "100% Packet Loss" Networking Bug in Under 10 Minutes

If you've ever launched Ubuntu in WSL2 only to discover there's no internet connectionping fails, DNS doesn't resolve, and apt update hangs forever—you're not alone.

I recently ran into this issue while my Windows host had a perfectly working internet connection, yet my WSL2 instance behaved as if it were completely offline.

After trying nearly every solution recommended online, the fix turned out to be surprisingly simple.

This post explains what didn't work, what actually fixed it, and why.


The Problem

Inside my WSL2 Ubuntu 24.04 instance:

ping 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

returned:

100% packet loss
Enter fullscreen mode Exit fullscreen mode

Trying DNS wasn't any better:

ping google.com
Enter fullscreen mode Exit fullscreen mode

produced:

Temporary failure in name resolution
Enter fullscreen mode Exit fullscreen mode

Even basic package management failed:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

It simply timed out because the Linux environment had no network connectivity.

Meanwhile...

  • ✅ Windows could browse the web normally.
  • ✅ Wi-Fi was connected.
  • ✅ Other Windows applications had internet access.

The problem existed only inside WSL2.


What Didn't Work

Like many developers, I followed the usual troubleshooting advice first.

Unfortunately, none of these solved the issue:

  • Editing /etc/resolv.conf
  • Making resolv.conf immutable using chattr
  • Running:
netsh winsock reset
Enter fullscreen mode Exit fullscreen mode
  • Running:
netsh int ip reset
Enter fullscreen mode Exit fullscreen mode
  • Restarting WSL
  • Restarting Windows
  • Manually configuring DNS servers

These are common fixes for DNS problems, but in my case the issue was much deeper.

The real culprit wasn't DNS.

It was the virtual networking layer that WSL2 uses.


The Fix: Enable Mirrored Networking

The solution was adding a .wslconfig file in my Windows user profile.

Open PowerShell as Administrator and run:

notepad "$env:USERPROFILE\.wslconfig"
Enter fullscreen mode Exit fullscreen mode

Add the following configuration:

[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=false
Enter fullscreen mode Exit fullscreen mode

Save the file.

Then completely shut down WSL:

wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

Finally, start WSL again:

wsl
Enter fullscreen mode Exit fullscreen mode

That's it.

Immediately afterwards:

ping 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

returned:

3 packets transmitted, 3 received, 0% packet loss
Enter fullscreen mode Exit fullscreen mode

Network connectivity was restored.


Why This Works

By default, WSL2 uses a NAT-based virtual network adapter.

Think of it as a virtual switch sitting between Windows and Linux.

Normally this works well, but it can become corrupted or misconfigured after:

  • Windows updates
  • Sleep and wake cycles
  • VPN usage
  • Firewall changes
  • Hyper-V networking issues

When that virtual switch breaks, your Linux instance loses its route to the outside world—even though Windows itself still has internet access.

Setting:

networkingMode=mirrored
Enter fullscreen mode Exit fullscreen mode

changes how WSL2 connects to the network.

Instead of relying on a separate virtual NAT adapter, WSL2 mirrors the Windows host's network interface directly.

Adding:

dnsTunneling=true
Enter fullscreen mode Exit fullscreen mode

allows DNS queries to flow through the Windows networking stack, avoiding many name-resolution issues.

In my case, disabling the WSL firewall with:

firewall=false
Enter fullscreen mode Exit fullscreen mode

also eliminated the remaining networking restrictions.

The result was a stable connection that survived restarts and behaved much more reliably than the default NAT configuration.


Verify the Fix

After restarting WSL, test a few commands:

ping 8.8.8.8
Enter fullscreen mode Exit fullscreen mode
ping google.com
Enter fullscreen mode Exit fullscreen mode
curl https://example.com
Enter fullscreen mode Exit fullscreen mode
sudo apt update
Enter fullscreen mode Exit fullscreen mode

If all four work, your networking stack has been restored successfully.


Key Takeaway

If:

  • Windows has internet,
  • WSL2 does not,
  • ping 8.8.8.8 fails,
  • and every DNS tutorial you've tried hasn't helped,

there's a good chance the problem isn't DNS at all.

It's the virtual networking layer.

Enabling mirrored networking through .wslconfig solved the issue instantly for me, and it's now one of the first things I'll check whenever WSL2 suddenly loses connectivity.

Hopefully, it saves you the same hours of troubleshooting it saved me.


Have you run into other WSL2 networking issues?

I'm curious to hear what caused them and how you fixed them. Share your experience in the comments—your solution might help the next developer searching for "WSL2 no internet."

Top comments (0)