How to use local DNS server for specific domain, and use DHCP-assigned DNS for everything else

2

I have the need to run a local DNS server for a local (non-routable) domain on my laptop, for development purposes. Simply editing /etc/hosts is not sufficient for my case, because I need certain VMs, which depend on actual DNS, to resolve the local domain.

Configuring bind to serve the local domain is easy. Configuring bind with forwarding addresses is also easy.

The problem lies in that once bind is configured, and resolvconf set to use 127.0.0.1 for name resolution, connections to wireless networks that depend on a web-based authentication breaks, since the local wireless network's DNS servers are no longer used.

Is there some way to dynamically set Bind's forwarding addresses when the network is brought up (perhaps via resolvconf, or some other similar service)?

Alternately, is there some way to use my local bind server only for my local domain name, and use those provided by DHCP for all other name resolution?

Flimzy

Posted 2017-09-20T02:09:59.937

Reputation: 4 168

Do you have resolvconf-update-bind script in /etc/resolvconf/update.d/ directory? – AnFi – 2017-09-20T05:16:18.543

Why don't you drop bind in favour of DNSMasq? – davidgo – 2017-09-20T05:53:47.297

@davidgo: dnsmasq doesn't work as an authoritative name server, so obviously it won't serve my needs. Maybe dnsmasq could be used along side bind, to accomplish my needs--if you think it would, I'd love to see your answer. – Flimzy – 2017-09-20T14:26:14.593

@AndrzejA.Filip: No, I'm not familiar with that file. Is that part of the standard resolvconf distribution? – Flimzy – 2017-09-20T14:27:05.337

@Flimzy AFAIR: Sample script (for bind8) is provided in debian resolvconf package BUT it is not installed in /etc/resolvconf/update.d/. – AnFi – 2017-09-20T18:17:40.267

@AndrzejA.Filip: Thanks, that was the hint I needed. If you'd like to turn that into an answer, I'll accept it. – Flimzy – 2017-09-20T21:41:27.673

As your local DNS is "non-routable", DNSMasq should be up to the task - you simply put the IP addresses in the hosts file and let DNSMasq inject these into the local recursive DNS served by DNSMasq, or specify them with "address=" lines, or even palm off zones to another BIND dns server using the "server" directive. DNSMasq will inject the domains in hosts files by default (unless no-hosts" is turned on). – davidgo – 2017-09-21T07:42:38.063

Another possibility - unless I'm missing something- which is probable - would be to turn your BIND instance into a full-blown recursive DNS server, ie to not use forwarders. This will (slightly) slow down your DNS response times though, because it can't take advantage of the larger nameservers cache. – davidgo – 2017-09-21T07:44:49.473

@davidgo That wouldn't help with these wireless access points that redirect to a login page before allowing full network access. – Flimzy – 2017-09-21T11:17:09.357

Answers

1

resolvconf program is capable to reconfigure bind to use per current connection DNS forwarders.

Sample resolvconf-update-bind script for bind8 is provided in debian resolvconf package
BUT it is not automatically installed in /etc/resolvconf/update.d/ directory.

AnFi

Posted 2017-09-20T02:09:59.937

Reputation: 771

0

Can you add the Wireless DNS's servers to the bind's forwarders ?? Eg. in your /etc/bind/named.conf.options configuration file :

options {
    directory "/var/cache/bind";

    recursion yes;                 # enables resursive queries
    ...
    allow-transfer { none; };      # disable zone transfers by default

    forwarders {
            Wireless DNS's server;
            Other DNS server IP (open dns resolver, ...);
    };
...
};

In that case, bind will forward request the requested domain if it is not present in his configured zone, first to the Wireless DNS server, second to the open DNS server. As you are 'stacking' resolvers, this might induce delay in your DNS reply for domain not served by the wireless DNS server. You should then set up a dns cache server.

EDIT

Source: https://www.digitalocean.com/community/tutorials/how-to-configure-bind-as-a-private-network-dns-server-on-ubuntu-14-04

Specify DNS server for specific domain

Source: https://serverfault.com/questions/391914/is-there-a-way-to-use-a-specific-dns-for-a-specific-domain

This is not possible with resolv.conf. But you can acheive that with dnsmasq:

/etc/dnsmasq.conf:

server=/mydomain.net/X.X.X.X

where X.X.X.X is your local DNS server which is not present in your dhcp filled resolv.conf file.

vera

Posted 2017-09-20T02:09:59.937

Reputation: 760

As stated in the question: Configuring bind with forwarding addresses is easy. The problem is that the forwarders I need to use change depending on which network I'm connected to. – Flimzy – 2017-09-20T14:23:14.433

sorry I did not point out that servers are changing – vera – 2017-09-20T15:18:20.850