0

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.

Lhunar
  • 3
  • 2

2 Answers2

3

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

adaptr
  • 16,576
  • 23
  • 34
  • 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 02 '11 at 13:52
0

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

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

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.

gelraen
  • 2,341
  • 20
  • 19