How To Fix WSL2 DNS Not Working

Windows Subsystem for Linux (WSL2) is a powerful tool for developers that combines the best of Windows and Linux environments.

However, it’s not uncommon for users to encounter DNS issues, which can be frustrating and impact productivity.

In this article, we provide a comprehensive guide to troubleshooting and resolving WSL2 DNS not working issues.

Why Is WSL2 DNS Not Working?

  1. Service Interruptions: Temporary interruptions in WSL2 or networking services can cause DNS-related problems.
  2. Network Configuration Issues: Incorrect settings or misconfigurations in the network stack can lead to DNS resolution problems.
  3. Outdated Software: Running outdated versions of WSL2 or Windows can cause compatibility issues, including DNS problems.
  4. Firewall or Security Software: Overly restrictive firewall settings or security software configurations can block DNS traffic.
WSL DNS Not Working

How To Fix WSL2 DNS Not Working?

WSL DNS error

1. Restart WSL2 And Networking Services

The first step in resolving DNS issues is to restart WSL2 and related networking services. This can clear temporary problems and restore functionality. Follow these steps:

  1. Close all WSL2 instances by running wsl.exe --shutdown in a Command Prompt or PowerShell window.
  2. Restart the “Windows Subsystem for Linux” service by executing net stop LxssManager followed by net start LxssManager.
  3. Reopen WSL2 and test the DNS functionality.

2. Check Network Configuration

Misconfigurations in network settings can cause DNS problems. Verify your network settings by following these steps:

  1. Open a WSL terminal and run cat /etc/resolv.conf to check the DNS configuration.
  2. If the nameserver address is incorrect or missing, add the correct DNS server address using the echo "nameserver <DNS_ADDRESS>" | sudo tee -a /etc/resolv.conf command.
  3. Test the DNS functionality again.

3. Update WSL2 And Windows

Outdated software can lead to compatibility issues, including DNS problems. Ensure both WSL and Windows are up-to-date:

  1. Update WSL by running sudo apt update && sudo apt upgrade in your Linux distribution.
  2. Update Windows by going to Settings > Update & Security > Windows Update, and click “Check for updates.”

4. Manual DNS Configuration

Manually configuring the DNS settings in WSL2 can resolve some issues. To do this, follow these steps:

  • Open a WSL terminal and run sudo nano /etc/wsl.conf
  • Add the following lines to the wsl.conf file:
[network]
generateResolvConf = false
  • Save and exit the editor by pressing Ctrl + X, then Y, and finally Enter.
  • Restart WSL by running wsl.exe --shutdown in a Command Prompt or PowerShell window.
  • Reopen WSL and create a new resolv.conf file by running sudo nano /etc/resolv.conf.
  • Add the desired nameserver(s) to the file, using the format:
nameserver <DNS_ADDRESS>
  • Save and exit the editor by pressing Ctrl + X, then Y, and finally Enter.
  • Test the DNS functionality again.

5. Firewall And Security Software Settings

Overly restrictive firewall settings or security software configurations can block DNS traffic. Check your firewall and security software settings to ensure they are not interfering with WSL’s DNS functionality:

  1. Open your firewall or security software settings.
  2. Add exceptions for WSL and related processes, such as wsl.exe and LxssManager.
  3. Ensure that DNS traffic is allowed through the firewall.
  4. Test the DNS functionality in WSL2 again.

6. Reset Network Settings In Windows

If the issue persists after trying the above solutions, you can reset the network settings in Windows to their default values:

  1. Open the Settings app by pressing Win + I.
  2. Navigate to Network & Internet > Status.
  3. Scroll down and click on “Network reset.”
  4. Click the “Reset now” button and confirm the action by clicking “Yes.”
  5. Restart your computer for the changes to take effect.

Please note that this will reset all network-related settings, including Wi-Fi and Ethernet configurations, so you may need to reconfigure your network connections after this step.

By following these comprehensive troubleshooting steps, you can effectively diagnose and resolve most WSL2 DNS issues, ensuring smooth operation and minimal downtime.