|
| 1 | +# Windows 10 DNS Priority |
| 2 | + |
| 3 | +The way DNS priority works |
| 4 | +[changed in Windows 10](https://web.archive.org/web/20190106092511/https://blogs.technet.microsoft.com/networking/2015/08/14/adjusting-the-network-protocol-bindings-in-windows-10/) |
| 5 | +to use interface metric instead of binding order. However, it isn't entirely clear from the docs precisely how this |
| 6 | +priority works under certain scenarios, so I have done some experiments: |
| 7 | + |
| 8 | +## Testing Interface Metrics |
| 9 | + |
| 10 | +Ethernet 1 (index 9), DNS server: 10.1.1.254 \ |
| 11 | +Ethernet 2 (index 24), DNS server: 10.2.2.254 |
| 12 | + |
| 13 | +```powershell |
| 14 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -InterfaceMetric 50 |
| 15 | +Set-NetIPInterface -InterfaceAlias "Ethernet 2" -InterfaceMetric 100 |
| 16 | +``` |
| 17 | + |
| 18 | +Ethernet 1 wins: |
| 19 | + |
| 20 | +```powershell |
| 21 | +nslookup google.com |
| 22 | +Address: 10.1.1.254 |
| 23 | +``` |
| 24 | + |
| 25 | +Let's flip the metrics: |
| 26 | + |
| 27 | +```powershell |
| 28 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -InterfaceMetric 100 |
| 29 | +Set-NetIPInterface -InterfaceAlias "Ethernet 2" -InterfaceMetric 50 |
| 30 | +``` |
| 31 | + |
| 32 | +Now Ethernet 2 wins, this is expected: |
| 33 | + |
| 34 | +```powershell |
| 35 | +nslookup google.com |
| 36 | +Address: 10.2.2.254 |
| 37 | +``` |
| 38 | + |
| 39 | +## Does Route Priority Matter? |
| 40 | + |
| 41 | +Ethernet 1 (index 9), DNS server: 10.1.1.254 \ |
| 42 | +Ethernet 2 (index 24), DNS server: 10.2.2.254 |
| 43 | + |
| 44 | +```powershell |
| 45 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -InterfaceMetric 50 |
| 46 | +Set-NetIPInterface -InterfaceAlias "Ethernet 2" -InterfaceMetric 100 |
| 47 | +Set-NetRoute -DestinationPrefix 0.0.0.0/0 -InterfaceAlias "Ethernet 1" -RouteMetric 256 |
| 48 | +Set-NetRoute -DestinationPrefix 0.0.0.0/0 -InterfaceAlias "Ethernet 2" -RouteMetric 256 |
| 49 | +``` |
| 50 | + |
| 51 | +Initially Ethernet 1 wins for DNS: |
| 52 | + |
| 53 | +```powershell |
| 54 | +nslookup google.com |
| 55 | +Address: 10.1.1.254 |
| 56 | +``` |
| 57 | + |
| 58 | +And also routing (because 256 + 50 is less than 256 + 100): |
| 59 | + |
| 60 | +```powershell |
| 61 | +Find-NetRoute -RemoteIPAddress "8.8.8.8" | Select-Object InterfaceAlias |
| 62 | +Ethernet 1 |
| 63 | +``` |
| 64 | + |
| 65 | +But what if we change the route priority: |
| 66 | + |
| 67 | +```powershell |
| 68 | +Set-NetRoute -DestinationPrefix 0.0.0.0/0 -InterfaceAlias "Ethernet 1" -RouteMetric 9999 |
| 69 | +Set-NetRoute -DestinationPrefix 0.0.0.0/0 -InterfaceAlias "Ethernet 2" -RouteMetric 5 |
| 70 | +``` |
| 71 | + |
| 72 | +Such that Ethernet 2 is the best route (5 + 100 is less than 9999 + 50) |
| 73 | + |
| 74 | +```powershell |
| 75 | +Find-NetRoute -RemoteIPAddress "8.8.8.8" | Select-Object InterfaceAlias |
| 76 | +Ethernet 1 |
| 77 | +``` |
| 78 | + |
| 79 | +The best DNS server is still on Ethernet 1: |
| 80 | + |
| 81 | +```powershell |
| 82 | +nslookup google.com |
| 83 | +Address: 10.1.1.254 |
| 84 | +``` |
| 85 | + |
| 86 | +So it would appear the route metrics are irrelevant. |
| 87 | + |
| 88 | +## How are IPv4 vs IPv6 interface metrics treated |
| 89 | + |
| 90 | +Note: Neither Ethernet adapters have an IPv6 address/route or DNS server. |
| 91 | + |
| 92 | +Initially |
| 93 | + |
| 94 | +```powershell |
| 95 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -AddressFamily IPv4 -InterfaceMetric 50 |
| 96 | +Set-NetIPInterface -InterfaceAlias "Ethernet 2" -AddressFamily IPv4 -InterfaceMetric 100 |
| 97 | +
|
| 98 | +# Ethernet 2 has the best metric of any interface: |
| 99 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -AddressFamily IPv6 -InterfaceMetric 50 |
| 100 | +Set-NetIPInterface -InterfaceAlias "Ethernet 2" -AddressFamily IPv6 -InterfaceMetric 25 |
| 101 | +``` |
| 102 | + |
| 103 | +Ethernet 2 now has the highest priority DNS: |
| 104 | + |
| 105 | +```powershell |
| 106 | +nslookup google.com |
| 107 | +Address: 10.2.2.254 |
| 108 | +``` |
| 109 | + |
| 110 | +## DNS servers on the same interface |
| 111 | + |
| 112 | +In this scenario only one Ethernet adapter is enabled: |
| 113 | + |
| 114 | +IPv4 DNS server: 10.1.1.254 \ |
| 115 | +IPv6 DNS server: ::1 |
| 116 | + |
| 117 | +```powershell |
| 118 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -InterfaceMetric 50 |
| 119 | +``` |
| 120 | + |
| 121 | +When both IPv4 and IPv6 metrics are equal the IPv6 DNS server is used first: |
| 122 | + |
| 123 | +```powershell |
| 124 | +nslookup google.com |
| 125 | +Address: ::1 |
| 126 | +``` |
| 127 | + |
| 128 | +What about if the IPv4 metric is lower: |
| 129 | + |
| 130 | +```powershell |
| 131 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -AddressFamily IPv4 -InterfaceMetric 50 |
| 132 | +Set-NetIPInterface -InterfaceAlias "Ethernet 1" -AddressFamily IPv6 -InterfaceMetric 100 |
| 133 | +``` |
| 134 | + |
| 135 | +The IPv6 DNS server is still chosen first: |
| 136 | + |
| 137 | +```powershell |
| 138 | +nslookup google.com |
| 139 | +Address: ::1 |
| 140 | +``` |
0 commit comments