I have already read the very useful question about dhcpcd: How do I set up networking/WiFi/static IP address?

My situation seems to be slightly unusual:

  • DHCP server on LAN is set to always give the Pi a specific IP address (based on its MAC). Let's say
  • The Pi is running bind, listening on

I want to configure the Pi to still get its IP address via DHCP, but to force the primary DNS server to be (itself).

I understand I should update /etc/dhcpcd.conf with: nohook resolv.conf

Is the "correct" way, on the Pi, to set the DNS server to:

  1. Add the DNS configuration to /etc/resolv.conf.tail, OR
  2. Add static domain_name_servers=... to /etc/dhcpcd.conf?

Are there any particular advantages or disadvantages to either method?

Also, I do not want to configure the DHCP server to give out as the DNS server.

  • Hi @Milliways, thanks for the comment. I'm not quite sure why you think it doesn't makes sense? As I say in the post, the Pi is running the Bind DNS server so that's why I want to tell the Pi to use itself as the DNS server and also as I say in the post, I don't want to give out the Pi's IP address via DHCP (because I don't want other devices on the network to use the Pi as the DNS server).
    – Bridgey
    Nov 10 '16 at 11:51

I think the answer you're looking for is here.

Blatantly plariarised:

You can add the following line to /etc/dhcp/dhclient.conf:

prepend domain-name-servers <working DNS IP(s) here>;

This adds the DNS IP address(es) you specify before that/those provided by the DHCP. If you would like to add it/them after the address(es) provided by the DHCP, just use

append domain-name-servers <working DNS IP(s) here>;

If, instead you would like to ignore the DNS address(es) provided by the DHCP altogether, use

supersede domain-name-servers <working DNS IP(s) here>;
  • Thank you very much for this - very helpful! I think this is for dhclient rather than dhcpcd, but I guess the principle is the same: specify it in he dhcp client configuration and it should get passed through to '/etc/resolve.conf'. I'll give it a while to see if anybody posts a dhcpcd-specific answer, but if not I'll accept yours. Thanks!
    – Bridgey
    Nov 10 '16 at 13:22
  • dhcpd is the DHCP server, isn't it? The thing which hands out IP addresses. That's not what you want to be running on your Pi if you have a router already doing it (which is what I interpreted from your post). dhclient is the DHCP client which goes to the DHCP server and gets an IP address (and other things). If you really are wanting the Pi to be the DHCP server, then that's a special case I don't know about -- how the DHCP server's IP address is allocated.
    – Mark Smith
    Nov 10 '16 at 13:31
  • dhcpcd - note the c :) This is a DHCP client not server :) This is currently the recommended DHCP client for the Pi (I believe!)
    – Bridgey
    Nov 10 '16 at 13:46
  • Ah! My mistake! :-)
    – Mark Smith
    Nov 10 '16 at 13:48
  • This is the selected answer, but it is not the correct answer. It will probably work if you're using dhclient, but if you're using deprecated software you probably know this.
    – Seamus
    Aug 25 '20 at 5:23

A Correct Way to Specify a DNS Server when Using DHCP:

This answer provides one correct way to override the DNS server(s) obtained by dhcpcd through the DHCP process. Here's another way (REF: dhcpcd documentation):

Create a file named /etc/resolv.conf.head. List your preferred DNS servers here using the same format as in /etc/resolv.conf. dhcpcd will prepend this file to /etc/resolv.conf.

dhcpcd was "hired" to write /etc/resolv.conf through resolvconf. If you write to it directly, your manually-generated DNS entries may be overwritten, possibly creating chaos in your system.

A Correct Way to Specify a "Fixed" IP Address:

Don't be tempted to use the static_ipaddress option in /etc/dhcpcd.conf; man dhcpcd.conf is specific about this:

For IPv4, you should use the inform ipaddress option instead of setting a static address.

If you use the inform ipaddress option in /etc/dhcpcd.conf, you will effectively have a static IP address, and you will see it in your router's DHCP table of leases.


The correct way to set DNS servers is in /etc/dhcpcd.conf. This will override the value supplied by the DHCP server, without interfering with other DHCP functions. Look for a line that looks like this (create it if it doesn't exist):

static domain_name_servers=

Separate multiple IP addresses with a single space ( ).

You can verify your DNS settings by executing nslookup <somewhere.com> from the command line. You should see the DNS servers you've specified in /etc/dhcpcd.conf listed in the output of nslookup.

I was updating the DNS servers for a Pi of mine, and found that I'd already specified the DNS servers here.

  • 1
    This is the correct answer if you're using dhcpcd instead of systemd-networkd. You should not be writing to /etc/dhcp/dhclient.conf as that is what dhcpcd was "hired to do" - the selected answer is incorrect unless you're still using the now deprecated dhclient.
    – Seamus
    Aug 25 '20 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.