7

How many nameserver entries can I give in /etc/resolv.conf? I have given our ISP's 2 nameserver entries as first and second. But since they have issues sometimes, I would like to add Google public nameserver enry. Does a 3rd & 4th entry make any difference?

This is the resolv.conf on our proxy(squid) server. I understand that Squid uses /etc/resolv.conf for name resolution.

Slipeer
  • 3,295
  • 2
  • 21
  • 33
nitins
  • 2,579
  • 15
  • 44
  • 68

3 Answers3

12

Actually, you're only allowed three server entries in /etc/resolv.conf.

See: http://linux.die.net/man/5/resolv.conf

Slipeer
  • 3,295
  • 2
  • 21
  • 33
b2c3
  • 136
  • 2
1

My original solution to overcome the 3 nameserver limit on dual-stack systems was to install dnsmasq, however the work-around increases installation and maintenance costs far too much (I operate many lxc containers), so I needed a simpler solution, which thankfully exists.

I discovered that you can use systemd-resolved which overcomes the 3 nameserver limit. Most modern distros have it all set up by default and ready to go. There's a file /etc/systemd/resolved.conf where you specify nameserver ip's. Edit the conf file and add in your nameservers, then run systemctl restart systemd-resolved. Done!

I noticed someone commented that MAXNS in resolv.h is not there anymore. The source version that I looked at on github also did not have MAXNS, however I remember encountering the 3 nameserver limit not very long ago so it appears to still apply.

Edit: The default /etc/systemd/resolved.conf has commented out entries suggesting that more than 3 DNS servers can be specified, however when looking at /run/systemd/resolve/resolv.conf, I see this comment

"Too many DNS servers configured, the following entries may be ignored."

Followed by the list of additional dns ip's after the first 3.

So it seems we're still stuck with only 3 DNS servers which is rather difficult to understand why. If there's a valid reason for the limit, then at the very least the limit should be spelled out in the default resolv.conf files,and the suggested DNS entries in the file should not go beyond 3, the final case is the resolver should error out when restarted when the DNS entries are invalid.

0

You can effectively have as many namservers as you want. Just remember that resolution will fail on the first before going to the second, and so on. It will be some time before name resolution attempts make it to the third and fourth nameservers.

Edit: As explained in the comments on this answer, I was wrong. You're limited to three nameservers by default, and this appears to be a compilation-time option (so not easy to change during runtime).

Jeff McJunkin
  • 1,372
  • 1
  • 8
  • 16