WSL2 cannot resolve names while a VPN is connected
Temporary failure in name resolutionShort answer
WSL2 gets its DNS settings from Windows through a virtual network, and a VPN client can change what Windows resolves without WSL following. Check /etc/resolv.conf first. On Windows 11 switch to mirrored networking, or toggle dnsTunneling. On any version, turn dnsProxy off, or write your own resolv.conf.
Fix it fast
1Find out which cause you have
Look at what nameserver WSL is using, then test one name and one raw IP. If the IP works and the name does not, the network is fine and DNS is the problem.
cat /etc/resolv.conf ping -c 2 1.1.1.1 getent hosts github.com2Match what you see, then jump to its fix
- 1
resolv.conf lists the tunnelling address 10.255.255.254 (the default) and names stop resolving after the VPN connectsDNS tunneling does not follow the VPN's DNS (Windows 11)Fix - 2
Names fail in NAT mode only while the VPN is connectedThe NAT DNS proxy hides the DNS servers the VPN pushesFix - 3
Auto-generated resolv.conf never holds the DNS server your VPN requiresYou need a fixed nameserver that the VPN allowsFix
- 1
What does the error look like?
Temporary failure in name resolutionnames do not resolve inside WSL after the VPN connects, but pinging an IP address works
Cause 1 of 3
DNS tunneling does not follow the VPN's DNS (Windows 11)
1Check
On Windows 11 22H2 and later, dnsTunneling is on by default and answers DNS requests from inside WSL through Windows. Check whether a .wslconfig already sets it, then compare with the nameserver line.
# PowerShell
Get-Content $env:UserProfile\.wslconfig2Fix
Switch the network to mirrored mode, which is documented as improving VPN compatibility. Put this in %UserProfile%\.wslconfig, then restart WSL. If you already use mirrored mode, try dnsTunneling=false instead.
[wsl2]
networkingMode=mirrored
# alternative if mirrored is already on:
# dnsTunneling=false3Verify
Shut WSL down fully, start it again with the VPN connected and resolve a name.
# PowerShell
wsl --shutdown
# then, inside WSL
getent hosts github.comConfirmed by learn.microsoft.com
Cause 2 of 3
The NAT DNS proxy hides the DNS servers the VPN pushes
1Check
In NAT mode WSL points Linux at the NAT on the host (dnsProxy=true, the default). Setting dnsProxy=false makes WSL copy the DNS servers from Windows into Linux instead, so the VPN's servers are used directly. This setting only applies to NAT mode, so it does not work together with mirrored mode.
# PowerShell
Get-Content $env:UserProfile\.wslconfig2Fix
Turn the proxy off in %UserProfile%\.wslconfig. On Windows 10, where dnsTunneling and mirrored mode are not available, this is the setting to try first.
[wsl2]
networkingMode=nat
dnsTunneling=false
dnsProxy=false3Verify
Restart WSL with the VPN connected and look at the new nameserver lines.
# PowerShell
wsl --shutdown
# then, inside WSL
cat /etc/resolv.confConfirmed by learn.microsoft.com
Cause 3 of 3
You need a fixed nameserver that the VPN allows
1Check
By default WSL regenerates /etc/resolv.conf at every start. Any edit you make is overwritten unless generateResolvConf is false in the distribution's /etc/wsl.conf.
cat /etc/wsl.conf2Fix
Stop WSL generating the file, then write your own. Use the DNS server address your VPN or network administrator gives you.
# /etc/wsl.conf
[network]
generateResolvConf=false
# remove the generated file (it may be a symlink), then create your own
sudo rm -f /etc/resolv.conf
echo "nameserver 10.0.0.53" | sudo tee /etc/resolv.conf3Verify
Close every WSL window, wait for the VM to stop, start again and resolve a name.
# PowerShell
wsl --shutdown
# then, inside WSL
getent hosts intranet.example.comConfirmed by learn.microsoft.com
How do I stop it coming back?
- Keep one WSL setting change per test, and run wsl --shutdown after each one so the change really applies.
- Keep WSL itself current (the Microsoft Store version), because networking options such as dnsTunneling and mirrored mode only exist in recent releases (wsl --version shows yours).
- Write down which DNS servers your VPN pushes so you can compare them with resolv.conf.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
Temporary failure in name resolution on a Linux server
ping: example.com: Temporary failure in name resolution
The name lookup got no usable DNS server.
3 causes, each with a fixServers
Let's Encrypt cannot find the _acme-challenge TXT record for your domain
The TXT record added at the DNS host never shows up for validation
With the DNS-01 challenge, Let's Encrypt looks up a TXT record named _acme-challenge under your domain.
3 causes, each with a fixServers
Docker container cannot resolve hostnames (pip, apt, curl fail)
[Errno -3] Temporary failure in name resolution
A container copies its DNS settings from the host.
3 causes, each with a fixServers
Docker pull or container DNS fails with "server misbehaving"
docker pull fails while a browser on the same machine opens the registry fine
'Server misbehaving' is a Go resolver error: the DNS server answered, but with a reply code that is neither success nor name-not-found.
3 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fix