The curious case of DNS and wi-fi routerΒΆ
Like any one with an internet connection, I have a wi-fi router at home. And if you have seen my older posts you would know that I use a DNS based ad blocker that I run on my home network. The ad blocker runs on a raspberry pi and I use its IP as the DNS server/cache in my router. I wanted to run a DNS performance test and I used the script dnsperf to do that. It basically runs a DNS query on the list of provided name servers and measures the time taken. Below are the result when running the test with my router(with IP :192.168.1.1) as the DHCP and pi(host name: pi) as the DNS server.
$ ./dnstest.sh
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 Average
192.168.1.1 634 ms 602 ms 110 ms 173 ms 67 ms 165 ms 25 ms 1000 ms 352 ms 1000 ms 412.80
pi 54 ms 11 ms 28 ms 12 ms 140 ms 15 ms 2 ms 144 ms 43 ms 26 ms 47.50
cloudflare 194 ms 2 ms 14 ms 25 ms 3 ms 3 ms 4 ms 106 ms 3 ms 19 ms 37.30
level3 187 ms 130 ms 135 ms 315 ms 296 ms 147 ms 152 ms 142 ms 232 ms 151 ms 188.70
google 1000 ms 1000 ms 1000 ms 1000 ms 45 ms 16 ms 15 ms 105 ms 21 ms 39 ms 424.10
quad9 1000 ms 52 ms 60 ms 120 ms 200 ms 127 ms 412 ms 145 ms 101 ms 56 ms 227.30
freenom 135 ms 245 ms 147 ms 125 ms 594 ms 130 ms 128 ms 132 ms 243 ms 234 ms 211.30
opendns 121 ms 141 ms 20 ms 100 ms 46 ms 48 ms 18 ms 74 ms 22 ms 18 ms 60.80
norton 1000 ms 366 ms 37 ms 37 ms 37 ms 38 ms 46 ms 38 ms 38 ms 323 ms 196.00
cleanbrowsing 1000 ms 1000 ms 305 ms 167 ms 148 ms 634 ms 296 ms 604 ms 563 ms 543 ms 526.00
yandex 1000 ms 174 ms 347 ms 297 ms 206 ms 175 ms 508 ms 297 ms 163 ms 328 ms 349.50
adguard 1000 ms 336 ms 287 ms 233 ms 274 ms 438 ms 257 ms 226 ms 258 ms 249 ms 355.80
neustar 1000 ms 1000 ms 1000 ms 1000 ms 1000 ms 1000 ms 43 ms 105 ms 97 ms 96 ms 634.10
comodo 249 ms 253 ms 379 ms 296 ms 295 ms 378 ms 281 ms 232 ms 260 ms 278 ms 290.10
As you can see it takes an average of 47ms when querying the name server directly. But as my router is the one acting as a DHCP server, the clients see the router to be the nameserver/DNS. Thus the queries in my home network first come to the router and then the router sends them to the DNS server. This adds an aditional hop for the DNS queries from the clients and was taking around 400ms for the query resolution. I use a Netgear router and I did go through the documentation to see if this behaviour can be changed in the router. But I could not find anything on this. AdGuard home - the service I use for ad blocking also has a built in DHCP feature. I disabled the DHCP feature in the router and enabled the one on my Pi. The result are intersting.
$ ./dnstest.sh
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 Average
192.168.1.1 14 ms 382 ms 12 ms 16 ms 33 ms 148 ms 10 ms 118 ms 4 ms 35 ms 77.20
router 3 ms 3 ms 3 ms 5 ms 4 ms 3 ms 3 ms 3 ms 3 ms 3 ms 3.30
pi 2 ms 2 ms 2 ms 3 ms 2 ms 2 ms 2 ms 2 ms 2 ms 2 ms 2.10
cloudflare 2 ms 2 ms 3 ms 2 ms 3 ms 2 ms 2 ms 3 ms 2 ms 2 ms 2.30
level3 143 ms 130 ms 137 ms 136 ms 138 ms 133 ms 132 ms 130 ms 135 ms 130 ms 134.40
google 15 ms 15 ms 39 ms 37 ms 42 ms 15 ms 15 ms 95 ms 15 ms 15 ms 30.30
quad9 47 ms 49 ms 49 ms 52 ms 50 ms 254 ms 58 ms 48 ms 47 ms 54 ms 70.80
freenom 132 ms 125 ms 125 ms 128 ms 126 ms 125 ms 138 ms 131 ms 125 ms 133 ms 128.80
opendns 92 ms 16 ms 78 ms 16 ms 17 ms 16 ms 17 ms 77 ms 73 ms 20 ms 42.20
norton 37 ms 37 ms 114 ms 38 ms 81 ms 37 ms 38 ms 108 ms 38 ms 153 ms 68.10
cleanbrowsing 198 ms 151 ms 150 ms 150 ms 143 ms 143 ms 152 ms 143 ms 144 ms 146 ms 152.00
yandex 159 ms 156 ms 160 ms 161 ms 158 ms 161 ms 161 ms 164 ms 160 ms 288 ms 172.80
adguard 291 ms 293 ms 300 ms 296 ms 297 ms 296 ms 296 ms 296 ms 298 ms 297 ms 296.00
neustar 39 ms 36 ms 39 ms 39 ms 61 ms 36 ms 38 ms 39 ms 38 ms 250 ms 61.50
comodo 277 ms 295 ms 235 ms 256 ms 226 ms 264 ms 297 ms 296 ms 296 ms 296 ms 273.80
The DNS query time came down to 2ms. And even the router started to respond very fast in 77ms compared to 412ms from the previous test. Now I do not have a direct way to measure if the load of maintaining the route table and the additional task of redirecting the DNS queries to the DNS server are affecting the performance. The router does not provide any means to measure the load. With this change, the router is only doing the job of providing the internet access to the home network and nothing else. DNS and DHCP are being managed by the Pi and I am happy with the performance.