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 {

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:

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 "" {
    type master;
    file "/etc/bind/zones/";

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
; Set the hostnames in alphabetical order
print-srv    IN A
router       IN A
server       IN A
ubuntu       IN A
xbox         IN A

7.1: Create and edit the reverse lookup configuration file:
sudo nano /etc/bind/zones/

7.2: My settings, reversed of the above:

; IP Address-to-Host DNS Pointers for the 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:

The response should be: has address 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
print-srv.home.lan has address
router.home.lan has address
server.home.lan has address
ubuntu.home.lan has address
xbox.home.lan has address

11: Test that the reverse lookup works:


Response: 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.

BIND Caching Name Server Setup
BIND Master Server Setup


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;” 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.

  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.

  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?

    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”;

  5. John B

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

    Thanks Lani

    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.

      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 ( 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.

  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
    I get this:
    ; <> DiG 9.4.2-P2.1 <>
    ;; global options: printcmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36531
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

    ; IN A


    ;; Query time: 214 msec
    ;; SERVER:
    ;; WHEN: Wed Sep 29 12:58:08 2010
    ;; MSG SIZE rcvd: 45
    and after # ping

    I get this:
    PING (ip of my VPS) 56(84) bytes of data.
    64 bytes from (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 from other machine (any where from internet) I get "unknown host" 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 in any table (I was trying with diferent proxies and diferent tools)

  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!

  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 “” {
    type master;
    file “/etc/bind/zones/”;

    … 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 “” {
    type master;
    file “/etc/bind/zones/”;

    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.



    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.


  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!



Leave a Reply to John B Cancel reply

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

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

Facebook photo

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

Connecting to %s

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