Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer

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

share|improve this answer
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. – Patrick Nov 2 '11 at 13:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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