Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

WSL2 cannot resolve names while a VPN is connected

ErrorTemporary failure in name resolution

Short 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.

  • Applies to Windows 11 23H2 and 24H2, Windows 10 22H2, WSL 2.x, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.com
  2. 2Match what you see, then jump to its fix

    1. 1resolv.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. 2Names fail in NAT mode only while the VPN is connectedThe NAT DNS proxy hides the DNS servers the VPN pushesFix
    3. 3Auto-generated resolv.conf never holds the DNS server your VPN requiresYou need a fixed nameserver that the VPN allowsFix

What does the error look like?

  • Temporary failure in name resolution
  • names 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\.wslconfig

2Fix

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=false

3Verify

Shut WSL down fully, start it again with the VPN connected and resolve a name.

# PowerShell
wsl --shutdown
# then, inside WSL
getent hosts github.com

Confirmed by learn.microsoft.com

Did this fix it?

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\.wslconfig

2Fix

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=false

3Verify

Restart WSL with the VPN connected and look at the new nameserver lines.

# PowerShell
wsl --shutdown
# then, inside WSL
cat /etc/resolv.conf

Confirmed by learn.microsoft.com

Did this fix it?

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.conf

2Fix

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.conf

3Verify

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.com

Confirmed by learn.microsoft.com

Did this fix it?

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

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 fix

Servers

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.