WSL2 DNS Resolution Fix – Complete Guide (2026)

WSL2 DNS resolution fix is one of the most common searches for developers and IT professionals using Windows Subsystem for Linux 2. When you encounter “Temporary failure in name resolution,” “Could not resolve hostname,” or DNS resolution stops working entirely, your WSL2 environment becomes effectively unusable for package management, git operations, and cloud interactions. According to Microsoft’s WSL troubleshooting documentation, DNS issues in WSL2 often stem from the automatic generation of /etc/resolv.conf that can overwrite custom DNS settings. This comprehensive WSL2 DNS resolution fix guide covers 10 proven methods to diagnose and resolve DNS issues.

When you search for a WSL2 DNS resolution fix, you are likely dealing with a scenario where ping 8.8.8.8 works but ping google.com fails, or sudo apt update returns “Temporary failure resolving ‘archive.ubuntu.com’.” According to a detailed CSDN analysis, the core issue is often that WSL automatically generates and overwrites /etc/resolv.conf, invalidating custom DNS settings[reference:0]. This WSL2 DNS resolution fix guide walks you through every step needed to restore DNS functionality.

Quick Overview: The fastest way to start your WSL2 DNS resolution fix is to open your WSL distribution and run: sudo rm /etc/resolv.conf, then sudo nano /etc/wsl.conf and add [network] generateResolvConf = false, then sudo nano /etc/resolv.conf and add nameserver 8.8.8.8. Finally, in PowerShell, run wsl --shutdown and restart WSL. This WSL2 DNS resolution fix guide covers all the details you need.

1. Understanding WSL2 DNS Resolution Issues

WSL2 uses a virtualized network stack that relies on NAT (Network Address Translation) to communicate with the host. DNS resolution is handled through the /etc/resolv.conf file, which WSL automatically generates at startup[reference:1].

Common causes of WSL2 DNS issues include:

  • Automatic resolv.conf overwrite: WSL regenerates /etc/resolv.conf each time it starts, overwriting custom DNS settings[reference:2].
  • VPN conflicts: When connected to a VPN, WSL2 may lose DNS resolution[reference:3].
  • Mirrored networking issues: In Windows 11 mirrored mode, the DNS resolver may enter a loop[reference:4].
  • DNS tunneling conflicts: The dnsTunneling feature can conflict with VPNs or third-party firewalls[reference:5].
  • ICS Service failure: The Internet Connection Sharing (ICS) service must be running for WSL2 networking[reference:6].

Understanding these root causes is the first step in any WSL2 DNS resolution fix guide.

2. WSL2 DNS Resolution Fix: Diagnose the Issue

Before applying fixes, you need to diagnose the exact problem. According to a detailed WSL2 troubleshooting guide, you should distinguish between DNS and routing issues[reference:7].

Step 1: Open your WSL2 terminal

Step 2: Test basic connectivity (should work if routing is fine):
    ping 8.8.8.8

Step 3: Test DNS resolution (will fail if DNS is broken):
    ping google.com
    nslookup google.com

Step 4: Check the current DNS configuration:
    cat /etc/resolv.conf

Step 5: Check the network route:
    ip route show

Step 6: If ping 8.8.8.8 works but ping google.com fails, you have a DNS issue

According to a CSDN guide, if nslookup fails but ping 8.8.8.8 succeeds, the problem is DNS configuration[reference:8].

Outcome: You have identified whether the issue is DNS‑specific or a broader network problem.

3. Disable Automatic resolv.conf Generation

Disabling automatic resolv.conf generation is the most important WSL2 DNS resolution fix. According to multiple sources, you must tell WSL not to automatically manage DNS[reference:9][reference:10].

Step 1: Open your WSL2 terminal

Step 2: Create or edit /etc/wsl.conf:
    sudo nano /etc/wsl.conf

Step 3: Add these lines:
    [network]
    generateResolvConf = false

Step 4: Save and exit (Ctrl+X, then Y, then Enter)

Step 5: Remove the existing resolv.conf (which may be a symlink):
    sudo rm /etc/resolv.conf

Step 6: Restart WSL from PowerShell:
    wsl --shutdown

Step 7: Reopen your WSL terminal

According to a Data Science Research Infrastructure guide, this prevents WSL2 from overwriting its own resolv.conf[reference:11]. A DNSFilter support article also confirms that setting generateResolvConf = false is essential for manual DNS configuration[reference:12].

Outcome: WSL no longer overwrites your DNS configuration.

4. Manually Configure DNS in resolv.conf

After disabling automatic generation, you need to manually set DNS servers. According to a Cloud DNS guide, you should add external DNS servers like Cloudflare or Google[reference:13].

Step 1: Create a new resolv.conf file:
    sudo nano /etc/resolv.conf

Step 2: Add DNS servers:
    nameserver 1.1.1.1
    nameserver 8.8.8.8
    nameserver 8.8.4.4

Step 3: Save and exit (Ctrl+X, then Y, then Enter)

Step 4: Make the file immutable (optional, prevents accidental overwrites):
    sudo chattr +i /etc/resolv.conf

Step 5: Verify the configuration:
    cat /etc/resolv.conf

Step 6: Test DNS resolution:
    ping google.com
    nslookup google.com

According to a guide from China, you can also use the WSL gateway IP as the DNS server for the most stable resolution[reference:14].

Outcome: DNS resolution is restored with manually configured servers.

5. Use the WSL Gateway IP as DNS Server

Using the WSL virtual gateway IP as the DNS server often provides the most stable WSL2 DNS resolution fix. According to a Win11 WSL2 guide, you can find the WSL gateway IP from the host[reference:15].

Step 1: On your Windows host, open PowerShell

Step 2: Find the WSL virtual adapter:
    ipconfig

Step 3: Look for "vEthernet (WSL)" and note its IPv4 address
    (e.g., 172.28.160.1)

Step 4: In your WSL terminal, edit resolv.conf:
    sudo nano /etc/resolv.conf

Step 5: Add the WSL gateway IP as the nameserver:
    nameserver 172.28.160.1

Step 6: Save and exit, then test DNS resolution

According to the guide, this gateway IP provides the most stable DNS resolution because it forwards requests through the host's network stack[reference:16].

Outcome: DNS queries are routed through the WSL virtual gateway for optimal resolution.

6. Enable DNS Tunneling in .wslconfig

DNS Tunneling is a recommended way to fix DNS issues in WSL2. According to a Microsoft Q&A, DNS Tunneling resolves DNS resolution issues while using VPNs[reference:17].

Step 1: On your Windows host, create or edit .wslconfig:
    notepad %USERPROFILE%\.wslconfig

Step 2: Add these lines:
    [wsl2]
    dnsTunneling=true

Step 3: Save and close the file

Step 4: Restart WSL:
    wsl --shutdown

Step 5: Reopen your WSL terminal

Step 6: Verify DNS resolution:
    ping google.com

According to a Medium article, WSL2 includes a feature called “DNS tunneling” where the WSL machine sends DNS packets on the loopback to a stub resolver on the host[reference:18]. This is often the most reliable WSL2 DNS resolution fix for VPN scenarios.

Outcome: DNS queries are tunneled through the host’s DNS resolver.

7. Switch to Mirrored Networking Mode

Mirrored networking mode resolves conflicts with VPNs and security software. According to a DNSFilter support article, switching WSL to mirrored networking mode resolves conflicts with roaming clients[reference:19].

Step 1: On your Windows host, create or edit .wslconfig:
    notepad %USERPROFILE%\.wslconfig

Step 2: Add these lines:
    [wsl2]
    networkingMode=mirrored

Step 3: Save and close the file

Step 4: Restart WSL:
    wsl --shutdown

Step 5: Reopen your WSL terminal

Step 6: Test DNS resolution:
    ping google.com

According to the DNSFilter article, this solution requires Windows 11 version 22H2 or later and WSL version 2.0.9 or later[reference:20]. This WSL2 DNS resolution fix is particularly effective when using VPNs or security software that interfere with WSL’s default NAT networking[reference:21].

Outcome: WSL uses mirrored networking, avoiding NAT-related DNS issues.

8. WSL2 DNS Resolution Fix: Restart ICS Service

The Internet Connection Sharing (ICS) Service is critical for WSL2 networking. According to a WSL troubleshooting guide, you should ensure the ICS service is running[reference:22].

Step 1: Press Windows + R, type "services.msc", and press Enter

Step 2: Find "Internet Connection Sharing (ICS)"

Step 3: Ensure "Startup type" is set to "Automatic"

Step 4: If the service is not running, right-click and select "Start"

Step 5: If it's already running, right-click and select "Restart"

Step 6: Restart WSL:
    wsl --shutdown

Step 7: Reopen your WSL terminal and test DNS

According to a WSL2 DNS troubleshooting guide, the ICS service must be running for WSL2 to resolve domain names[reference:23].

Outcome: The ICS Service is running, enabling proper DNS resolution.

9. Reset Network Stack and Flush DNS

Resetting the network stack can resolve persistent WSL2 DNS resolution fix issues. According to a Stack Overflow answer, you should reset Winsock and flush DNS[reference:24].

Step 1: Open PowerShell as Administrator

Step 2: Run these commands in order:
    wsl --shutdown
    netsh winsock reset
    netsh int ip reset all
    netsh winhttp reset proxy
    ipconfig /flushdns

Step 3: Restart your computer

Step 4: After restart, open WSL and test DNS resolution:
    ping google.com

According to a Stack Overflow answer, these commands reset network settings and clear DNS cache[reference:25].

Outcome: The network stack is reset, resolving corruption-related DNS issues.

10. Update WSL and Windows

Keeping WSL and Windows updated is essential for a reliable WSL2 DNS resolution fix. According to a GitHub reference, you should update WSL to the latest version[reference:26].

Step 1: Open PowerShell as Administrator

Step 2: Update WSL:
    wsl --update

Step 3: Check for Windows updates:
    Settings → Windows Update → Check for updates

Step 4: Install all available updates

Step 5: Restart your computer

Step 6: Open WSL and test DNS resolution

According to a GitHub troubleshooting guide, updating WSL to the latest version can resolve stability and networking issues[reference:27]. This WSL2 DNS resolution fix ensures you have the latest bug fixes and improvements.

Outcome: WSL and Windows are updated to the latest versions with networking fixes.

11. Frequently Asked Questions

Why does WSL2 have DNS resolution issues?

WSL2 DNS resolution issues are typically caused by the automatic generation and overwriting of /etc/resolv.conf, VPN conflicts, mirrored networking mode issues, or the ICS Service not running. According to a Win11 WSL2 guide, WSL automatically generates and overwrites /etc/resolv.conf, invalidating custom DNS settings[reference:28].

How do I fix “Temporary failure in name resolution” in WSL2?

Disable automatic resolv.conf generation by adding generateResolvConf = false to /etc/wsl.conf, manually configure DNS servers in /etc/resolv.conf, and restart WSL with wsl --shutdown. According to a DNSFilter guide, this is the most reliable fix[reference:29].

What is DNS tunneling in WSL2?

DNS Tunneling is a WSL2 feature where the WSL machine sends DNS packets on the loopback to a stub resolver on the host. According to a Medium article, this is an effective way to fix DNS issues in WSL2[reference:30].

How do I enable DNS tunneling in WSL2?

Create or edit %USERPROFILE%\.wslconfig and add [wsl2] dnsTunneling=true, then run wsl --shutdown and restart WSL.

What is mirrored networking mode in WSL2?

Mirrored networking mode makes WSL2 share the same network stack as Windows. According to a DNSFilter article, this resolves conflicts with VPNs and security software[reference:31].

Why does WSL2 lose DNS when connected to a VPN?

VPNs can interfere with WSL2’s NAT networking and DNS tunneling. According to a Data Science Research Infrastructure guide, you can fix this by disabling automatic DNS configuration and manually setting DNS servers[reference:32].

How do I find the WSL gateway IP for DNS?

Open PowerShell on Windows and run ipconfig. Look for the IPv4 address of the “vEthernet (WSL)” adapter. According to a Win11 WSL2 guide, this is the most stable DNS server for WSL2[reference:33].

What is the ICS Service and why does it affect WSL2 DNS?

The Internet Connection Sharing (ICS) Service provides NAT functionality for WSL2. According to a WSL2 DNS troubleshooting guide, this service must be running for WSL2 to resolve domain names[reference:34].

Can updating WSL fix DNS issues?

Yes. According to a GitHub troubleshooting guide, updating WSL to the latest version can resolve stability and networking issues[reference:35].

Where can I find more WSL2 troubleshooting help?

Explore our Windows 11 Troubleshooting Hub and guides on WSL2 DNS resolution and Hyper‑V network adapter not working.

12. Conclusion

WSL2 DNS resolution fix is an essential skill for any developer or IT professional using Windows Subsystem for Linux 2. This guide has covered 10 proven methods—from diagnosing the issue and disabling automatic resolv.conf generation to manually configuring DNS, enabling DNS tunneling, switching to mirrored networking, restarting the ICS Service, resetting the network stack, and updating WSL. According to Microsoft’s WSL troubleshooting documentation, DNS issues in WSL2 often stem from the automatic generation of /etc/resolv.conf that can overwrite custom DNS settings.

Start with the simplest fix — disabling automatic resolv.conf generation and manually configuring DNS — and escalate to more advanced solutions like DNS tunneling or mirrored networking only if needed.

For more Windows troubleshooting, explore our Windows 11 Troubleshooting Hub and guides on Hyper‑V network adapter not working and Device Manager network adapter missing.

With the right approach from this WSL2 DNS resolution fix guide, you can restore DNS functionality and keep your WSL2 development environment running smoothly.

Editorial Team
This article was researched and written by the HowToFixPro technical editorial team. Our team consists of Windows and Linux system administrators with years of experience in WSL2 configuration, network troubleshooting, and development environment optimization across multiple platforms.

2 thoughts on “WSL2 DNS Resolution Fix – Complete Guide (2026)”

  1. Pingback: WSL2 Proxy Configuration Guide – Complete (2026)

  2. Pingback: Windows Firewall WSL Traffic Fix – Complete Guide fast (2026)

Comments are closed.

Scroll to Top