What algorithm does Windows use to decide which DNS Server it will query in order to resolve names?
Let's say I have several interfaces, all active, some with no dns server specified, some told to determine it automatically, and some with it specified manually (in interface ipv4 AND interface ipv6).
I'm asking for an answer to this general question hoping that I know how to solve a more specific problem in Windows Vista - I have two interfaces, one a lower metric and a DNS server specified manually. nslookup uses THIS DNS server and resolves the names correctly. However, all other applications fail to resolve the name unless I manually specify a DNS server for the other interface, which the applications then use. nslookup also uses the DNS server specified for this other interface once it is specified.
Thanks
If I'm not mistaken, it's determined by the NIC binding order in the Advanced Settings in the network connections folder. You can verify it by changing the binding order of the various NIC's and running nslookup as a test.
To expand on my answer, citing the article that Evan linked, here is an excerpt from said article:
The preferred adapter in step 1 being the adapter that's listed first in the binding order.
In Windows 10 you must update the metric of each interface in the order you want.
References:
I used 10 for my LAN, 20 for WLAN, and 100 for VPN Interfaces (I prefer local DNS at work, this may be reverse for others). Remember lower metric = higher priority.
See this article in Microsoft Support for An explanation of the Automatic Metric feature for IPv4 routes.
I suspect this works because part of the route selection is to then set the source IP of the interface with the highest metric priority (lowest number) as you are not using the same IP address for all connections, whereas a dual-homed BGP connection would use the same source IP, but select different next-hop gateways pending destination IP.
For Server, install the DNS service and do something purposeful/intelligent, I do not agree with doing this on Server OS.
To specifically answer the question, Windows uses the first DNS records associated with the highest ranking network interface (an
InterfaceMetric
with a lower value has higher rank). Examples below show how to obtain and change that interface ranking value. When there are no manual DNS servers configured on an interface, Windows relies on DNS servers provided by any DHCP server associated with a network interface.A common scenario where this issue pops up is when you have one or more VPNs that provide a DNS server for resources defined for that virtual network.
However, the public DNS server assigned by a WiFi router is taking precedent and either claiming that hosts don't exist or are responding with the unexpected IP address.
To resolve this, we need to explicitly dictate which network interface should take precedence by specifying its associated "metric". (Currently, this metric appears to only be settable via PowerShell ... see below)
Change Metric of Network Interface (e.g., the VPN)
First, list local interfaces and their metrics
Then, set metric of network interface
(NOTE: Make sure you do this from an administrative PowerShell console)
Testing Effect of Interface Metric
In this example, before changing the metric value, pinging a local resource that also has a publicly-defined IP returns its public IP (instead of the internal IP returned by my VPN's DNS server).
Example When Bad! :(
Example When Good! :)
After changing the metric on the network interface, I now see the expected internal IP address that is returned from the DNS server associated with my VPN:
This page describes the algorithm used by Windows to perform DNS queries. It's not in depth enough to give you all the answers you're looking for, but some time w/ a sniffer and this article ought to be all you need to determine what's happening in your specific situation.
I had exactly the same problem. I've spent a day trying to figure it out.
If you have several network cards and if you specify a DNS server in each of them do you know what DNS server will be used?
Well, you can check it with:
So you see the server that your PC actually uses.
The question is: how does windows choose which DNS server to use and how can we change it.
We especially need it when we use VPN clients.
The answer from qwerty2010 is right and correct. But you can use it ONLY when you have a NIC in control panel - network and sharing center - change adapter settings - list of nics
Only if you see the nic that is reponsible for your VPN client you can use the graphical way.
So you go Network and sharing centre -> Change adapter settings -> Advanced -> Advanced settings -> and you move UP the nic with DNS you'd like to USE.
However if for instance you use Shrew vpn client - you will not have any nics.
What do you do? You open registry.
And you look in subfolders 0000, 0001 etc the folder with
Then you copy to the clipboard
Now you go
and you open
key = Bind
. You'll see the list like thisAll you have to do is put to the top
That's all. There is no need to reboot.
Now your windows will use DNS specified in shrew vpn nic when you use vpn connection.
On Windows 10 and 11, DNS priority is determined by interface metric, this is documented here - the DNS servers on the interface with the lowest metric value will be used first.
It is important to note that an interface actually has two interface metric values, one for IPv4 and one for IPv6.
You can configure these either via:
Or via Powershell:
For the purposes of DNS the lowest of the two values is considered, in other words the list of interfaces is sorted by the min(Ipv4Metric, Ipv6Metric).
Each interface (e.g. Ethernet or WiFi) then has a list of DNS servers, but within that list IPv6 servers come first.
Here is an example scenario:
Windows first finds the best interface - Ethernet 2 since it has the lowest metric, and will therefore use DNS server
10.2.2.2
The next best interface is Ethernet 1, Windows will attempt
2001:db8::1
since IPv6 DNS servers are used first. And then finally10.1.1.1
Note: See my experiments that prove this
As this might help you or others, you can disable the windows round-robin usage of the listed dns to make the dns usage more predictable. Try setting the
RoundRobin=0
in theHKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\DNS\Parameters
(reference) to disable the dns round-robing.There is also a "timeout" for rotating the servers, you can also try to setting it to zero:
It doesn't decide randomly. You're connected to a router which gets it IP from a company which has DNS servers. They get your request unless you alter the IP manually to another DNS, for instance: OpenDns. Or perhaps you decide on having your own DNS servers. That works too. Just enter the IP adresses in the network center and all should be well. And yes, you'll have to set those manually.
You can also adjust a file in
C:\Windows\System32
called "hosts" with no extension. It allows you to have URL-requests redirected instead of being sent to the standard DNS. To a local server(which must be running and listening to port 80)