DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel
Explore NY Tech

How to Fix WSL2 DNS Issues

July 09, 2026 — LiveStream

How to Fix WSL2 DNS Issues
As an Amazon Associate I earn from qualifying purchases.
🛒 Recommended gear on Amazon

Disclosure: some links above are affiliate links — if you buy through them I may earn a small commission at no extra cost to you. Thanks for supporting the channel!

Embarking on a journey into the digital realm of Linux within your Windows environment with WSL2 (Windows Subsystem for Linux 2) is often a smooth expedition. It blends the best of both worlds, offering powerful development capabilities. However, even the most seasoned explorers encounter roadblocks, and a common stumbling block is the dreaded WSL2 DNS issues, leaving your Linux instances cut off from the internet. This comprehensive guide will equip you with the knowledge and tools to navigate these network challenges, ensuring your WSL2 environment enjoys seamless internet access and robust name resolution.

When your WSL2 instance struggles to connect to the internet, often manifesting as "Temporary failure in name resolution" errors, it's typically a sign of a misconfigured or non-functional DNS (Domain Name System) setup. This critical guide delves deep into the causes and provides step-by-step solutions to fix WSL2 DNS issues, transforming a frustrating dead end into a clear path forward.

Navigating the Digital Wilderness: Understanding WSL2 DNS Challenges

Picture your WSL2 instance as a vibrant, bustling base camp nestled within the vast landscape of your Windows operating system. It's a marvel of modern engineering, allowing you to run a full Linux kernel right alongside your Windows applications. But like any expedition, communication is key. DNS acts as your base camp's essential communication hub, translating human-readable website names (like google.com) into machine-readable IP addresses (like 142.250.190.46). When this system falters, your WSL2 instance becomes isolated, unable to locate external resources, download packages, or even ping a simple domain.

The intricate dance between Windows' networking stack and WSL2's virtualized environment can sometimes lead to connectivity woes. WSL2, by default, attempts to integrate seamlessly with your host machine's network configuration. It sets up a lightweight virtual network adapter, and crucially, it often dynamically generates its /etc/resolv.conf file based on the DNS servers configured on your Windows host. While this automation is convenient in theory, it's also the primary source of many WSL2 internet access issues.

Common scenarios that can disrupt WSL2's DNS resolution include:

Understanding these potential causes is the first step in charting a clear path to resolution. We're not just fixing a symptom; we're understanding the underlying terrain to prevent future missteps.

Charting Your Course: Essential Troubleshooting Steps to Fix WSL2 DNS

When your WSL2 instance finds itself stranded without internet connectivity, it's time to embark on a methodical troubleshooting expedition. This section outlines the most effective strategies to diagnose and fix WSL2 DNS issues, guiding you through each step with precision.

The First Aid Kit: Checking and Customizing `resolv.conf`

The /etc/resolv.conf file is the cornerstone of DNS resolution in Linux. By default, WSL2 attempts to manage this file automatically, populating it with DNS servers it detects from your Windows host. While convenient, this automation is often the culprit behind persistent DNS problems.

Step 1: Inspecting the Current `resolv.conf`

Open your WSL2 terminal and inspect the contents of your current resolv.conf:

cat /etc/resolv.conf

You'll likely see something similar to this, with an IP address from your host machine:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.XX.XX.XX

The nameserver entry points to an IP address that WSL2 uses as its DNS resolver, often an internal IP address assigned by your Windows host's virtual network adapter. If this IP address is unreachable or incorrectly configured, your DNS requests will fail.

Step 2: Taking Control – Disabling Automatic `resolv.conf` Generation

To gain full control over your WSL2's DNS configuration and prevent the system from overwriting your custom settings, you need to disable the automatic generation of /etc/resolv.conf. This is done by editing or creating the /etc/wsl.conf file.

First, it's good practice to back up your existing resolv.conf in case you need to revert:

sudo mv /etc/resolv.conf /etc/resolv.conf.backup

Now, open or create /etc/wsl.conf using a text editor like nano or vim:

sudo nano /etc/wsl.conf

Add the following lines to the file:

[network]
generateResolvConf = false

Save and exit the editor (Ctrl+X, Y, Enter for nano). This flag tells WSL2 to leave your /etc/resolv.conf untouched.

Step 3: Crafting Your Custom `resolv.conf`

With automatic generation disabled, you can now manually create a reliable /etc/resolv.conf. This is where you specify public, stable DNS servers that are known for their performance and reliability. Google's Public DNS and Cloudflare DNS are popular choices.

Open /etc/resolv.conf for editing (it might be empty or a new file):

sudo nano /etc/resolv.conf

Add your preferred DNS servers. For example, using Google's DNS:

nameserver 8.8.8.8
nameserver 8.8.4.4

Or using Cloudflare's DNS, which is often faster:

nameserver 1.1.1.1
nameserver 1.0.0.1

You can even combine them:

nameserver 1.1.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4

Adding multiple nameserver entries provides redundancy. If the first server is unresponsive, the system will try the next one. Save and exit the file.

Important Note: Ensure the file permissions are correct after creating/editing: sudo chmod 644 /etc/resolv.conf. This ensures only root can write to it, preventing unintended changes.

Step 4: Restarting WSL2

For the changes in /etc/wsl.conf to take effect, you must completely restart the WSL2 environment. Close all open WSL2 terminal windows and then open a Windows Command Prompt or PowerShell and run:

wsl --shutdown

This command terminates all running WSL2 distributions. Wait a few seconds, then reopen your WSL2 terminal. Your new /etc/resolv.conf should now be active, and your WSL2 DNS resolution issues should be resolved.

Beyond the Beaten Path: Advanced DNS Solutions

Sometimes, the journey requires venturing off the main trail. If customizing /etc/resolv.conf doesn't fully resolve your WSL2 connectivity problems, these advanced techniques might uncover the root cause.

Addressing VPN Interferences

VPNs are designed to reroute your network traffic and often come with their own DNS servers to prevent DNS leaks. This can clash with WSL2's attempt to use your host's (now VPN-controlled) DNS or your custom DNS. If you're using a VPN, try the following:

Resetting Windows Network Adapters

A corrupted or stuck network configuration on the Windows host can cascade into WSL2. Resetting the network stack can often clear up these transient issues.

Open a Windows Command Prompt or PowerShell as an administrator and run these commands:

ipconfig /flushdns
netsh winsock reset
netsh int ip reset

After running these, it's advisable to restart your entire Windows machine (not just WSL2) to ensure a clean network state. Then, restart your WSL2 instance.

Windows Firewall Considerations

While less common for standard DNS resolution (as most firewalls allow outbound DNS by default), a restrictive Windows Firewall rule could be blocking WSL2's requests. If you've manually configured firewall rules or are on a corporate network, ensure that outbound UDP traffic on port 53 is allowed for the WSL2 virtual network adapter.

You can check your network adapters for WSL2 by running ipconfig in Windows Command Prompt and looking for adapters named "vEthernet (WSL)".

Modifying the WSL2 `hosts` File

The /etc/hosts file in Linux allows you to manually map domain names to IP addresses. While not directly related to general DNS resolution, if you're experiencing issues resolving specific local network names or development domains, checking this file might be necessary.

sudo nano /etc/hosts

Ensure there are no erroneous or outdated entries that might be overriding legitimate DNS lookups for specific domains.

Reinstalling WSL2 (The Last Resort)

If all else fails, and you've exhausted every troubleshooting step, a complete reset of your WSL2 environment might be necessary. This is a drastic measure and should only be undertaken if you have backed up your data or can easily recreate your WSL2 setup.

For more detailed information on managing WSL2 distributions and backup strategies, you might find our guide on efficient WSL2 backup and restore particularly useful.

Verifying Your Position: Confirming DNS Resolution

Once you've applied a fix, the crucial next step is to verify that your WSL2 DNS issues are truly resolved. You wouldn't set sail without checking your compass, would you?

In your WSL2 terminal, use these commands to test DNS resolution:

1. Ping a public domain:

ping google.com

If successful, you'll see a series of replies with IP addresses and time statistics. If it fails, you'll likely see "Temporary failure in name resolution" or "Name or service not known."

2. Use `nslookup` (Name Server Lookup):

nslookup google.com

This command queries your configured DNS server directly. A successful result will show the DNS server that resolved the query and the IP addresses for the domain.

Server:		1.1.1.1
Address:	1.1.1.1#53

Non-authoritative answer:
Name:	google.com
Address: 142.250.190.46
Name:	google.com
Address: 2a00:1450:4001:820::200e

If nslookup is not installed, you can often install it with sudo apt update && sudo apt install dnsutils (for Debian/Ubuntu).

3. Use `dig` (Domain Information Groper):

dig google.com

dig provides more detailed information about DNS queries. Look for the ANSWER SECTION and verify that IP addresses are returned. Similar to nslookup, you might need to install dnsutils.

If all these tests show successful resolution, congratulations! You've successfully navigated the complexities of WSL2 DNS resolution and restored your internet access.

Avoiding Quicksand and Pitfalls: Best Practices for WSL2 DNS Stability

A seasoned traveler knows that foresight is as valuable as a good map. To minimize future encounters with WSL2 DNS issues, integrate these best practices into your workflow.

By adopting these practices, you're not just fixing problems; you're building resilience into your WSL2 environment, ensuring smooth sailing (or coding) ahead.

Key Takeaways

Frequently Asked Questions

Why does WSL2 DNS keep breaking?

WSL2 DNS frequently breaks because, by default, it relies on dynamically generated configurations inherited from your Windows host's network settings. Changes to your Windows network (e.g., connecting to a new Wi-Fi, enabling a VPN, or router reboots) can cause these inherited DNS settings to become stale or incorrect within your WSL2 instance, leading to name resolution failures. The automatic regeneration of /etc/resolv.conf overwrites any manual fixes, creating a persistent issue.

Can I use different DNS servers in WSL2 than in Windows?

Yes, you absolutely can. In fact, this is the recommended approach to achieving stable DNS resolution in WSL2. By setting generateResolvConf = false in /etc/wsl.conf and then manually adding specific nameserver entries (like Google's 8.8.8.8 and 8.8.4.4, or Cloudflare's 1.1.1.1 and 1.0.0.1) to your WSL2's /etc/resolv.conf, you ensure your Linux environment uses a fixed, reliable set of DNS servers independent of your Windows host's configuration.

What to do if `wsl --shutdown` doesn't fix it?

If wsl --shutdown doesn't resolve your DNS issues, it indicates a deeper problem beyond a simple network reset. First, ensure you've implemented the static DNS configuration steps (disabling generateResolvConf and manually setting nameserver entries). If the problem persists, investigate potential Windows-side issues such as firewall blocks, VPN interference, or corrupted Windows network adapters. Try running ipconfig /flushdns, netsh winsock reset, and netsh int ip reset from an administrative Windows Command Prompt, followed by a full Windows restart. As a last resort, consider exporting, unregistering, and re-importing your WSL2 distribution.

Is it safe to disable `generateResolvConf`?

Yes, it is generally safe and often recommended to disable generateResolvConf. This setting gives you manual control over your WSL2's DNS configuration, preventing it from being overwritten by dynamic changes on the Windows host. By setting your own reliable public DNS servers, you improve stability and predictability. The only potential downside is that if your chosen DNS servers become unavailable, you'd need to manually update /etc/resolv.conf again, but this is rare with major public DNS providers.

Navigating the occasional network hiccup in WSL2 is part of the modern developer's journey. With these strategies, you're well-equipped to face any challenge and ensure your development environment remains connected and productive. For a visual walkthrough and further insights into these fixes, be sure to watch the accompanying video guide on @explorenystream. Don't forget to like, share, and subscribe for more expert guides on technology and beyond!

Report Abuse

Contributors