If you begin to have a lot of computers at home, or even you manage a little LAN on an office, it may come in handy to have a little domain configured. Having a domain configured has some advantages, including easy machine naming and name resolution of those machines. We'll explain here how to setup a little domain with a linux machine and an opensource DHCP and DNS servers.

For this to work you'll need:

Having a custom DHCP server will allow you to have more control over the IP leases you have in your network. One nice feature that most of the low cost DSL/Cable routers don't provide are static IP mappings for specific machines via it's MAC Ethernet address. Of course you could simply configure the IPs of your computers statically, but it's always more confortable to simply check the "get everything network related automagically" when you are configuring your computers. And having some specific computers an static IP address will be very useful later, when we set up the DNS, so we will be able to have our computers friendly names such as "router", "dad", "xbox360" or "mediacenter". Another interesting advantage on having certain computers on certain IP addresses is that we can configure certain ports to be open for specific machines without having to worry on what IP will it have when the lease expires or the computers reboots.

Having a custom DNS will serve two purposes. First of all, as an internet DNS server, which will come in handy since we'll be querying the DNS root servers directly, avoiding the risk of our ISP DNS to shut down and leaving us without name resolution. And secondly, will allow us to resolve names in our custom domain, so we can connect to our dad's comp or our Xbox 360 simply typing "dad" or "xbox360" as the network name of the device.

First of all, we'll start configuring the DHCP server. Use your preferred method to install ISC DHCP Server in your current distribution. When you have it installed, we'll create our custom IP leasing schema. We will use the subnet 192.168.1.0/24 (refer to a networking manual if you have trouble finding out what those numbers mean). For simplicity's sake, let's suppose we have 4 devices we want to configure in our LAN. Finally, we will use "mydomain" as a domain name.

  • Our internet router, will have the IP address 192.168.1.1 (remember to turn off the DHCP Server from this router or you'll end up with a nasty broadcast conflict).
  • Our server, will have the IP address 192.168.1.2 and it's name will be "server.mydomain".
  • Our computer, will have the IP address 192.168.1.3 and it's name will be "uber.mydomain".
  • Our dad's computer, will have the IP address 192.168.1.4 and it's name will be "dad.mydomain".
  • An Xbox 360 computer, will have the IP address 192.168.1.5 and it's name will be "xbox360.mydomain".

We'll reserve those 5 initial addresses and some more for static purposes, let's say from 192.168.1.1 to 192.168.1.20, because we may add new machines in the future. We'll want other computers who want to connect (such as laptops or another gadgets like PSPs or Nintendo DSs) have a random IP dynamically assigned starting from 192.168.1.21 until 192.168.1.254. This is what we have to put on our "/etc/dhcp3/dhcpd.conf" configuration file:

default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.2;
option domain-name "mydomain";
# mydomain
subnet 192.168.1.0 netmask 255.255.255.0 {
        range 192.168.1.21 192.168.1.254;
        }

This lines will tell the server some default options like the lease time, but more importantly, the gateway, dns server and network mask and broadcast address. The subnet clause will tell the server the range of IPs it has to lease for the network we want to set up.

The next step is to set up the fixed IP hosts. We will have to add a clause like this one for every one of them:

host uber {
   hardware ethernet 00:00:00:00:00:00;
   fixed-address 192.168.1.3;
}

Note the two lines. "hardware ethernet" must containt the MAC address of the network card of the computer you want to configure, and "fixed address" must contain the IP address you want to assign to that computer. Consult your OS networking documentation on how to obtain the MAC address of your NIC if you don't know how to do it.

This is all you need to setup your DHCP server.

Let's see now how to configure the DNS service. I'm not gonna tell you the specifics on how to setup bind to resolve internet addresses. It should ship configured to do so by default. If it does not, Google it to find the standard setup. What I'm gonna show you here is how to set it up to resolve names in our domain "mydomain". What wee need to tell our bind server are three things:

  • That he has to resolve the names in the "mydomain" domain.
  • Where to find the name - address resolution.
  • Where to find the address - name resolution.

Let’s start with the latter options. Use your favourite text editor to edit a file named “/etc/bind/db.mydomain” and type this in it: </p>

$TTL 3D
@       IN      SOA     server.mydomain. ns2.mydomain. (
                        199802151       ; serial, todays date + todays serial #
                        8H              ; refresh, seconds
                        2H              ; retry, seconds
                        4W              ; expire, seconds
                        1D )            ; minimum, seconds
mydomain.        IN NS      server.mydomain.              ; Inet Address of name server

localhost.mydomain. IN A 127.0.0.1
server.mydomain. IN A 192.168.1.2
uber.mydomain. IN A 192.168.1.3
dad.mydomain. IN A 192.168.1.4
xbox360.mydomain. IN A 192.168.1.5

The file is pretty self explanatory. We're telling our server the mapping and some parameters like refresh time of the resolutions.

If we want reverse dns, we have to tell the server the reverse map. You should keep those two files in sync whenever you modify one of them. Again, edit a file named "/etc/bind/db.192.168.1" and type in those lines:

$TTL 3D
@               IN      SOA     ns.mydomain. hostmaster.mydomain. (
                199802151       ; Serial
                8H      ; Refresh
                2H      ; Retry
                4W      ; Expire
                1D)     ; Minimum TTL
        NS      ns.mydomain.
2 PTR server.mydomain.
3 PTR uber.mydomain.
4 PTR dad.mydomain.
5 PTR xbox360.mydomain.

Now we have to tell our server that he has to resolve the addresses from those domains using the files we just created. Edit your bind configuration file (typically "/etc/bind/named.conf") and add those two zones:

zone "mydomain" {
        type master;
        file "/etc/bind/db.mydomain";
        allow-query { 192.168.1.0/24; };
};

zone "1.168.192.in-addr.arpa" {
        type master;
        file "/etc/bind/db.192.168.1";
        allow-query { 192.168.1.0/24; };
};

And voilà, you're done! Now you have the computers in your LAN in a proper domain, with the IP addresses and names you want and en easy way to connect to them by simply using its names.

Don't forget that for everything to work you have to configure your computers to use DHCP and that they must resolve the names in the "mydomain" domain. This is done in different ways depending on your OS. In Linux you must use the "search" option in the "/etc/resolv.conf" file (which isn't really needed because we specified that in our DHCP server). In Mac OS this option is configured in the NIC setup, and in Windows it's done under the System Preferences.

Thanks to Roger Ferrer on helping me with the understanding of Bind!