WSL2: DNS Address in resolv.conf Not Updating on Network Change

Abstract: Resolve WSL2 DNS resolution failures after network changes by configuring static DNS in wsl.conf or restarting the service.

Created: 2026-08-12 by
The DNS address in /etc/resolv.conf within WSL2 is a dynamically generated file that mirrors the host Windows network settings. When you switch networks, this file does not automatically update because it is mounted as a read-only symlink to a temporary file managed by the Hyper-V virtual switch. To resolve this issue and ensure your Linux environment uses the correct DNS servers for the new network, you must either configure WSL2 to use a static DNS server or manually intervene with network adapter settings on the Windows host.

Understanding the Dynamic Nature of resolv.conf

In WSL2, the file /etc/resolv.conf is not a persistent configuration file like it is in traditional Linux distributions. Instead, it is a symbolic link pointing to a temporary file located at /run/wslg/resolv.conf or similar paths depending on the version. This temporary file is populated by the WSL daemon based on the DNS servers assigned to the Windows host's active network interface. When you connect to a new Wi-Fi network or switch from Ethernet to Wi-Fi, Windows updates its own DNS configuration. However, the WSL2 virtual machine does not receive an immediate notification to refresh its internal DNS cache or remount the resolv.conf file. Consequently, your Linux distribution continues to query the old DNS servers, leading to resolution failures or timeouts until the WSL instance is restarted or the underlying network state is forcibly refreshed. This behavior is by design to maintain network isolation and stability between the host and the guest OS.

Why Restarting WSL Helps

Restarting the WSL service forces the daemon to re-evaluate the host's network state. By killing all running instances and restarting the service, you trigger a fresh generation of the resolv.conf content. While effective, this approach disrupts any running processes in your Linux environment, making it unsuitable for production workflows or long-running services.

Configuring Static DNS via wsl.conf

A more robust solution is to override the dynamic DNS assignment by configuring a static DNS server in the WSL2 configuration file. This method ensures that regardless of the host network change, your Linux VM always uses a reliable DNS resolver, such as Google's public DNS or your corporate internal DNS. To implement this, create or edit the wsl.conf file in the root directory of your Linux distribution. You can do this by running the following command in your WSL terminal:
sudo nano /etc/wsl.conf
Add the following section to the file:
[network]
generateResolvConf = false
After saving the file, you must manually create a standard /etc/resolv.conf file. Since generateResolvConf is set to false, WSL will no longer manage this file. You can create it with your preferred DNS servers:
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'
Ensure the permissions are set correctly so that the file is readable:
sudo chmod 644 /etc/resolv.conf
Finally, restart WSL to apply the changes. Open PowerShell or Command Prompt on Windows and run:
wsl --shutdown
Then relaunch your Linux distribution. Your DNS queries will now bypass the dynamic host mapping and go directly to the specified servers. Note that if you need to change DNS servers later, you must edit /etc/resolv.conf directly again.

Managing Network Adapter Settings on Windows

If you prefer to keep the dynamic DNS behavior but want to force an update without restarting WSL, you can manipulate the Windows network adapter settings. The WSL2 virtual switch relies on the host's primary network interface. Sometimes, disabling and re-enabling the adapter triggers a refresh of the IP and DNS configurations that WSL detects. 1. Open the Network Connections panel in Windows (press Win + R, type ncpa.cpl, and hit Enter). 2. Identify the active network adapter (Wi-Fi or Ethernet). 3. Right-click the adapter and select Disable. 4. Wait approximately 10 seconds. 5. Right-click the adapter again and select Enable. This action forces Windows to renew its DHCP lease and update its DNS cache. In many cases, WSL2 will detect this change and update its internal DNS records upon the next network request. However, this method is not guaranteed to work in all scenarios, particularly if the WSL daemon has cached the previous state aggressively.

Advanced Troubleshooting with Custom DNS Routes

For users requiring complex network setups, such as those using VPNs or custom routing tables, managing DNS in WSL2 can become intricate. If you are using tools like Twingate or other enterprise VPN solutions, you may need to configure specific DNS routes to ensure connectivity. For detailed guidance on automating DNS configuration in these advanced scenarios, refer to our article on Automatically Configure DNS Server Routes for WSL2 Ubuntu on Windows with Twingate VPN. Additionally, if you are experiencing broader networking issues alongside DNS problems, such as mirrored network mode compatibility, it is worth reviewing how WSL2 handles network interfaces. See WSL2 and Mirrored Network Mode: A Compatibility Overview for Dev Projects for insights into network topology impacts.

Conclusion

The inability of /etc/resolv.conf to update automatically on network change is a known limitation of WSL2's architecture. The most reliable fix for developers is to disable automatic generation in wsl.conf and specify static DNS servers. This eliminates dependency on the host's transient network state and provides consistent name resolution across different environments.

Frequently Asked Questions

Can I make WSL2 automatically detect DNS changes without restarting?

No, WSL2 does not support live hot-reloading of /etc/resolv.conf when the host network changes. The file is regenerated only during the startup of the WSL service or when explicitly triggered by shutdown commands. You must restart WSL or use a static DNS configuration to avoid manual intervention.

Does setting generateResolvConf to false break internet access?

No, it does not break internet access as long as you provide valid DNS servers in /etc/resolv.conf. In fact, it often improves reliability because your Linux environment is no longer dependent on potentially misconfigured or slow host DNS servers. Ensure you use public resolvers like 8.8.8.8 or your local network's DNS gateway.

How do I check which DNS servers WSL2 is currently using?

You can view the current DNS configuration by opening your WSL terminal and running the command cat /etc/resolv.conf. This will display the nameserver entries currently active in your Linux distribution. If it shows dynamic entries, automatic generation is still enabled.

What happens to my existing processes if I use wsl --shutdown?

Running wsl --shutdown terminates all running Linux processes and closes all connected terminals. Any unsaved work in background services or long-running scripts will be lost. Always save your work and stop critical services before shutting down the WSL instance to prevent data loss.

Is this issue specific to Windows 11?

No, this behavior exists in both Windows 10 and Windows 11 WSL2 implementations. It is inherent to how the Hyper-V virtual switch manages network interfaces and DNS forwarding. The troubleshooting steps provided are applicable to all versions of WSL2 supported on Windows 10 and 11.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More