I have a number of machines which do not use a network manager, and only use dhcpcd for setting the IP address. For example, my raspberry pi 4. I have statically assigned the IP address in the /etc/dhcpcd.conf file, and it works, I am happy. What I want to do, is make it so that if I type nslookup machine2 (for example), it appends the configured domain to that lookup.

In another machine that uses dhcpcd (my ArchLinux PC), I have the address configured to use dhcp (i.e. not static this time), via dhcpcd. On my DHCP server, I have set it up so that it specifies the "domain-name" field as an option that is returned to the client. The result, is that my /etc/resolv.conf file is updated with the following line:

domain mydomain.local

As this "domain" value is set in this file, I can simply just type nslookup machine2, and it appends mydomain.local to that query, and my dns server resolves the IP for the fqdn of machine2.mydomain.local.

So ideally, I want to mimick this setup, so that my raspberry pi4 will do the same thing, however it's statically set, so how do I do that?

Please note, I've tried adding "search domain.local" to the /etc/resolv.conf file, and it does what I want it to do, but then these settings are lost on reboot, so I cannot set this value here. I need a proper working solution with dhcpcd.


I was asked to put an output of my /etc/resolv.conf here:

$ cat /etc/resolv.conf
# Generated by resolvconf
  • Apologies I completely misread dhcpcd as dhcpd. Sorry for the confusion. Dec 17, 2019 at 0:21

2 Answers 2


If I have (at last) understood correctly then you have configured your network with dhcpcd.conf (not dhcpd.conf)

I imagine this configuration takes a form similar to this:

interface eth0
static ip_address=
static routers=
static domain_name_servers=

To set the domain and search domain you should be able to just add something like this:

static domain_name=example.com
static domain_search=example.com

In other words, you just need to set the domain_search as a static option.

For reference see here http://www.techsneeze.com/configuring-static-ip-raspberry-pi-running-raspbian/

As noted by the OP, this option is very well hidden. It's inferred because dhcpcd is a network configuration tool built around DHCP concepts. In dhcpcd you set static configuration by defining (parts of) a DHCP response. So in this situation the answer is simply to add the domain_search to the statically defined values.

The reason for this being poorly documented may be to do with the fact that DHCP allows custom DHCP options to be added. It's therefore impossible for dhcpcd to list every option that you could define statically. As it happens domain_search is not part of the core DHCP standard, it's bolted on by RFC 3397.

That said. It could be better described in the manual.

  • 4
    Hello again Philip, thanks for your efforts, honestly. The documentation on this setting is non-existent, or I couldn't find it. It works! There is a catch though! IF you specify your "static domain_name_servers" BEFORE you specify the "static domain_name", then you actually lose your name servers. However, if you do it the other way around, both work! Not exactly sure why that is, but it works this way around correctly. If you have a link to ANY documentation on this, please share, as I found it very VERY difficult to find the correct syntax online. Again, thanks for your help!
    – john smith
    Dec 17, 2019 at 1:15
  • 2
    PS: Can you update your reply so that it shows the static domain_name before the static domain_name_servers, so that others don't run into this "bug", or whatever it is that's making the name servers drop out the resolv.conf with the current way around you have posted. Then I'll mark it as answered. Again, I'm so very grateful for all your efforts on this, I really appreciate it!
    – john smith
    Dec 17, 2019 at 1:17
  • @johnsmith you are right on both counts. This is very well hidden, I read through the entire man page and couldn't see it. And that order doesn't seem like it should make a difference so well done for spotting it. I'll investigate further tonight about that. It could well be a bug. Dec 17, 2019 at 7:49
  • @johnsmith wow - the order domain_name / domain_name_servers is indeed important - I FINALLY fixed my config thanks to that little comment! I've had a resolvconf.conf workaround for YEARS! Thank you so much for sharing!
    – asac
    Oct 28, 2022 at 14:08

I am not sure how to get the answer using nslookup. BUT for a program that uses the nsswitch.conf file to tell it how to resolve things, you can do it IF the target of your query is running avahi (or any zero_conf aka mDNS daemon). The getent cmd is such a utility. For example I have a PC on my LAN with the name 'shadow'

`getent hosts shadow`

returns nothing.

but getent hosts shadow.local returns: shadow.local

avahi-resolve -n shadow returns

Failed to create host name resolver: Invalid host name

avahi-resolve -n shadow.local returns:


Even though I have never defined the domain "local" anywhere.

For this to work the target must be on-line so that it can answer mDNS polls. For example if host hector is offline:

avahi-resolve -n hector.local

Failed to resolve host name 'hector.local': Timeout reached

getent hosts hector.local

times out with nothing returned

The KEY is to have the following line in your /etc/nsswitch.conf file:

hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname

This will cause a cmd like getent to first check the /etc/hosts file and if the host is not found there to try using the mDNS facility.

I think that installing and running avahi automatically adds the necessary libraries to the path(s) that getent checks so that when getent sees mdns4_minimal in the nsswitch.conf file it knows what to do.

The above is a bit of a (unsatisfactory) hack. I would be very interested in knowing how to coerce dhcpd into doing what you want. pgmer6809

You must log in to answer this question.

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