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.
@ghenadiibatalski I recently did a fresh install of everything on Windows 11 with WSL2 and ubuntu 22, no such luck. It has the same issues as I had on Windows 10.
The
[boot]
command works well, though I modified it a bit to include the bridge IP that is potentially recreated during WSL restarts. After adding this bit into/etc/wsl.conf
, exit wsl and restart it by usingwsl --shutdown
in a terminal. Re-open your wsl instance afterward, and it will have generated the updated/etc/resolv.conf
file with the combined nameservers.When the
resolv.conf
is recreated during wsl2 boot, it has the bridge IP in it as the nameserver, and I wanted to retain that for other reasons. Feel free to move$(cat /etc/resolv.conf)
around based on your needs. In my case, I only need one main, working DNS toward the top of the list so that things likebrew
andterraform
can work properly.Others who have several other DNS configs for VPN adapters, etc., may need those auto generated settings as well.
Description of how it works
$(cat /etc/resolv.conf)
printf
command injects the result of that after the first nameserver, and before the other two (configure as needed)command = "<full command>"
, so they are escaped:\"
/etc/resolv.conf
.Update 2023-08-09
I just realized I had the command writing to
resolve.conf
, notresolv.conf
like I had in bullet point 4, above. I updated the script to use the correct file nameresolv.conf
.Due to this comment being buried by newer comments, I've moved it to a separate gist here: https://gist.github.com/ps2goat/f885ad790178ed9e8012b0681a0ef61d