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.

3 Answers 3

12

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

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

2
  • 4
    so what if I enter more?
    – phil294
    Jul 7, 2016 at 21:38
  • 2
    The man page for resolv.conf points to constant MAXNS in /usr/include/resolv.h. In RedHat 8 the resolv.h file has no such constant. Anyone have a source for more current information? Aug 17, 2022 at 15:52
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).

4
  • 7
    It's set by MAXNS in resolv.conf, which is normally 3.
    – Sirex
    Dec 24, 2010 at 9:14
  • 2
    MAXNS is in resolv.h, a file used when software is built, not in resolv.conf. It's not something you can change on the fly.
    – Dan Pritts
    Mar 15, 2019 at 16:15
  • I stand corrected. My bad! Mar 29, 2019 at 23:08
  • 1
    Here it is 2022, twelve years later. I searched resolv.h on a RedHat 8 system (not exactly bleeding edge) and do not see MAXNS. Is this hardwired limit still in effect? Aug 17, 2022 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .