If you're encountering ping github.com
failing inside WSL with a Temporary failure in name resolution
, you're not alone — this has been a long-standing issue, especially when using VPNs or corporate networks.
This issue is now fixed robustly with DNS tunneling, which preserves dynamic DNS behavior and avoids limitations like WSL’s former hard cap of 3 DNS servers in /etc/resolv.conf
.
DNS tunneling is enabled by default in WSL version 2.2.1 and later, meaning that if you're still seeing DNS resolution issues, the first and most effective fix is simply to upgrade WSL. Upgrading WSL updates the WSL platform itself, but does not affect your installed Linux distributions, apps, or files.
To upgrade WSL, follow these steps,
# Run all of the following in a Windows terminal (PowerShell, Command Prompt, etc.)
# 1. Check your current WSL version
wsl --version
# 2. Close all open *WSL windows* — any Linux terminals running via WSL (Ubuntu, Debian, etc.)
# 3. Shut down the WSL subsystem
wsl --shutdown
# 4. Upgrade WSL
wsl --upgrade
# 5. Verify the upgrade was successful (version should now be >= 2.2.1)
wsl --version
# 6. Open your WSL terminal and test
ping github.com
# 🎉 If it works, drop a comment on this Gist and tell us how happy you are.
If needed, explicitly enable tunneling by creating (source):
# C:\Users\<YourUsername>\.wslconfig
[wsl2]
dnsTunneling=true
That’s it. No more messing with /etc/resolv.conf
. No more weird hacks!
Preserved for historical transparency and for users unable to upgrade WSL.
# In WSL
cd /etc
echo "[network]" | sudo tee wsl.conf
echo "generateResolvConf = false" | sudo tee -a wsl.conf
# Back in Windows
wsl --terminate <DistroName> # or use wsl --shutdown
# Back in WSL
sudo rm -f /etc/resolv.conf
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
If you're using a VPN like Cisco AnyConnect:
Get-NetAdapter | Where-Object { $_.InterfaceDescription -Match "Cisco AnyConnect" } | Set-NetIPInterface -InterfaceMetric 6000
Big thanks to,
- @ThePlenkov/(comment) — the first to publicly document the DNS tunneling fix in
.wslconfig
(WSL 2.2.1+) - @skudbucket — for confirming and spreading awareness
- @MartinCaccia, @yukosgiti, @machuu, @AlbesK — for documenting earlier workarounds
- GitHub Issue #4277
- GitHub Issue #4246
- Legacy fix from #4285
- WSL DNS Tunneling Docs
- WSL Config Docs
- WSL 2.2.1 Release Notes
If you're still using manual resolv.conf hacks in 2024+, you're solving a problem that's already been solved.
DNS on WSL2 STILL JUST BREAKS: CLOSING THOUSANDS OF BUG REPORTS ON THIS 10 YEAR OLD BUG (WHICH IS NOT FIXED) IS WEIRD!
I have implemented that hard coded DNS solution (above) and it is a lot better, but WSL2 still looses it's DNS even if you disconnect briefly and reconnect your IPsec VPN. Once that happens still have to reboot. (I am running WSL2 on top end Dell laptop with up-to-date bios and Windows 10.)
When running ordinary applications under Windows or on a Linux PC, any disconnection of the network and reconnection allows all applications to reconnect to the network no problem; not so with WSL! When running WSL, DNS resolution is lost even with a brief disconnection or the lease time on the network driver laps and reconnects, after that you can’t connect or even ping devices unless you reboot!
Even with millions of complaints, and thousands of bug reports, this bug has been persistent for almost a decade and NOT FEXED IN JULY 2023! This is so serious many developers avoid all Docker development under WSL and Windows. When Windows programmers write Linux network code, what could possibly go wrong?
WSL team members even close bug reports rather than combine the data from thousands of similar reports. When reports are closed so that others can’t comment the geniuses have magically fixed the major bug right? NOT! The use of Docker Desktop makes it 100 times worse, but fortunately Docker Desktop is NOT Docker and many people run WSL2 without Docker Desktop.