I want to create a host file on a custom location (ex. /opt/app/hosts) with the same formatting as the /etc/hosts file.

The reason for this is that I want to manually query a DNS server for a specific range of hosts and write those to my own custom host file. I can't add that DNS server to the /etc/resolv.conf because I don't want the server to try resolving hosts with it (apart from the small subset that I query manually).

I've tried searching for a way to include it in /etc/hosts or configure it in /etc/nsswitch.conf or /etc/resolv.conf but as far as I can tell neither of these configuration files contain.


You can setup BIND to forward requests for specific domains to specific DNS server:

zone "some.domain"
        type forward;
        forwarders {; };

All other requests will be forwarded to servers specified in global options::forwarders section. Probably, this is the best way to achieve what you want.


dnsmasq can do this (and more); it allows you to use any local name database in addition to the regular hosts file and DNS with one easy switch:

dnsmasq -H /opt/app/hosts

  • You can also use dnsmasq as a proxy to send all dns requests through to your normal name server, and then send these specific requests on through to the special name server. This way you dont have to keep anything local and do manual updates when it changes. – phemmer Nov 2 '11 at 13:52

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.