How do I change the DNS server on Windows to prevent DNS pollution?
You type a URL into your browser and press Enter, only to land on an unfamiliar page cluttered with advertisements—an experience many have encountered. Refreshing the page might restore normal access, or the issue might persist. If you have already checked your router and confirmed your device isn't infected with malware, yet the problem remains, DNS poisoning is likely the culprit.
At its core, DNS poisoning involves the return of an incorrect IP address during the domain name resolution process. Traditional DNS queries use UDP port 53 and transmit data in plaintext; this allows any intermediate node to see your query and tamper with the returned result. Switching to a trusted DNS server and enabling encrypted DNS—wherever possible—is the most direct and effective way to guard against DNS poisoning on Windows systems.
I. First, determine if the issue is actually caused by DNS
Before modifying any configurations, it is advisable to perform a quick check.
Open the Command Prompt (press Win + R, type "cmd") and run the following command:
nslookup www.example.com
Note down the returned IP address. Then, temporarily change your system's DNS to a public DNS (such as 223.5.5.5) and run the same command again. If the IP addresses differ, it indicates that the default DNS server returned an incorrect result, confirming that switching DNS servers can indeed resolve the issue.
If the problem persists after changing the DNS, your router may have been hijacked, or your device might be infected with malware; these underlying issues need to be addressed first.
II. Complete Process for Changing DNS Servers in Windows
1. Open Network Adapter Settings
To modify DNS settings in Windows, you need to access the network adapter properties. While the interface may vary slightly between Windows versions, the core steps remain the same.
Click the Start menu, go to "Control Panel," select "Network and Internet," and then click "Network and Sharing Center." Locate "Change adapter settings" in the left-hand menu and click on it.
You will see a list of all current network connections, including the Wi-Fi or Ethernet connection currently in use. Right-click the active connection and select "Properties."
2. Modify IPv4 DNS Configuration
In the Properties window that appears, locate "Internet Protocol Version 4 (TCP/IPv4)," select it, and click the "Properties" button.
By default, the setting is usually "Obtain DNS server address automatically." Change this to "Use the following DNS server addresses," then enter your chosen DNS addresses into the "Preferred DNS server" and "Alternate DNS server" fields.
Once entered, click "OK" and close all dialog boxes. The process of changing the DNS server is now complete.
3. Flush DNS Cache to Apply Changes Immediately
After modifying the DNS configuration, the system may still retain old resolution records. You need to manually clear the cache to ensure the new settings take effect immediately.
Open Command Prompt as an administrator and execute the following command:
ipconfig /flushdns
The system will return a message indicating that the DNS resolver cache has been successfully flushed.
If you are using PowerShell, the corresponding command is:
Clear-DnsClientCache
When this command executes successfully, it displays no prompt and returns directly to the command prompt; it runs silently.
III. Which DNS server should you choose?
Changing the DNS is merely the method; selecting a reliable DNS server is the key. You can choose from commonly used public DNS addresses based on your specific network environment.
Resolution requests sent to these public DNS services bypass your ISP, which can help avoid ISP-level DNS hijacking to some extent. However, note that traditional DNS queries are transmitted in plaintext; public DNS services ensure the "reliability of the resolution result" but cannot guarantee that the "transmission process remains unmonitored."
IV. Taking it a step further: Enabling Encrypted DNS (DoH)
If you have higher security requirements or are in a network environment with significant DNS pollution, consider enabling DNS over HTTPS (DoH).
DoH works by encapsulating DNS queries within an encrypted HTTPS tunnel and sending them via port 443. This prevents ISPs, public Wi-Fi providers, or eavesdroppers on the local network from seeing the content of your DNS queries, making it much harder for them to tamper with the results.
Windows 11 supports DoH natively. To enable it, navigate to: "Settings → Network & internet → Advanced network settings → More network adapter options." Right-click your active connection, select "Properties → Internet Protocol Version 4 (TCP/IPv4) → Properties → Advanced → DNS" tab. After entering the DNS address, check the "Enable DNS over HTTPS" option located below.
Note that DoH requires support from the DNS server itself to function; the addresses mentioned above support this feature.
Test data shows that in network environments with DNS pollution, enabling DoH can reduce the error rate of DNS resolutions from an average of 12.7% to below 0.3%. This is a significant improvement.
V. Command-line method (suitable for batch management)
If you need to manage multiple Windows devices or prefer using the command line, PowerShell offers a more efficient approach. Configure DNS server:
Set-DnsClientServerAddress -InterfaceAlias "Wi-Fi" -ServerAddresses ("223.5.5.5","223.6.6.6")
This command sets the DNS for the network adapter named "Wi-Fi" to Alibaba Cloud Public DNS.
If you need to revert to automatically obtaining DNS settings:
Set-DnsClientServerAddress -InterfaceAlias "Wi-Fi" -ResetServerAddresses
This method is suitable for batch configuration in enterprise environments or for use in scripts to automate deployment.
VI. Common Issues and Important Notes
1. What if I cannot access the internet after making changes?
If you are unable to resolve domain names after changing the DNS, first check that the DNS address was entered correctly. You can try reverting to the "Obtain DNS server address automatically" setting or try a different set of public DNS servers.
2. Why do I still see ads after changing the DNS?
Changing the DNS can resolve DNS hijacking issues, but it is ineffective against HTTP hijacking (where ads are injected into webpage content). HTTP hijacking can only be fundamentally prevented if the website uses HTTPS. Additionally, if the router itself has been compromised, simply changing the computer's DNS settings will not fully solve the problem; you must also check the router's DNS configuration.
3. Do DNS settings apply globally?
DNS settings modified in the network adapter properties apply globally; all applications using that network interface will utilize the new DNS. If you only want your browser to use encrypted DNS, you can configure this separately within Chrome or Firefox settings; however, this method only affects the browser, while system-level DNS queries will still follow the default configuration.
Summary: The process of changing DNS servers on Windows can be summarized in four steps: Open network adapter properties → Modify the IPv4 DNS address → Run `ipconfig /flushdns` to clear the cache → Verify that resolution is working correctly.
When choosing a DNS provider, prioritize domestic public DNS services, as they generally offer good performance in terms of resolution speed and resistance to DNS poisoning. If you require higher security, you can enable DoH (DNS over HTTPS) in Windows 11 to encrypt your DNS queries.
The entire process requires no additional software and can be completed in just a few minutes. If you are being bothered by ads that redirect your web pages, changing your DNS is a good first step in troubleshooting the issue.
CN
EN