Resolving Internet Connection Issues in WSL 2 on Ubuntu

If your WSL 2 Ubuntu instance can’t reach the internet — ping fails, apt update hangs, or you get “Temporary failure in name resolution” — the problem is almost always DNS. WSL auto-generates its DNS config, and it often breaks when you’re on a VPN, corporate network, or after a Windows update. This guide covers multiple ways to fix WSL 2 internet connection issues, from the quickest to the most permanent.

Confirm the Problem

Open your WSL terminal and run:

ping -c 4 google.com

If you see Temporary failure in name resolution or the command hangs, DNS is not working. Your WSL instance can’t translate domain names to IP addresses.

Resolving Internet Connection Issues in WSL 2 on Ubuntu

Also check what DNS server WSL is currently using:

cat /etc/resolv.conf

If the nameserver entry points to an unreachable IP or a VPN-provided DNS that doesn’t resolve public domains, that’s the root cause.

Fix 1: Update WSL (Quickest Fix)

WSL version 2.2.1 and later includes DNS tunneling enabled by default. This feature resolves DNS requests through a virtualization layer instead of relying on /etc/resolv.conf, which fixes most DNS issues automatically — especially on VPNs.

From PowerShell or Windows Terminal (not WSL):

wsl --shutdown
wsl --update

After the update, reopen your WSL terminal and test with ping google.com. If it works, you’re done.

Check your WSL version with:

wsl --version

If the WSL version is 2.2.1 or higher and you still have issues, move to the next fix.

Fix 2: Set DNS Manually (Quick Fix)

Override the auto-generated DNS config with public DNS servers:

sudo nano /etc/resolv.conf

Replace the existing nameserver lines with:

nameserver 8.8.8.8
nameserver 8.8.4.4

Save the file (Ctrl+O, Enter, Ctrl+X), then test again:

ping -c 4 google.com

This works immediately, but WSL will overwrite /etc/resolv.conf the next time it restarts. See the next section to make it permanent.

Fix 3: Make DNS Changes Permanent

WSL auto-generates /etc/resolv.conf on every startup. To keep your custom DNS settings, you need to disable that behavior. For a detailed walkthrough, see How to Make Resolve Config Changes Permanent in WSL 2. Here’s the short version:

1. Disable auto-generation

Edit (or create) /etc/wsl.conf:

sudo nano /etc/wsl.conf

Add:

[network]
generateResolvConf = false

2. Set your DNS servers

Remove the old symlink and create a new file:

sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf

Add:

nameserver 8.8.8.8
nameserver 8.8.4.4

If you also need access to internal corporate resources, add your corporate DNS below the public ones:

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 10.0.0.1

3. Restart WSL

From PowerShell:

wsl --shutdown

Reopen your WSL terminal. Your DNS settings will persist across restarts.

Fix 4: Enable DNS Tunneling and Mirrored Networking

On Windows 11 22H2 and later, WSL supports DNS tunneling and mirrored networking mode. DNS tunneling resolves DNS through a virtualization layer (bypassing /etc/resolv.conf entirely), and mirrored mode mirrors your Windows network interfaces into WSL for better VPN and proxy compatibility.

Create or edit %USERPROFILE%\.wslconfig in Windows (for example, C:\Users\YourName\.wslconfig):

[wsl2]
networkingMode = mirrored
dnsTunneling = true

Then restart WSL from PowerShell:

wsl --shutdown

This is the best option if you frequently switch between VPN and direct connections.

Still Not Working?

If none of the fixes above resolve the issue:

  • Reset Windows network adapters — open PowerShell as Administrator and run netsh winsock reset, then restart your computer. This resets the Windows networking stack that WSL depends on.
  • Disable and re-enable the WSL adapter — in Windows, open Network Connections (ncpa.cpl), find the vEthernet (WSL) adapter, right-click and disable it, then enable it again.
  • Check your VPN — some VPN clients (especially Cisco AnyConnect) override DNS settings aggressively. The mirrored networking mode from Fix 4 usually handles this, but you may also need to add your VPN’s DNS server to /etc/resolv.conf.
  • Verify Windows has internet — make sure your Windows host machine can reach the internet. If Windows itself has no connection, WSL won’t either.

Verify the Fix

Once you’ve applied a fix, confirm everything works:

ping -c 4 google.com

You should see successful replies with response times.

Resolving Internet Connection Issues in WSL 2 on Ubuntu

You can also test DNS resolution directly:

nslookup google.com

Conclusion

WSL 2 internet issues are almost always caused by DNS misconfiguration. Updating WSL to get DNS tunneling is the easiest fix. If that doesn’t work, manually setting DNS servers in /etc/resolv.conf and making the change permanent with wsl.conf will. If you’re also having trouble with tools that depend on WSL networking, see Fixing GitHub Copilot Chat “Took Too Long to Get Ready” in VS Code. For setting up your WSL development environment, check out How to Install Ubuntu 20.04 or 22.04 in WSL 2 on Windows 10.