Local Home Network DNS – how hard can it be?

So I wanted to do something I thought would be fairly straightforward.  I have a home network with a PlusNet-provided Technicolor Gateway router and behind that I currently have my (Windows 7) laptop and my HP Proliant Microserver running Lubuntu.

In addition to a media server I want to use my Lubuntu box as a development environment for multiple websites, but I want to be able to access each website from the laptop.

Running multiple sites is easy enough with Apache’s Virtual Hosts feature, and I can configure the /etc/hosts file on my server to let me access them locally.  However I want to be able to do the actual work /testing on my laptop (for starters) and have an easy to remember name for each of the virtual hosts.

So here’s what (I think) I need to do:

  1. Install Apache (and PHP/MySQL) and configure the virtual hosts – check.
  2. Set up a DNS server on my server
  3. Configure the laptop to query that server for DNS (preferably through the router config so it applies to the whole network…) let’s come to that later.

Piece of cake, right?  Read on for completion of step 2.

What I want is my server, let’s call it “myserver” (took me hours to come up with that), to be myserver.lan.  That works fine out of the box (I think my router is preconfigured to use .lan as the device itself seems to live at dsldevice.lan – I’m at the stage of hoping that doesn’t cause problems without quite understanding it).  All I want to do is add my different websites on myserver as subdomains – e.g. site1.myserver.lan, site2.myserver.lan etc

Enter dnsmasq

I experimented with Bind9 without much luck and then discovered that (L)Ubuntu’s Network Manager tool comes bundled with its own version of a tool called dnsmasq – apprently a lighter-weight DNS and DHCP server.  I have my router doing DHCP so don’t need that, but you can supposedly run DNS in dnsmasq independently of that so I figured I’d give it a go.

So I changed approach, removed Bind and tried to configure this dnsmasq instance.  It turns out this instance of dnsmasq runs on 127.0.1.1 rather than the usual localhost ip of 127.0.0.1.  Lubuntu also seems to preconfigure it to do some weird stuff (like not read your hosts file, which dnsmasq usually includes in its config) meaning I couldn’t figure out how to expose it to the rest of my network.

Luckily, it’s this packaged instance is configured to allow you to run a separate instance of dnsmasq (which is one reason for using the 127.0.1.1 address).  So a quick sudo apt-get install dnsmasq later and I’m up and running.  As I’d already been messing about using dnsmasq.conf (with some help from linux.com) to try and make the aforementioned bundled isntance work, it asked me if I wanted to keep the file I had or overwrite it with a fresh one.  I used the package’s ‘clean’ one.

Success?

As I said before, by default dnsmasq reads any hostname/IP address pairs from your /etc/hosts file and since I’ve already added the addresses I want to use into my /etc/hosts, when I test dnsmasq all seems good.  I fire up Powershell on my Windows laptop and:

PS C:\Users\Steve> nslookup site1.myserver.lan <ip-address-of-myserver>
Server: site1.myserver.lan
Address: <ip-address-of-myserver>

Name: site1.myserver.lan
Address: <ip-address-of-myserver>

So far so good… but that’s only half the story.  This only works if I directly tell my PC to query that DNS server (i.e. by putting the <ip-address-of-myserver> in the command above.  When I leave that off it uses the DNS server configured in Windows, i.e. the IPv6 adress pointing at my router.  I had already set static DNS servers for my laptop, pointing at myserver, but the IPv6 address (which I haven’t changed, so the router is still setting by DHCP) seems to be taking precedence. This also means that using ping or trying to browse to the domain gives a DNS error.

Now what…?

I could disable IPv6, probably with limited repurcussions but I don’t like dirty workarounds (or losing!).   That leaves me with the option of either configuring my laptop and giving it the IPv6 address of myserver or doing it right and forcing my Technicolor Gateway router to use myserver as it’s primary DNS.  I think I’ve won the round on this one, but the war continues…

Author: nerd.

An experienced IT professional, I used to run a number of small websites and spend a lot of time tinkering with my sites or my PC - back when I had free time.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.