Skip to content

Instantly share code, notes, and snippets.

@coltenkrauter
Last active July 14, 2026 21:45
Show Gist options
  • Select an option

  • Save coltenkrauter/608cfe02319ce60facd76373249b8ca6 to your computer and use it in GitHub Desktop.

Select an option

Save coltenkrauter/608cfe02319ce60facd76373249b8ca6 to your computer and use it in GitHub Desktop.
Fix DNS resolution in WSL2

Permanent WSL DNS Fix (WSL 2.2.1+)

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!


🧟 Previous Workarounds (for WSL < 2.2.1 or locked-down systems)

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

πŸ™Œ Credit & Sources

Big thanks to,


If you're still using manual resolv.conf hacks in 2024+, you're solving a problem that's already been solved.

@ceedveed

ceedveed commented Aug 20, 2025

Copy link
Copy Markdown

dnsTunneling

The entire fix:

  1. Create .wslconfig under %USERPROFILE%
  2. Add:
[wsl2]
dnsTunneling=true

That's it. According to the documentation, it should be the default. Apparently it is not.

Thanks for this. Still needed as of WSL 2.5.10. This fixed my issue of Technitium DNS Server not working in Docker on a Windows host using WSL 2 backend.

EDIT: nevermind issue was a VPN using split tunneling that was causing the issue. Had to disable VPN.

@bluroz

bluroz commented Jan 12, 2026

Copy link
Copy Markdown

I am using win11 25h2 version but dnsTunneling=true setting did not work for me.

@seliel

seliel commented Jan 29, 2026

Copy link
Copy Markdown

Hi everyone! I'm still having this issue.

Default values, nothing works.

Created .wslconfig in %USERPROFILE%, added

[wsl2]
dnsTunneling=true

Didn't worked

Keeping that conf, In Ubuntu, file /etc/resolv.conf, added

[network]
generateResolvConf = true

Still a failure while conected to VPN

My specs:

Microsoft Windows 11 Enterprise
25H2

WSL version: 2.6.3.0
Kernel version: 6.6.87.2-1

Cisco Secure Client, Anyconnect

@mhkh8367

Copy link
Copy Markdown

Hi everyone,
I have used v2rayN and that worked

Test code:

$ git ls-remote https://github.com/nvm-sh/nvm.git | head

Result:

a6ec73943099a86fba98bde3b04a1c60944a4549 HEAD
df9ac58f8b73f7cdddad67396f1992acb0706b02 refs/heads/awk
edb47ffdea6567480fa93c4f196597489818a44d refs/heads/bionic
663c9968cbdad59b7b3d1dc38bec1db9535a02f0 refs/heads/block_iojs
d2f31a21f37e3c0ebf5365ac635af2e2e070fbe0 refs/heads/colors
4f91e99415484257b4678090c052f307d157e24e refs/heads/fix-3474
26066c10f42afdef9085a30f522b4e73cc2a4e59 refs/heads/fix-nvmrc-comment-hash
a6ec73943099a86fba98bde3b04a1c60944a4549 refs/heads/master
da5baa005b9f59f8f9f86002c85a2053f09494ba refs/heads/npm8
4a7275a0c60a5633b3924577ba5d048febd008b2 refs/heads/nvmrc


WSL Config:
Networking mode: NAT
DNS Tunneling enabled: checked
v2rayN config: Enable Tun: checked

or

Networking mode: Mirrored
DNS Tunneling enabled: not important
v2rayN config: Enable Tun: not important


v2rayN config:
System proxy: Set system proxy
Config:
vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIkBTT05JQ18yNTI0INqp2KfZhtin2YQg2LHZiNio24zaqdinINmIINiq2YTar9ix2KfZhSBcdUQ4M0RcdURENEHirZDvuI8iLA0KICAiYWRkIjogIjEwNC4xOC4xOS45OSIsDQogICJwb3J0IjogIjQ0MyIsDQogICJpZCI6ICJiNGE2NTYxMS00OTY5LTQyYjItYmM3NC01NzY4Yjk0MGJkOWUiLA0KICAiYWlkIjogIjAiLA0KICAic2N5IjogImF1dG8iLA0KICAibmV0IjogIndzIiwNCiAgInR5cGUiOiAiLS0tIiwNCiAgImhvc3QiOiAidnl2enloZ3ouY29tIiwNCiAgInBhdGgiOiAiLyIsDQogICJ0bHMiOiAidGxzIiwNCiAgInNuaSI6ICJ2eXZ6eWhnei5jb20iLA0KICAiYWxwbiI6ICIiLA0KICAiZnAiOiAiIg0KfQ==


OS Name: Microsoft Windows 11 Enterprise
OS Version: 10.0.26200 N/A Build 26200

WSL version: 2.7.8.0
Kernel version: 6.18.33.1-1
Windows version: 10.0.26200.8655

Virtualization: wsl
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 6.18.33.1-microsoft-standard-WSL2
Architecture: x86-64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment