Every time WSL 2 restarts, it overwrites /etc/resolv.conf with DNS settings from your Windows host. If you’ve manually set custom DNS servers, they get wiped on the next boot. This guide shows you how to make resolv.conf changes permanent in WSL 2 so your DNS configuration survives restarts.
Why WSL 2 Overwrites resolv.conf
By default, WSL 2 auto-generates /etc/resolv.conf as a symlink that mirrors your Windows DNS settings. This works for most people, but breaks when you need custom DNS — for example, when you’re on a VPN, using a corporate DNS server, or need public DNS like Google’s 8.8.8.8 to resolve external endpoints.
If you’re experiencing DNS-related internet issues, see Resolving Internet Connection Issues in WSL 2 on Ubuntu for the full troubleshooting guide.
Step 1: Disable Auto-Generation
Tell WSL to stop generating /etc/resolv.conf automatically by editing /etc/wsl.conf:
sudo nano /etc/wsl.conf
Add these lines (or append to existing content):
[network]
generateResolvConf = false
Save the file (Ctrl+O, Enter, Ctrl+X).
Step 2: Create a Custom resolv.conf
The existing /etc/resolv.conf is a symlink to an auto-generated file. Remove it and create a regular file in its place:
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf
Add your DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4
These are Google’s public DNS servers. You can use any DNS provider — Cloudflare (1.1.1.1), Quad9 (9.9.9.9), or your corporate DNS. If you need both public and internal DNS, list them in order of priority:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 10.0.0.1
DNS servers are tried in order. Public DNS first ensures external domains resolve quickly, while internal DNS handles corporate resources.
Step 3: Restart WSL
The wsl.conf change takes effect after a full WSL restart. From PowerShell or Windows Terminal:
wsl --shutdown
Reopen your WSL terminal.
Step 4: Verify
Check that your custom DNS is in place:
cat /etc/resolv.conf
You should see your manually configured nameservers, not the auto-generated content. Test that DNS resolution works:
ping -c 2 google.com
Alternative: Use DNS Tunneling Instead
On Windows 11 22H2 and later, WSL supports DNS tunneling — a feature that resolves DNS through a virtualization layer instead of relying on /etc/resolv.conf at all. This is the better option if you frequently switch between VPN and direct connections, since it handles DNS changes automatically.
Create or edit %USERPROFILE%\.wslconfig in Windows (e.g., C:\Users\YourName\.wslconfig):
[wsl2]
dnsTunneling = true
Then restart WSL with wsl --shutdown. With DNS tunneling enabled, you don’t need to disable generateResolvConf or manage /etc/resolv.conf manually.
How to Revert
If you want to go back to the default behavior, edit /etc/wsl.conf and either remove the [network] section or set:
[network]
generateResolvConf = true
Delete your custom /etc/resolv.conf and restart WSL. It will recreate the symlink automatically.
Conclusion
Your custom DNS settings now persist across WSL restarts. The wsl.conf approach works on any version of WSL 2, while DNS tunneling is the modern alternative for Windows 11 users. If DNS issues are causing tools like GitHub Copilot to time out, see Fixing GitHub Copilot Chat “Took Too Long to Get Ready” in VS Code. For general WSL setup, check out How to Install Ubuntu 20.04 or 22.04 in WSL 2 on Windows 10.


