0

I am managing a particular host machine, and I would like to locally add a new name server for it to query (i.e. not changing its name server settings via the dhcp server). It seems that there are multiple ways to add a new name server.

  • Adding a 'nameserver ' directive directly to the resolv.conf file
  • Adding a 'DNS{1,2}=address' directive to a ifcfg-ethX file
  • Adding a 'append domain-name-servers' directive to a dhclient.conf file. (Let's assume the host is using dhcp).

Perhaps there are even more ways...

Which way is preferred? If I want the name server address to be persisted following restarts, and also be available for use immediately in the next lookup by the host, which option is best?

Thanks

3 Answers 3

4

I would

  • add it to the DHCP server's domain name-server option list
  • add it to /etc/resolv.conf

The client will start using it immediately and the next time it refreshes it's DHCP lease/options it will get it from the server too.

You could also add the new server to the DHCP server's domain name server list and restart networking on the client so that it immediately updates from the server

service network restart

If you don't want to change the DHCP server configuration then you can use the /etc/dhcp/dhclient.conf file to append or prepend an address to the domain-name-servers list

append domain-name-servers 8.8.4.4;

would add the name server at 8.8.4.4 to the end of the list of nameservers in /etc/resolv.conf. Using prepend would put it at the beginning.

Be aware that the maximum number of entries in the nameserver list in /etc/resolv.conf is 3.

3
  • Sorry, I was slightly unclear. I'm on the host side, not the DHCP server side. I want to add a name server that my host will use, and leave the DHCP server as-is.
    – ChaimKut
    May 21, 2013 at 7:13
  • @ChaimKut Why? Is static configuration an option?
    – ewwhite
    May 21, 2013 at 13:50
  • @ewwhite I'm working on an application intended to run on a regular host. The application has no ability to alter the DHCP server sitting elsewhere in the network.
    – ChaimKut
    May 22, 2013 at 16:22
1

The way I have always done it was to modify /etc/network/interfaces.

The entry for all my hosts looks like this:

dns-nameservers 8.8.8.8 8.8.4.4

This sets 8.8.8.8 and 8.8.4.4 as your DNS servers, naturally you could replace those with whichever DNS you decide to use. After modifying that file make sure to issue /etc/init.d/networking restart so the changes take affect.

1
  • 1
    CentOS doesn't have that file.
    – user9517
    May 21, 2013 at 13:39
1

Changing this at /etc/resolv.conf by adding the appropriate entries is the most consistent approach across Linux distributions/versions. Plus, it is immediately active and persists across reboots. Consistency is key here.

I would not rely on the ifcfg-ethX files or something like dhclient's configuration file. The system probably shouldn't be using DHCP (unless it's a workstation), and that's an assumption that doesn't scale...

1
  • This would be overwritten by dhclient as per the OPs third bullet point.
    – user9517
    May 21, 2013 at 13:47

You must log in to answer this question.

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