WSL2: DNS Address Resolution in Windows 11 Not Updating Network Change
If you're using WSL2 on Windows 11 and have encountered the problem where the DNS address in the resolv.conf file doesn't update when you change networks, you're not alone. This article will cover the key concepts related to this issue and provide a detailed explanation of the problem and potential solutions.
Understanding WSL2 and DNS Resolution
WSL2 (Windows Subsystem for Linux version 2) is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. It uses virtualization technology to create a lightweight virtual machine that runs a Linux kernel, allowing you to run Linux applications alongside Windows applications.
When you're using WSL2, the DNS resolution process is handled by the Windows DNS client. The resolv.conf file in the WSL2 environment is a symlink to the /mnt/wsl/dns/
The Problem: DNS Address Not Updating in resolv.conf
If you've encountered the problem where the DNS address in the resolv.conf file doesn't update when you change networks, it's likely because the Windows DNS client isn't updating the DNS address properly. This can cause issues when trying to resolve domain names from within the WSL2 environment.
Potential Solutions
There are a few potential solutions to this problem:
- Restart the WSL2 service: You can try restarting the WSL2 service to see if that resolves the issue. To do this, open an elevated PowerShell prompt and run the following command:
Restart-Service LxssManager- Restart the Windows DNS client: You can also try restarting the Windows DNS client to see if that resolves the issue. To do this, open an elevated PowerShell prompt and run the following command:
Restart-Service dnscache- Manually update the resolv.conf file: If the above solutions don't work, you can try manually updating the resolv.conf file. To do this, open the resolv.conf file in a text editor and update the DNS address to match the new network. For example:
nameserver 8.8.8.8- Use a third-party DNS resolver: If none of the above solutions work, you can try using a third-party DNS resolver, such as Google DNS or Cloudflare DNS. To do this, open the network settings in Windows and update the DNS server to the IP address of the third-party DNS resolver. For example:
8.8.8.8In this article, we covered the issue of the DNS address not updating in the resolv.conf file when changing networks in WSL2 on Windows 11. We provided a detailed explanation of the problem and potential solutions, including restarting the WSL2 service and Windows DNS client, manually updating the resolv.conf file, and using a third-party DNS resolver.
References
- Microsoft Docs: WSL 2 FAQ
- GitHub: WSL 2 DNS resolution not working after switching networks #4152
- Super User: WSL2 DNS not working after switching networks