Setting up a DNS for the local network on the Ubuntu Hardy Heron server

There is now an updated guide for Ubuntu 12.04: Setting up a DNS for the local network on the Ubuntu 12.04 (Precise Pangolin) server

Condensed version

This is my really condensed step by step procedure that I took to setup my local dns for our local network at home. It really isn’t more than just a shorter version of the great guides posted by Sam Davis:

BIND Caching Name Server Setup
BIND Master Server Setup

I really recommend that you read his two post to get some more information, then you can check my pointers and maybe my configurations posted below if you want yet another example to look at.

Step by step instructions

1: Make sure that the latest version of bind9 is installed (that’s the dns-server software):
sudo apt-get install bind9

2.1: Configure the DNS to cache requests:
sudo nano /etc/bind/named.conf.options

2.2: Uncomment or add the forwarders section and replace the x:es with the ip-address to the primary and secondary dns of your isp:

forwarders {
        x.x.x.x;
        x.x.x.x;
};

3.1: Make the server use its own DNS for lookups:
sudo nano /etc/resolv.conf

3.2: Change or add the nameserver directive to point to the local machine:
nameserver 127.0.0.1

3.3: You can also add a search directive, to that you don’t have to type the whole fully qualified domain name every time, just the computer name instead:
search home.lan

Note: This must also be done for other Ubuntu clients that use a static IP. But then it should point to the IP of the DNS server. If you have a DHCP server you should specify your DNS IP in its settings, as well as the search domain.

4.1: Define the zones for the local domain:
sudo nano /etc/bind/named.conf.local

4.2: Add a zone for the local domain:

zone "home.lan" IN {
    type master;
    file "/etc/bind/zones/home.lan.db";
};

4.3: Also add a zone for reverse dns lookups for the local network:

zone "10.10.10.in-addr.arpa" {
    type master;
    file "/etc/bind/zones/rev.10.10.10.in-addr.arpa";
};

Note: Make sure that it’s literal quotes that is used, so that they not are converted if you copy and past them to the terminal. You get literal quotes on a Swedish keyboard by pressing “Shif+2″, on an English keybord it might be “Shif+,” ?

5: Create the zones directory:
sudo mkdir /etc/bind/zones

6.1: Configure the local domain:
sudo nano /etc/bind/zones/home.lan.db

6.2: My settings, change to your match your host names and ip-addresses:

; Use semicolons to add comments.
; Do NOT add empty lines.
; Host-to-IP Address DNS Pointers for home.lan
; Note: The extra “.” at the end of addresses are important.
; The following parameters set when DNS records will expire, etc.
; Importantly, the serial number must always be iterated upward to prevent
; undesirable consequences. A good format to use is YYYYMMDDII where
; the II index is in case you make more that one change in the same day.
home.lan. IN SOA ubuntu.home.lan. hostmaster.home.lan. (
    2008080901 ; serial
    8H ; refresh
    4H ; retry
    4W ; expire
    1D ; minimum
)
; NS indicates that ubuntu is the name server on home.lan
; MX indicates that ubuntu is (also) the mail server on home.lan
home.lan. IN NS ubuntu.home.lan.
home.lan. IN MX 10 ubuntu.home.lan.
; Set the address for localhost.home.lan
localhost    IN A 127.0.0.1
; Set the hostnames in alphabetical order
print-srv    IN A 10.10.10.9
router       IN A 10.10.10.10
server       IN A 10.10.10.5
ubuntu       IN A 10.10.10.1
xbox         IN A 10.10.10.2

7.1: Create and edit the reverse lookup configuration file:
sudo nano /etc/bind/zones/rev.10.10.10.in-addr.arpa

7.2: My settings, reversed of the above:

; IP Address-to-Host DNS Pointers for the 10.10.10.0 subnet
@ IN SOA ubuntu.home.lan. hostmaster.home.lan. (
    2008080901 ; serial
    8H ; refresh
    4H ; retry
    4W ; expire
    1D ; minimum
)
; define the authoritative name server
           IN NS ubuntu.home.lan.
; our hosts, in numeric order
1         IN PTR ubuntu.home.lan.
2         IN PTR xbox.home.lan.
5         IN PTR server.home.lan.
9         IN PTR print-srv.home.lan.
10        IN PTR router.home.lan.

8: Restart bind to use the new settings:
sudo /etc/init.d/bind9 restart

9: Test that the dns lookups works with the local server:
host ping.sunet.se

The response should be:
ping.sunet.se has address 192.36.125.18
ping.sunet.se has IPv6 address 2001:6b0:7::18

10: Test that all of your computers are listed with the following command:
host -l home.lan

The output should list all of your entered hosts:

home.lan name server ubuntu.home.lan.
localhost.home.lan has address 127.0.0.1
print-srv.home.lan has address 10.10.10.9
router.home.lan has address 10.10.10.10
server.home.lan has address 10.10.10.5
ubuntu.home.lan has address 10.10.10.1
xbox.home.lan has address 10.10.10.2

11: Test that the reverse lookup works:

 host 10.10.10.1

Response:
1.10.10.10.in-addr.arpa domain name pointer ubuntu.home.lan.

Final words
Do not forget to update the serial every time you make any changes to a zone file.

Referenses:
BIND Caching Name Server Setup
BIND Master Server Setup

About these ads

25 thoughts on “Setting up a DNS for the local network on the Ubuntu Hardy Heron server

  1. Pingback: Make your DHCP server dynamically update your DNS records on Ubuntu Hardy Heron « Lani’s Weblog

  2. Bill Day

    Thanks for an excellent, concise tutorial. Everything worked first time! One thing you might add is that it sometimes is necessary to add or uncomment “prepend domain-name-servers 127.0.0.1;” to /etc/dhcp3/dhclient.conf if your server on your home lan gets its IP by DHCP. Otherwise, the DHCP server/router may overwrite your /etc/resolv.conf with its own IP address.

    Reply
  3. lani78 Post author

    Thank you Bill for your comment. I’m glad that it worked for you. And thank you for the pointer on the dhcp problem. I’ll leave that in your comment for now, as I don’t have any first hand experience with it myself as I use a static IP for my server.

    Reply
  4. Todd

    Fantastic post, this was the simplest way to get things going for my home lan. 1 question: when I have visitors hop on to my network, i’d like to be able to tell them that the shared fileserver is located at “fileserver” or something like that. right now, unless they change their resolve.conf file, they’ll have to type “fileserver.home.lan”. is there anyway to ditch the home.lan and just allow searching by machine name?

    Reply
    1. lani78 Post author

      Hi Todd, thank you for your kind words.

      You should be able to tell your DHCP-server to set the default domain to home.lan. With the dhcp3-server that are available for Ubuntu you can specify this with the following parameter:

      option domain-name “home.lan”;

      Reply
  5. John B

    Worked for me with no pain, thanks also to Bill Day for his comment above “prepend domain-name-servers 127.0.0.1;”

    Thanks Lani

    Reply
    1. lani78 Post author

      That is a really impressive and comprehensive how to! I’m glad that my information could help. I think that I have to try out Webmin some day. Thank you for letting me know about your how to. I saw your remark in your how to about the lack of a table of contents, I do however think that a TOC would add great value to your how to.

      Reply
      1. kevinthecomputerguy

        I hear ya. I worry a T.O.C will encourage people to jump around the doc. Each page kinda buils of the next one. But your right, because i keep getting asked for that. I will get started on it. You totally have to try webmin, it rocks. Don’t let anyone tell you its not secure, i see that all the time on google searches, and it just is not accurate.
        thanks for your help, thats DNS was kicking my butt.

    1. lani78 Post author

      bzr is short for Bazaar, which in this case is a version control system (http://bazaar.canonical.com). I’ve added it as an alias for the machine called ubuntu. That way I can have Apache serve me the Bazaar website when surfing to bzr and my default website when surfing to ubuntu. Removing the need to remember different ports for the different services, which would have been another possible setup.

      Reply
  6. Pingback: Can i set up a dns server if i don't have registered domain?

  7. Pingback: Help setting up a new server

  8. Pingback: DNS files .

  9. miki

    after # dig mysite.com
    I get this:
    ; <> DiG 9.4.2-P2.1 <> mysite.com
    ;; global options: printcmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36531
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

    ;; QUESTION SECTION:
    ;mysite.com. IN A

    ;; ANSWER SECTION:
    mysite.com. 0 IN A xx.xxx.xx.xxx

    ;; Query time: 214 msec
    ;; SERVER: 208.67.220.220#53(208.67.220.220)
    ;; WHEN: Wed Sep 29 12:58:08 2010
    ;; MSG SIZE rcvd: 45
    and after # ping mysite.com

    I get this:
    PING mysite.com (ip of my VPS) 56(84) bytes of data.
    64 bytes from mysite.com (ip of my VPS): icmp_seq=1 ttl=64 time=0.045 ms

    Those results are shown if I dig and ping from root of my VPS, but when I ping mysite.com from other machine (any where from internet) I get "unknown host mysite.com" how can I be shure that my zone files are correct??? there is about 24h of propagation (if that may be a problem) but I can't find mysite.com in any table (I was trying with diferent proxies and diferent tools)

    Reply
  10. Vinay Sajip

    Thank you for a very concise description, which worked flawlessly except for one thing: while the “host” command gave the correct address for a machine, the “ping” command failed! That’s because in my setup, my Ubuntu box doesn’t have a static IP address: it gets a DHCP address from my router (always the same address, since I’ve set up a MAC->IP mapping on the router, but still, it uses DHCP). The DHCP client code overwrites the “search” directive in /etc/resolv.conf, which means you can’t use unqualified host names: I circumvented this by adding

    supersede domain-name “home.lan”;

    to /etc/dhcp3/dhclient.conf. Hoping this info will help someone!

    Reply
  11. Pingback: DNS server

  12. Pingback: BInd

  13. Charles

    Thanks Lani — it was a great help :-)

    Three suggestions for improvement.

    Firstly the 10.10.10.x addresses are the same backwards and forwards. In …

    zone “10.10.10.in-addr.arpa” {
    type master;
    file “/etc/bind/zones/rev.10.10.10.in-addr.arpa”;
    };

    … it is not apparent that the address has been reversed. It would be apparent if say the 192.168.1.x range was used giving

    zone “1.168.192.in-addr.arpa” {
    type master;
    file “/etc/bind/zones/rev.1.168.192.in-addr.arpa”;
    };

    Secondly the bzr line could be removed; it confused me; I searched for a bzr keyword!

    Thirdly bind9 and probably earlier is OK with blank lines in a zone file (tested on 9.7.2). O’Reilly’s “DNS and BIND 5th Edition” section 4.2.2 suggests using blank lines and does not say anything about them only being possible in specific versions.

    Best

    Charles

    Reply
    1. lani78 Post author

      Hi Charles!

      Thank you very much for your comment! I’m glad that it helped you!

      I’m also grateful for your suggestions. I agree completely with you regarding the 10.10.10.x addresses, I just never thought about it. I created these guides mostly to remember what I did at home and I happen to use that address range in our home network. I could never believe that these tutorials would be so popular :) I will see if I get the time to update the addresses in all of the tutorials, so that they match if you do them in order.

      I will remove the bzr line right away! It was an alias that I used for my Bazaar version control system.

      And I guess that you suggest using blank lines in the zone file to increase readability? Which I also totally agree with.

      Regards,
      Lani

      Reply
  14. Pingback: strange nameserver logins from my lappy to lan hosts

  15. sweetcutie

    Evreything works great for me! except for host ping, it says “no servers could be reached” no idea why it doesnt work :(

    anyway great tutorial!

    ^,..,^

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s