0

I have a server with search example.com in resolv.conf, and it works correctly for DNS lookups. That is, if I ping host, and host1.example.com is in DNS, it is found.

But if host1.example.com is in /etc/hosts instead of DNS, it is not found. I assume the entry in resolv.conf only applies to DNS.

Is there a way to make a domain search path that works for /etc/hosts entries, and if not, why not?

2
  • You could have aliases in the hosts file, e.g. the entry 172.16.1.1 host1.example.com host1.
    – Torin
    Apr 5, 2018 at 17:09
  • You write ”if I ping host […]“. Don't you mean host1?
    – myrdd
    May 15, 2019 at 16:38

1 Answer 1

3

The simple and generally used method is to include both host1 and host1.example.com to /etc/hosts.

However, you can reach your goal using dnsmasq. dnsmasq will read your hosts file (configurable,this is the default), you just have to set your original ns as upstream in dnsmasq and localhost as ns in resolv.conf and you can keep your search option. You will get the added benefit of locally cached name service.

This is the most basic (probably server) setup, if you are using resolvconf like ns manager you have to configure that instead.

It's worth to keep in mind, if you make changes in /etc/hosts you must restart dnsmasq.

You must log in to answer this question.

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