On my home LAN I have a number of computers. They are connected to a router which connects me to the internet and acts as DHCP server and nameserver on the LAN.
Some of my computers are Ubuntu machines, and I'm trying to set up a good /etc/resolv.conf on them. The problem is that my router is really lousy as a nameserver (very, very slow), so I prefer to use an external name server such as Google's nameserver or OpenDNS.
But these public nameservers obviously do not know the IP addresses of my local machines.
So here's my question: Is there any way to configure /etc/resolv.conf so that certain hostnames are resolved by one nameserver and other hostnames are resolved by another nameserver?
(My guess is no, and in that case I'll have to set up fixed IP addresses. But I hope to avoid that.)
Install a local forwarding nameserver on the computers that need to make a choice between the local nameserver and Internet nameserver. Use Unbound because it's lightweight and easy to configure for this task.
Put this into the Unbound config:
stub-zone:
name: "internal.example.com"
stub-host: internal.nameserver.ip.address
forward-zone:
name: "."
forward-host: internet.nameserver.ip.address
Put nameserver 127.0.0.1
into /etc/resolv.conf
so that application on the local host wil use this instance of Unbound.
Now when you try to resolve myhost.internal.example.com
it will send the query to internal.nameserve.ip.address
and when you try to resolve www.google.com
it will send the query to internet.nameserver.ip.address
.
Hopefully all of your local hosts are grouped under a single local domain (internal.example.com
) above. Unfortunately, it is all too likely that your cheap router+DHCPserver+DNSserver sticks all of the hostnames it knows right into its synthesized root zone. If that's the case then you'll have to list them all one by one as follows:
stub-zone:
name: "hostname1"
stub-host: internal.nameserver.ip.address
stub-zone:
name: "hostname2"
stub-host: internal.nameserver.ip.address
stub-zone:
name: "hostname3"
stub-host: internal.nameserver.ip.address
forward-zone:
name: "."
forward-host: internet.nameserver.ip.address
The problem with this is of course that now you have a bunch of Unbound instances on different machines that you have to configure and set up. You could avoid this by having just one host on your LAN provide this service and act as a recursive nameserver for all the other hosts, but if you're going to do that then you might as well make that host the DHCP server and authoritative nameserver for local hosts too and get rid of your slow embedded DHCP+DNS server in the first place.