Java and /etc/resolv.conf DNS server failover

domain-name-systemjava

Executive Summary

  • Does Java query the next resolv.conf name server entry if the first one fails or times out?
  • What is the default timeout at which Java will consider a resolver "down"?

Details

In /etc/resolv.conf, in most sites, there are multiple DNS servers configured for use by the system. Can anyone clarify what happens, with Java, if the first DNS server in the list fails? For example, imagine the following resolv.conf:

nameserver 8.8.8.8
nameserver 4.4.4.4

If 8.8.8.8 becomes unreachable then will Java try 4.4.4.4? In our experience it does not – we saw many threads waiting to resolve DNS names even though the backup DNS servers were reachable.

Best Answer

On Linux java will delegate hostname resolution to the underlying C system library which does the actual resolving.

The name servers will be queried in the order listed as specified in /etc/resolv.conf after the other sources of information specified in /etc/nsswitch.conf have been queried (think /etc/hosts but possibly NIS or LDAP).

You can specify a timeout value in /etc/resolv.conf , according to the man page the default is 5 seconds.

If your first server gives a valid error code I.e. servfail the second name server will not be queried