How to Fix WSL2 DNS Resolution Issues on Windows (No Internet in WSL)
— LiveStream

Your WSL2 Ubuntu was working yesterday. Today apt update hangs, ping google.com says 'Temporary failure in name resolution', but Windows itself is online. It's a DNS problem inside WSL2 — and here is how to fix it for good.
Why WSL2 loses DNS
WSL2 runs in a lightweight VM behind a virtual NIC. It auto-generates /etc/resolv.conf from Windows, but VPNs, corporate networks, and Windows updates frequently break that hand-off, leaving WSL with a nameserver it can't reach.
The quick fix — set a working nameserver
Stop WSL from auto-generating resolv.conf, then point it at a public resolver:
# in WSL, create /etc/wsl.conf
sudo tee /etc/wsl.conf <Then from PowerShell, restart WSL so the change loads:
wsl --shutdownIf you are on a VPN
Corporate VPNs often need WSL to use the VPN's DNS. Either set the nameserver to your VPN's resolver, or mirror Windows networking (Windows 11 22H2+): add networkingMode=mirrored under [wsl2] in %UserProfile%\.wslconfig and shut down WSL.
Common mistakes to avoid
- Editing resolv.conf without disabling generateResolvConf — WSL overwrites it on restart.
- Forgetting
wsl --shutdown— changes don't apply to a running distro. - Using only an internal DNS that the WSL VM can't route to.
Key takeaways
- WSL2 DNS breaks when the Windows hand-off fails (VPN/updates).
- Disable generateResolvConf, then set 8.8.8.8 / 1.1.1.1.
- Always
wsl --shutdownafter changes. - On VPNs, prefer mirrored networking mode.
- Make resolv.conf immutable (
chattr +i) if it keeps resetting.
FAQ
Q: Will this survive reboots?
A: Yes, once generateResolvConf=false. Use chattr +i /etc/resolv.conf to lock it.
Q: ping works but apt fails?
A: Likely a proxy, not DNS — check /etc/apt/apt.conf.d/ for stale proxy settings.
Q: Mirrored mode — which Windows?
A: Windows 11 22H2 and later.
For more practical fixes and tech walkthroughs, subscribe to @explorenystream. Found this useful? Share it with someone fighting the same error.