Dns lookup in Linux

Dns lookup in Linux provided by a set of functions in glibc. Nameservers must be defined in /etc/resolv.conf file as below:

nameserver 1.1.1.1
nameserver 2.2.2.2
nameserver 3.3.3.3

All of the getaddrinfo family of functions follows the process of:

  1. Send dns query to first nameserver
  2. If there is no answer in 5 seconds, send same query to second nameserver
  3. If there is no answer again in 3 seconds, send same query to third nameserver
  4. If still no answer received in 6 seconds, repeat the process from step 1

If you provide a not working nameserver ip in resolv.conf file in the first lines, all of the functions which depends on name resolution in any time will be slow down as described above.

Also note that, only first 3 nameserver line valid for glibc. If you provide more than 3 nameserver in resolv.conf, they just ignored by glibc.