home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / DNS_HOWT.GZ / DNS_HOWT
Encoding:
Text File  |  1996-08-02  |  43.0 KB  |  1,050 lines

  1.   DNS HOWTO
  2.   Nicolai Langfeldt janl@math.uio.no
  3.   v1.1, 30 June 1996
  4.  
  5.   HOWTO become a totally small time DNS admin.
  6.  
  7.   Keywords: DNS, bind, named, dialup, ppp, slip, Internet, domain, name,
  8.   hosts, resolving
  9.  
  10.   Legal stuff:
  11.  
  12.   (C)opyright 1995 Nicolai Langfeldt.  Do not modify without amending
  13.   copyright, distribute freely but retain copyright message.  The author
  14.   wishes to thank Arnt Gulbrandsen who read the drafts to this work
  15.   countless times and provided many useful suggestions.
  16.  
  17.   Other stuff:
  18.  
  19.   This will never be a finished document, please send me mail about your
  20.   problems and successes, it can make this a better HOWTO.  So please
  21.   send money, comments and/or questions to janl@ifi.uio.no.
  22.  
  23.   This HOWTO is dedicated to Anne Line Norheim.  Though she will
  24.   probably never read it since she's not that kind of girl.
  25.  
  26.   1.  Introduction.
  27.  
  28.   What this is and isn't.
  29.  
  30.   DNS is, to the uninitiated (you ;-), one of the more opaque areas of
  31.   network administration.  This HOWTO will try to make a few things
  32.   clearer.  It describes how to set up a simple DNS name server.  For
  33.   more complex setups you will need to read the Real Documentation.
  34.   I'll get back to what this Real Documentation consists of in ``the
  35.   last chapter''.
  36.  
  37.   Before you start on this you should configure your machine so that you
  38.   can telnet in and out of it, and make successfully make all kinds of
  39.   connections to the net, and you should especially be able to do telnet
  40.   127.0.0.1 and get your own machine.  You also need a good
  41.   /etc/host.conf, /etc/resolv.conf and /etc/hosts files as a starting
  42.   point, since I will not explain their function here.  If you don't
  43.   already have all this set up and working the networking/NET-2 HOWTO
  44.   explains how to set it up.  Read it.
  45.  
  46.   If you're using SLIP or PPP you need that working.  Read the PPP HOWTO
  47.   if it's not.
  48.  
  49.   When I say `your machine' I mean the machine you are trying to set up
  50.   DNS on.  Not any other machine you might have that's involved in your
  51.   networking effort.
  52.  
  53.   I assume you're not behind any kind of firewall that blocks name
  54.   queries.  If you are you will need a special configuration, see the
  55.   section on ``firewalls and other peculiar net things''.
  56.   Name serving on Unix is done by a program called named.  This is a
  57.   part of the bind package which is coordinated by Paul Vixie for The
  58.   Internet Software Consortium.  Named is included in most Linux
  59.   distributions and is usually installed as /usr/sbin/named.  If you
  60.   have a named you can probably use it; if you don't have one you can
  61.   get a binary off a Linux ftp site, or get the latest and greatest
  62.   source from ftp.vix.com:/pub/bind in either the release or testing
  63.   subdirectory, whatever fits your lifestyle best.
  64.  
  65.   DNS is a net-wide database.  Take care about what you put into it.  If
  66.   you put junk into it, you, and others will get junk out of it.  Keep
  67.   your DNS tidy and consistent and you will get good service from it.
  68.   Learn to use it, admin it, debug it and you will be another good admin
  69.   keeping the net from falling to it's knees overloaded by
  70.   mismanagement.
  71.  
  72.   In this document I state flatly a couple of things that are not
  73.   completely true (they are at least half truths though).  All in the
  74.   interest of simplification.  Things will probably work if you believe
  75.   what I say.
  76.  
  77.   Tip: Make backup copies of all the files I instruct you to change if
  78.   you already have them, so if after going through this nothing works
  79.   you can get it back to your old, working state.
  80.  
  81.   2.  A caching only name server.
  82.  
  83.   A first stab at DNS config, very useful for dialup users.
  84.  
  85.   A caching only name server will find the answer to name queries and
  86.   remember the answer the next time you need it.
  87.  
  88.   First you need a file called /etc/named.boot.  This is read when named
  89.   starts.  For now it should simply contain:
  90.  
  91.   ______________________________________________________________________
  92.   ;  Boot file for nicolais caching name server
  93.   ;
  94.   directory /var/named
  95.   ;
  96.   ; type          domain                          source file or host
  97.   cache           .                               root.cache
  98.   primary         0.0.127.in-addr.arpa            pz/127.0.0
  99.   ______________________________________________________________________
  100.  
  101.   The `directory' line tells named where to look for files.  All files
  102.   named subsequently will be relative to this.  /var/named is the right
  103.   directory according to the Linux Filesystem Standard.  Personaly, I
  104.   use /local/named, but I'm quirky.
  105.  
  106.   The file named /var/named/root.cache is named in this.
  107.   /var/named/root.cache should contain this:
  108.  
  109.   ______________________________________________________________________
  110.    .       518400  NS      D.ROOT-SERVERS.NET.
  111.    .       518400  NS      E.ROOT-SERVERS.NET.
  112.    .       518400  NS      I.ROOT-SERVERS.NET.
  113.    .       518400  NS      F.ROOT-SERVERS.NET.
  114.    .       518400  NS      G.ROOT-SERVERS.NET.
  115.    .       518400  NS      A.ROOT-SERVERS.NET.
  116.    .       518400  NS      H.ROOT-SERVERS.NET.
  117.    .       518400  NS      B.ROOT-SERVERS.NET.
  118.    .       518400  NS      C.ROOT-SERVERS.NET.
  119.   ;
  120.   D.ROOT-SERVERS.NET.     3600000 A       128.8.10.90
  121.   E.ROOT-SERVERS.NET.     3600000 A       192.203.230.10
  122.   I.ROOT-SERVERS.NET.     3600000 A       192.36.148.17
  123.   F.ROOT-SERVERS.NET.     3600000 A       192.5.5.241
  124.   G.ROOT-SERVERS.NET.     3600000 A       192.112.36.4
  125.   A.ROOT-SERVERS.NET.     3600000 A       198.41.0.4
  126.   H.ROOT-SERVERS.NET.     3600000 A       128.63.2.53
  127.   B.ROOT-SERVERS.NET.     3600000 A       128.9.0.107
  128.   C.ROOT-SERVERS.NET.     3600000 A       192.33.4.12
  129.   ______________________________________________________________________
  130.  
  131.   The file describes the root name servers in the world.  This changes
  132.   over time and must be maintained.  See the ``maintenance section'' for
  133.   how to keep it up to date.  This file is described in the named man
  134.   page, but it is, IMHO, best suited for people that already understand
  135.   named.
  136.  
  137.   The next line in named.boot is the primary line.  I will explain its
  138.   use in a later chapter, for now just make this a file named 127.0.0 in
  139.   the subdirectory pz:
  140.  
  141.   ______________________________________________________________________
  142.   @               IN      SOA     linux.bogus. hostmaster.linux.bogus. (
  143.                                   1       ; Serial
  144.                                   28800   ; Refresh
  145.                                   7200    ; Retry
  146.                                   604800  ; Expire
  147.                                   86400)  ; Minimum TTL
  148.                           NS      ns.linux.bogus.
  149.   1                       PTR     localhost.
  150.   ______________________________________________________________________
  151.  
  152.   Next, you need a /etc/resolv.conf looking something like this:
  153.  
  154.   ______________________________________________________________________
  155.   search subdomain.your-domain.edu your-domain.edu
  156.   nameserver 127.0.0.1
  157.   ______________________________________________________________________
  158.  
  159.   The `search' line specifies what domains should be searched for any
  160.   hostnames you want to connect to.  The `nameserver' line specifies
  161.   what address your machine can reach a nameserver at, in this case your
  162.   own machine since that is where your named runs. (Note: Named never
  163.   reads this file, the resolver that uses named does.)
  164.   To illustrate what this file does: If a client tries to look up foo,
  165.   foo.subdomain.your-domain.edu is tried first, then foo.your-
  166.   fomain.edu, finally foo.  If a client tries to look up
  167.   sunsite.unc.edu, sunsite.unc.edu.subdomain.your-domain.edu is tried
  168.   first, then sunsite.unc.edu.your-domain.edu, and finally
  169.   sunsite.unc.edu.  You may not want to put in too many domains in the
  170.   search line, it takes time to search them.
  171.  
  172.   The example assumes you belong in the domain subdomain.your-
  173.   domain.edu, your machine then, is probably called your-
  174.   machine.subdomain.your-domain.edu.  The search line should not contain
  175.   your TLD (Top Level Domain, `edu' in this case).  If you frequently
  176.   need to connect to hosts in another domain you can add that domain to
  177.   the search line like this:
  178.  
  179.   ______________________________________________________________________
  180.   search subdomain.your-domain.edu. your-domain.edu. other-domain.com.
  181.   ______________________________________________________________________
  182.  
  183.   and so on. Obviously you need to put real domain names in instead.
  184.  
  185.   Next, depending on your libc version you either need to fix
  186.   /etc/nsswitch.conf or /etc/host.conf.  If you already have
  187.   nsswitch.conf that's what we'll fix, if not, we'll fix host.conf.
  188.  
  189.   /etc/nsswitch.conf
  190.  
  191.   This is a long file specifying where to get different kinds of data
  192.   types, from what file or database.  It usually contains helpful
  193.   comments at the top.  Find the line starting with `hosts:', it should
  194.   read
  195.  
  196.   ______________________________________________________________________
  197.   hosts:      files dns
  198.   ______________________________________________________________________
  199.  
  200.   If there is no line starting with `hosts:' then put in the one above.
  201.   It says that programs should first look in the /etc/hosts file, then
  202.   check DNS according to resolv.conf.
  203.  
  204.   /etc/host.conf
  205.  
  206.   It probably contains several lines, one should starting with order and
  207.   it should look like this:
  208.  
  209.   ______________________________________________________________________
  210.   order hosts,bind
  211.   ______________________________________________________________________
  212.  
  213.   If there is no `order' line you should stick one in.  It tells the
  214.   host name resolving routines to first look in /etc/hosts, then ask the
  215.   name server (which you in resolv.conf said is at 127.0.0.1) These two
  216.   latest files are documented in the resolv(8) manpage (do `man 8
  217.   resolv') in most Linux distributions.  That man page is IMHO readable,
  218.   and everyone, especially DNS admins, should read it.  Do it now, if
  219.   you say to yourself "I'll do it later" you'll never get around to it.
  220.  
  221.   Starting named.
  222.  
  223.   After all this it's time to start named.  If you're using a dialup
  224.   connection connect first.  Type `ndc start', and press return, no
  225.   options.  If that back-fires try `/usr/sbin/ndc start' instead.  Now
  226.   you can test your setup.  If you view your syslog message file
  227.   (usually called /var/adm/messages) while starting named (do tail -f
  228.   /var/adm/messages) you should see something like:
  229.  
  230.        Jun 30 21:50:55 roke named[2258]: starting.  named 4.9.4-REL Sun Jun 30 21:29:0
  231.        3 MET DST 1996   janl@roke.slip.ifi.uio.no:/var/tmp/bind/named
  232.        Jun 30 21:50:55 roke named[2258]: cache zone "" loaded (serial 0)
  233.        Jun 30 21:50:55 roke named[2258]: primary zone "0.0.127.in-addr.arpa" loaded (s
  234.        erial 1)
  235.  
  236.   If there are any messages about errors then there is a mistake named
  237.   will name the file it is in (one of named.boot and root.cache I hope
  238.   :-) Kill named and go back and check the named file.
  239.  
  240.        $ nslookup
  241.        Default Server:  localhost
  242.        Address:  127.0.0.1
  243.  
  244.        >
  245.  
  246.   If that's what you get it's working.  We hope.  Anything else, go back
  247.   and check everything.  Each time you change the named.boot file you
  248.   need to restart named using the ndc restart command.
  249.  
  250.   Now you can enter a query.  Try looking up some machine close to you.
  251.   pat.uio.no is close to me, at the University of Oslo:
  252.  
  253.        > pat.uio.no
  254.        Server:  localhost
  255.        Address:  127.0.0.1
  256.  
  257.        Name:    pat.uio.no
  258.        Address:  129.240.2.50
  259.  
  260.   nslookup now asked your named to look for the machine pat.uio.no.  It
  261.   then contacted one of the name server machines named in your
  262.   root.cache file, and asked its way from there.  It might take tiny
  263.   while before you get the result as it searches all the domains you
  264.   named in /etc/resolv.conf.
  265.  
  266.   If you try again you get this:
  267.  
  268.        > pat.uio.no
  269.        Server:  localhost
  270.        Address:  127.0.0.1
  271.  
  272.        Non-authoritative answer:
  273.        Name:    pat.uio.no
  274.        Address:  129.240.2.50
  275.  
  276.   Note the `Non-authoritative answer:' line we got this time around.
  277.   That means that named did not go out on the network to ask this time,
  278.   it instead looked in it's cache and found it there.  But the cached
  279.   information might be out of date (stale).  So you are informed of this
  280.   (very slight) danger by it saying `Non-authorative answer:'.  When
  281.   nslookup says this the second time you ask for a host it's a sure sign
  282.   it named caches the information and that it's working.  You exit
  283.   nslookup by giving the command `exit'.
  284.  
  285.   If you're a dialup (ppp, slip) user please read the ``section on
  286.   dialup connections'', there is some advice there for you.
  287.  
  288.   Now you know how to set up a caching named.  Take a beer, milk, or
  289.   whatever you prefer to celebrate it.
  290.  
  291.   3.  A simple domain.
  292.  
  293.   How to set up your own domain.
  294.  
  295.   Before we really start this section I'm going to serve you some theory
  296.   on how DNS works.  And you're going to read it because it's good for
  297.   you.  If you don't `wanna' you should at least skim it very quickly.
  298.   Stop skimming when you get to what should go in your named.boot file.
  299.  
  300.   DNS is a hierarchical system.  The top is written `.' and pronounced
  301.   `root'.  Under . there are a number of Top Level Domains (TLDs), the
  302.   best known ones are ORG, COM, EDU and NET, but there are many.  When
  303.   you want to find out the address of prep.ai.mit.edu your name server
  304.   has to find a name server that serves edu.  It asks a root.cache file
  305.   is for), the . server gives a list of edu servers.  I'll illustrate
  306.   this here:
  307.  
  308.        $ nslookup
  309.        Default Server:  localhost
  310.        Address:  127.0.0.1
  311.  
  312.   Start asking a root server.
  313.  
  314.        > server c.root-servers.net.
  315.        Default Server:  c.root-servers.net
  316.        Address:  192.33.4.12
  317.  
  318.   Set the Query type to NS (name server records).
  319.  
  320.        > set q=ns
  321.  
  322.   Ask about edu.
  323.  
  324.        > edu.
  325.  
  326.   The trailing . here is significant, it tells the server we're asking
  327.   that edu is right under ., this narrows the search somewhat.
  328.  
  329.        edu     nameserver = A.ROOT-SERVERS.NET
  330.        edu     nameserver = H.ROOT-SERVERS.NET
  331.        edu     nameserver = B.ROOT-SERVERS.NET
  332.        edu     nameserver = C.ROOT-SERVERS.NET
  333.        edu     nameserver = D.ROOT-SERVERS.NET
  334.        edu     nameserver = E.ROOT-SERVERS.NET
  335.        edu     nameserver = I.ROOT-SERVERS.NET
  336.        edu     nameserver = F.ROOT-SERVERS.NET
  337.        edu     nameserver = G.ROOT-SERVERS.NET
  338.        A.ROOT-SERVERS.NET      internet address = 198.41.0.4
  339.        H.ROOT-SERVERS.NET      internet address = 128.63.2.53
  340.        B.ROOT-SERVERS.NET      internet address = 128.9.0.107
  341.        C.ROOT-SERVERS.NET      internet address = 192.33.4.12
  342.        D.ROOT-SERVERS.NET      internet address = 128.8.10.90
  343.        E.ROOT-SERVERS.NET      internet address = 192.203.230.10
  344.        I.ROOT-SERVERS.NET      internet address = 192.36.148.17
  345.        F.ROOT-SERVERS.NET      internet address = 192.5.5.241
  346.        G.ROOT-SERVERS.NET      internet address = 192.112.36.4
  347.  
  348.   This tells us that *.root-servers.net serves edu., so we can go on
  349.   asking c.  Now we want to know who serves the next level of the domain
  350.   name: mit.edu.:
  351.  
  352.   > mit.edu.
  353.   Server:  c.root-servers.net
  354.   Address:  192.33.4.12
  355.  
  356.   Non-authoritative answer:
  357.   mit.edu nameserver = STRAWB.mit.edu
  358.   mit.edu nameserver = W20NS.mit.edu
  359.   mit.edu nameserver = BITSY.mit.edu
  360.  
  361.   Authoritative answers can be found from:
  362.   STRAWB.mit.edu  internet address = 18.71.0.151
  363.   W20NS.mit.edu   internet address = 18.70.0.160
  364.   BITSY.mit.edu   internet address = 18.72.0.3
  365.  
  366.   steawb, w20ns and bitsy serves mit, select one and inquire about
  367.   ai.mit.edu:
  368.  
  369.        > server W20NS.mit.edu.
  370.  
  371.   Hostnames are not case sensitive, but I use my mouse to cut and paste
  372.   so it gets copied as-is from the screen.
  373.  
  374.        Server:  W20NS.mit.edu
  375.        Address:  18.70.0.160
  376.  
  377.        > ai.mit.edu.
  378.        Server:  W20NS.mit.edu
  379.        Address:  18.70.0.160
  380.  
  381.        Non-authoritative answer:
  382.        ai.mit.edu      nameserver = WHEATIES.AI.MIT.EDU
  383.        ai.mit.edu      nameserver = ALPHA-BITS.AI.MIT.EDU
  384.        ai.mit.edu      nameserver = GRAPE-NUTS.AI.MIT.EDU
  385.        ai.mit.edu      nameserver = TRIX.AI.MIT.EDU
  386.        ai.mit.edu      nameserver = MUESLI.AI.MIT.EDU
  387.  
  388.        Authoritative answers can be found from:
  389.        AI.MIT.EDU      nameserver = WHEATIES.AI.MIT.EDU
  390.        AI.MIT.EDU      nameserver = ALPHA-BITS.AI.MIT.EDU
  391.        AI.MIT.EDU      nameserver = GRAPE-NUTS.AI.MIT.EDU
  392.        AI.MIT.EDU      nameserver = TRIX.AI.MIT.EDU
  393.        AI.MIT.EDU      nameserver = MUESLI.AI.MIT.EDU
  394.        WHEATIES.AI.MIT.EDU     internet address = 128.52.32.13
  395.        WHEATIES.AI.MIT.EDU     internet address = 128.52.35.13
  396.        ALPHA-BITS.AI.MIT.EDU   internet address = 128.52.32.5
  397.        ALPHA-BITS.AI.MIT.EDU   internet address = 128.52.37.5
  398.        GRAPE-NUTS.AI.MIT.EDU   internet address = 128.52.32.4
  399.        GRAPE-NUTS.AI.MIT.EDU   internet address = 128.52.36.4
  400.        TRIX.AI.MIT.EDU internet address = 128.52.32.6
  401.        TRIX.AI.MIT.EDU internet address = 128.52.38.6
  402.        MUESLI.AI.MIT.EDU       internet address = 128.52.32.7
  403.        MUESLI.AI.MIT.EDU       internet address = 128.52.39.7
  404.  
  405.   So weaties.ai.mit.edu is a nameserver for ai.mit.edu:
  406.  
  407.        > server WHEATIES.AI.MIT.EDU.
  408.        Default Server:  WHEATIES.AI.MIT.EDU
  409.        Addresses:  128.52.32.13, 128.52.35.13
  410.  
  411.   Now I change query type, we've found the name server so now we're
  412.   going to ask about everything wheaties knows about prep.ai.mit.edu.
  413.  
  414.        > set q=any
  415.        > prep.ai.mit.edu.
  416.        Server:  WHEATIES.AI.MIT.EDU
  417.        Addresses:  128.52.32.13, 128.52.35.13
  418.  
  419.        prep.ai.mit.edu CPU = dec/decstation-5000.25    OS = unix
  420.        prep.ai.mit.edu
  421.                inet address = 18.159.0.42, protocol = tcp
  422.                 #21 #23 #25 #79
  423.        prep.ai.mit.edu preference = 1, mail exchanger = life.ai.mit.edu
  424.        prep.ai.mit.edu internet address = 18.159.0.42
  425.        ai.mit.edu      nameserver = alpha-bits.ai.mit.edu
  426.        ai.mit.edu      nameserver = wheaties.ai.mit.edu
  427.        ai.mit.edu      nameserver = grape-nuts.ai.mit.edu
  428.        ai.mit.edu      nameserver = mini-wheats.ai.mit.edu
  429.        ai.mit.edu      nameserver = trix.ai.mit.edu
  430.        ai.mit.edu      nameserver = muesli.ai.mit.edu
  431.        ai.mit.edu      nameserver = count-chocula.ai.mit.edu
  432.        ai.mit.edu      nameserver = life.ai.mit.edu
  433.        ai.mit.edu      nameserver = mintaka.lcs.mit.edu
  434.        life.ai.mit.edu internet address = 128.52.32.80
  435.        alpha-bits.ai.mit.edu   internet address = 128.52.32.5
  436.        wheaties.ai.mit.edu     internet address = 128.52.35.13
  437.        wheaties.ai.mit.edu     internet address = 128.52.32.13
  438.        grape-nuts.ai.mit.edu   internet address = 128.52.36.4
  439.        grape-nuts.ai.mit.edu   internet address = 128.52.32.4
  440.        mini-wheats.ai.mit.edu  internet address = 128.52.32.11
  441.        mini-wheats.ai.mit.edu  internet address = 128.52.54.11
  442.        mintaka.lcs.mit.edu     internet address = 18.26.0.36
  443.  
  444.   So starting at . we found the successive nameservers for the next
  445.   level in the domain name.  If you had used your own DNS server instead
  446.   of using all those other servers, your named would of-course cache all
  447.   the information it found while digging this out for you, and it would
  448.   not have to ask again for a while.
  449.  
  450.   A much less talked about, but just as important domain is in-
  451.   addr.arpa.  It too is nested like the `normal' domains.  in-addr.arpa
  452.   allows us to get the hosts name when we have it's address.  A
  453.   important thing here is to note that ip#s are written in reverse order
  454.   in the in-addr.arpa domain.  If you have the address of a machine:
  455.   192.128.52.43 named procedes just like for the prep.ai.mit.edu
  456.   example: find arpa. servers.  Find in-addr.arpa. servers, find 192.in-
  457.   addr.arpa. servers, find 128.192.in-addr.arpa. servers, find
  458.   52.128.192.in-addr.arpa.  servers.  Find needed records for
  459.   43.52.128.192.in-addr.arpa.  Clever huh? (say `yes').  Also, the
  460.   reversion of the numbers is kinda confusing the first 2 years.
  461.  
  462.   I have just told a lie.  DNS does not work literally the way I just
  463.   told you.  But it's close enough.
  464.  
  465.   Our own doman.
  466.  
  467.   Now to define our own domain.  We're going to make the domain
  468.   linux.bogus and define machines in it.  I use a totally bogus domain
  469.   name to make sure we disturb no-one Out There.
  470.  
  471.   We've already started this part with this line in named.boot:
  472.  
  473.   ______________________________________________________________________
  474.   primary         0.0.127.in-addr.arpa            pz/127.0.0
  475.   ______________________________________________________________________
  476.  
  477.   Please note the lack of `.' at the end of the domain names in this
  478.   file.  The first line names the file pz/127.0.0 as defining
  479.   0.0.127.in-addr.arpa.  We've already set up this file, it reads:
  480.  
  481.   ______________________________________________________________________
  482.   @               IN      SOA     linux.bogus. hostmaster.linux.bogus. (
  483.                                   1       ; Serial
  484.                                   28800   ; Refresh
  485.                                   7200    ; Retry
  486.                                   604800  ; Expire
  487.                                   86400)  ; Minimum TTL
  488.                           NS      ns.linux.bogus.
  489.   1                       PTR     localhost.
  490.   ______________________________________________________________________
  491.  
  492.   Please note the `.' at the end of all the full domain names in this
  493.   file, in contrast to the named.boot file above.  Some people like to
  494.   start each zone file with a $ORIGIN directive, but this is
  495.   superfluous.  The origin (where in the DNS hierarchy it belongs) of a
  496.   zone file is specified in the `domain' column of the named.boot file,
  497.   in this case it's 0.0.127.in-addr.arpa.
  498.  
  499.   This `zone file' contains 3 `resource records' (RRs): A SOA RR.  A NS
  500.   RR and a PTR RR.  SOA is short for Start Of Authority.  The `@' is a
  501.   special notation meaning the origin, and since the `domain' column for
  502.   this file says 0.0.127.in-addr.arps the first line really says
  503.  
  504.          0.0.127.IN-ADDR.ARPA. IN      SOA ...
  505.  
  506.   NS is the Name Server RR, it tells DNS what machine is the name server
  507.   of the domain.  And finally the PTR record says that 1 (equals
  508.   1.0.0.127.IN-ADDR.ARPA, i.e. 127.0.0.1) is named localhost.
  509.  
  510.   The SOA record is the preamble to all zone files, and there should be
  511.   exactly one in each zone file, the very first record.  It describes
  512.   the zone, where it comes from (a machine called linux.bogus), who is
  513.   responsible for its contents (hostmaster@linux.bogus), what version of
  514.   the zone file this is (serial: 1), and other things having to do with
  515.   caching and secondary DNS servers.  For the rest of the fields
  516.   ,refresh, retry, expire and minimum use the numbers used in this HOWTO
  517.   and you should be safe.
  518.  
  519.   The NS record tells us who does DNS serving for 0.0.127.in-addr.arpa,
  520.   it is ns.linux.bogus.  The PTR record tells us that 1.0.0.127.in-
  521.   addr.arpa (aka 127.0.0.1) is known as localhost.
  522.  
  523.   Now restart your named (the command is ndc restart) and use nslookup
  524.   to examine what you've done:
  525.  
  526.        $ nslookup
  527.  
  528.        Default Server:  localhost
  529.        Address:  127.0.0.1
  530.  
  531.        > 127.0.0.1
  532.        Server:  localhost
  533.        Address:  127.0.0.1
  534.  
  535.        Name:    localhost
  536.        Address:  127.0.0.1
  537.  
  538.   so it manages to get localhost from 127.0.0.1, good.  Don't push it.
  539.   Now for our main task, the linux.bogus domain, insert a new primary
  540.   line in named.boot:
  541.  
  542.   ______________________________________________________________________
  543.   primary               linux.bogus                     pz/linux.bogus
  544.   ______________________________________________________________________
  545.  
  546.   Note the continued lack of ending `.' on the domain name in the
  547.   named.boot file.
  548.  
  549.   In the linux.bogus zone file we'll put some totally bogus data:
  550.  
  551.   ______________________________________________________________________
  552.   ;
  553.   ; Zone file for linux.bogus
  554.   ;
  555.   ; Mandatory minimum for a working domain
  556.   ;
  557.   @       IN      SOA     linux.bogus. hostmaster.linux.bogus. (
  558.                           199511301       ; serial, todays date + todays serial #
  559.                           28800           ; refresh, seconds
  560.                           7200            ; retry, seconds
  561.                           3600000         ; expire, seconds
  562.                           86400 )         ; minimum, seconds
  563.                   NS      ns.linux.bogus.
  564.                   NS      ns.friend.bogus.
  565.                   MX      10 mail.linux.bogus   ; Primary Mail Exchanger
  566.                   MX      20 mail.friend.bogus. ; Secondary Mail Exchanger
  567.  
  568.   localhost       A       127.0.0.1
  569.   ns              A       127.0.0.2
  570.   mail            A       127.0.0.4
  571.   ______________________________________________________________________
  572.  
  573.   There is one new RR type in this file, the MX, or Mail eXchanger RR.
  574.   It tells mail systems where to send mail that is addressed to
  575.   someone@linux.bogus, namely too mail.linux.bogus or mail.friend.bogus.
  576.   The number before each machine name is that MX RRs priority, The RR
  577.   with the lowest number (10) is the one mail should be sent to
  578.   primarily.  If that fails it can be sent to one with a higher number,
  579.   a secondary mail handler, i.e. mail.friend.bogus which has priority 20
  580.   here.
  581.  
  582.   Restart named by running ndc restart.  Examine the results with
  583.   nslookup:
  584.  
  585.        $ nslookup
  586.        > set q=any
  587.        > linux.bogus
  588.        Server:  localhost
  589.        Address:  127.0.0.1
  590.  
  591.        linux.bogus
  592.                origin = linux.bogus
  593.                mail addr = hostmaster.linux.bogus
  594.                serial = 199511301
  595.                refresh = 28800 (8 hours)
  596.                retry   = 7200 (2 hours)
  597.                expire  = 604800 (7 days)
  598.                minimum ttl = 86400 (1 day)
  599.        linux.bogus     nameserver = ns.linux.bogus
  600.        linux.bogus     nameserver = ns.friend.bogus
  601.        linux.bogus     preference = 10, mail exchanger = mail.linux.bogus.linux.bogus
  602.        linux.bogus     preference = 20, mail exchanger = mail.friend.bogus
  603.        linux.bogus     nameserver = ns.linux.bogus
  604.        linux.bogus     nameserver = ns.friend.bogus
  605.        ns.linux.bogus  internet address = 127.0.0.2
  606.        mail.linux.bogus        internet address = 127.0.0.4
  607.  
  608.   Upon careful examination you will discover a bug.  The line
  609.  
  610.          linux.bogus     preference = 10, mail exchanger = mail.linux.bogus.linux.bogu
  611.        s
  612.  
  613.   is all wrong.  It should be
  614.  
  615.          linux.bogus     preference = 10, mail exchanger = mail.linux.bogus
  616.  
  617.   I deliberately made a mistake so you could learn from it :-) Looking
  618.   in the zone file we find that the line
  619.  
  620.        @               MX      10 mail.linux.bogus     ; Primary Mail Exchanger
  621.  
  622.   is missing a period.  Or has a 'linux.bogus' too many.  If a machine
  623.   name does not end in a period in a zone file the origin is added to
  624.   it's end.  So either
  625.  
  626.   ______________________________________________________________________
  627.   @               MX      10 mail.linux.bogus.    ; Primary Mail Exchanger
  628.   ______________________________________________________________________
  629.  
  630.   or
  631.  
  632.   ______________________________________________________________________
  633.   @               MX      10 mail                 ; Primary Mail Exchanger
  634.   ______________________________________________________________________
  635.  
  636.   is correct.  I prefer the latter form, it's less to type.  In a zone
  637.   file the domain should either be written out and ended with a `.'  or
  638.   it should not be included at all, in which case it defaults to the
  639.   origin.  I must stress that in the named.boot file there should not be
  640.   `.'s after the domain names.  You have no idea how many times a `.'
  641.   too many or few have fouled up things and confused the h*ll out of
  642.   people.
  643.  
  644.   So having made my point here is the new zone file, with some extra
  645.   information in it as well:
  646.  
  647.   ______________________________________________________________________
  648.   ;
  649.   ; Zone file for linux.bogus
  650.   ;
  651.   ; Mandatory minimum for a working domain
  652.   ;
  653.   @       IN      SOA     linux.bogus. hostmaster.linux.bogus. (
  654.                           199511301       ; serial, todays date + todays serial #
  655.                           28800           ; refresh, seconds
  656.                           7200            ; retry, seconds
  657.                           604800          ; expire, seconds
  658.                           86400 )         ; minimum, seconds
  659.  
  660.                   NS      ns              ; Inet Address of name server
  661.                   NS      ns.friend.bogus.
  662.                   MX      10 mail         ; Primary Mail Exchanger
  663.                   MX      20 mail.friend.bogus. ; Secondary Mail Exchanger
  664.  
  665.   localhost       A       127.0.0.1
  666.   ns              A       127.0.0.2
  667.   mail            A       127.0.0.4
  668.   ;
  669.   ; Extras
  670.   ;
  671.   @               TXT     "Linux.Bogus, your DNS consultants"
  672.  
  673.   ns              MX      10 mail
  674.                   MX      20 mail.friend.bogus.
  675.                   HINFO   "Pentium" "Linux 1.2"
  676.                   TXT     "RMS"
  677.   richard         CNAME   ns
  678.   www             CNAME   ns
  679.  
  680.   donald          A       127.0.0.3
  681.                   MX      10 mail
  682.                   MX      20 mail.friend.bogus.
  683.                   HINFO   "i486"  "Linux 1.2"
  684.                   TXT     "DEK"
  685.  
  686.   mail            MX      10 mail
  687.                   MX      20 mail.friend.bogus.
  688.                   HINFO   "386sx" "Linux 1.0.9"
  689.  
  690.   ftp             A       127.0.0.5
  691.                   MX      10 mail
  692.                   MX      20 mail.friend.bogus.
  693.                   HINFO   "P6" "Linux 1.3.59"
  694.   ______________________________________________________________________
  695.  
  696.   You might want to move the first three A records so that they're
  697.   placed next to their respective other records, instead on top like
  698.   that.
  699.  
  700.   There are a number of new RRs here: HINFO (Host INFOrmation) has two
  701.   parts, it's a good habit to quote each.  The first part is the
  702.   hardware or CPU on the machine, and the second part the software or OS
  703.   on the machine.  ns has a Pentium CPU and runs Linux 1.2.  The TXT
  704.   record is a free text record that you can use for anything you like.
  705.   CNAME (Canonical NAME) is a way to give each machine several names.
  706.   So richard and www is a alias for ns.  It's important to note that A
  707.   MX, CNAME and SOA record should never refer to a CNAME record, they
  708.   should only refer to something with a A record, so it would wrong to
  709.   have
  710.  
  711.   ______________________________________________________________________
  712.   foobar  CNAME   richard                 ; NO!
  713.   ______________________________________________________________________
  714.  
  715.   but correct to have
  716.  
  717.   ______________________________________________________________________
  718.   foobar  CNAME   ns                      ; Yes!
  719.   ______________________________________________________________________
  720.  
  721.   It's also important to note that a CNAME is not a legal host name for
  722.   a e-mail address: webmaster@www.linux.bogus is an illegal e-mail
  723.   address given the setup above.  You can expect quite a few mail admins
  724.   Out There to enforce this rule even if it works for you.  The way to
  725.   avoid this is to use A records (and perhaps some others too, like a MX
  726.   record) instead:
  727.  
  728.   ______________________________________________________________________
  729.   www     A       127.0.0.2
  730.   ______________________________________________________________________
  731.  
  732.   Paul Vixie, the primary named wizard, recommends not using CNAME.  So
  733.   consider not using it very seriously.
  734.  
  735.   Load the new database by running ndc reload, this causes named to read
  736.   its files again.
  737.  
  738.        $ nslookup
  739.        Default Server:  localhost
  740.        Address:  127.0.0.1
  741.  
  742.        > ls -d linux.bogus
  743.  
  744.   This means that all records should be listed.
  745.  
  746.   [localhost]
  747.    linux.bogus.                   SOA   linux.bogus hostmaster.linux.bogus. (1995
  748.   11301 28800 7200 604800 86400)
  749.    linux.bogus.                   NS    ns.linux.bogus
  750.    linux.bogus.                   NS    ns.friend.bogus
  751.    linux.bogus.                   MX    10   mail.linux.bogus
  752.    linux.bogus.                   MX    20   mail.friend.bogus
  753.    linux.bogus.                   TXT   "Linux.Bogus, your DNS consultants"
  754.    localhost                      A     127.0.0.1
  755.    mail                           A     127.0.0.4
  756.    mail                           MX    10   mail.linux.bogus
  757.    mail                           MX    20   mail.friend.bogus
  758.    mail                           HINFO 386sx       Linux 1.0.9
  759.    donald                         A     127.0.0.3
  760.    donald                         MX    10   mail.linux.bogus
  761.    donald                         MX    20   mail.friend.bogus
  762.    donald                         HINFO i486        Linux 1.2
  763.    donald                         TXT   "DEK"
  764.    www                            CNAME ns.linux.bogus
  765.    richard                        CNAME ns.linux.bogus
  766.    ftp                            A     127.0.0.5
  767.    ftp                            MX    10   mail.linux.bogus
  768.    ftp                            MX    20   mail.friend.bogus
  769.    ftp                            HINFO P6          Linux 1.3.59
  770.    ns                             A     127.0.0.2
  771.    ns                             MX    10   mail.linux.bogus
  772.    ns                             MX    20   mail.friend.bogus
  773.    ns                             HINFO Pentium     Linux 1.2
  774.    ns                             TXT   "RMS"
  775.    linux.bogus.                   SOA   linux.bogus hostmaster.linux.bogus. (1995
  776.   11301 28800 7200 604800 86400)
  777.  
  778.   That's good.  Let's check what it says for www alone:
  779.  
  780.        > set q=any
  781.        > www.linux.bogus.
  782.        Server:  localhost
  783.        Address:  127.0.0.1
  784.  
  785.        www.linux.bogus canonical name = ns.linux.bogus
  786.  
  787.   ns.linux.bogus
  788.  
  789.        linux.bogus     nameserver = ns.linux.bogus
  790.        linux.bogus     nameserver = ns.friend.bogus
  791.        ns.linux.bogus  internet address = 127.0.0.2
  792.  
  793.   and ns.linux.bogus has the address 127.0.0.2.  Looks good too.
  794.  
  795.   Winding down
  796.  
  797.   Of course, this domain is highly bogus, and so are all the addresses
  798.   in it.  For a real domain insert the real domain names and addresses
  799.   and all the other information.  When that is done you need a reverse
  800.   lookup zone file, it should be like the 127.0.0 file and contain
  801.   exactly one PTR RR for each address in use, i.e.
  802.  
  803.        127.0.0.2       PTR     ns.linux.bogus.
  804.        127.0.0.3       PTR     donald.linux.bogus.
  805.        127.0.0.4       PTR     mail.linux.bogus.
  806.        127.0.0.5       PTR     ftp.linux.bogus.
  807.  
  808.   for our example domain (in addition to the SOA RR of-course).  The
  809.   domain name (origin) of the file should be reversed just as with
  810.   127.0.0 versus 0.0.127.in-addr.arpa.
  811.  
  812.   Now it's time for you to play around with things and set up your
  813.   domain.  When you've finished playing with the linux.bogus domain
  814.   remove it from your named.boot file.
  815.  
  816.   4.  Firewalls and other odd things.
  817.  
  818.   Q: How do use DNS from inside a firewall? A: A couple of hints:
  819.   `forwarders', `slave', and have a look in the literature list at the
  820.   end of this HOWTO.
  821.  
  822.   Q: How do I make DNS rotate through the available addresses for a
  823.   service, say www.busy.site to obtain a load balancing effect, or
  824.   similar? A: Make several A records for www.busy.site and bind 4.9.3 or
  825.   later will round-robin the answers.  It will not work with earlier
  826.   versions of bind.
  827.  
  828.   5.  Maintenance
  829.  
  830.   Keeping it working.
  831.  
  832.   There is one maintenance task you have to do on nameds, other than
  833.   keeping them running.  That's keeping the root.cache file updated.
  834.   The easiest way is using dig, first run dig with no arguments, you
  835.   will get the root.cache according to your own server.  Then ask one of
  836.   the listed root servers with dig @rootserver.  You will note that the
  837.   output looks terribly like a root.cache file except for a couple of
  838.   extra numbers.  Those numbers are harmless.  Save it to a file (dig .
  839.   @e.root-servers.net >root.cache.new) and replace the old root.cache
  840.   with it.
  841.  
  842.   Remember to restart named after replacing the cache file.
  843.  
  844.   Al Longyear sent me this script that can be run automatically to
  845.   update named.cache, install it a crontab entry for it and forget it.
  846.   The script assumes you have mail working and that the mail-alias
  847.   `hostmaster' is defined.  You should hack it to suit your setup.
  848.  
  849.   ______________________________________________________________________
  850.   #!/bin/sh
  851.   #
  852.   # Update the nameserver cache information file once per month.
  853.   # This is run automatically by a cron entry.
  854.   #
  855.   (
  856.    echo "To: hostmaster <hostmaster>"
  857.    echo "From: system <root>"
  858.    echo "Subject: Automatic update of the named.boot file"
  859.    echo
  860.  
  861.    export PATH=/sbin:/usr/sbin:/bin:/usr/bin:
  862.    cd /var/named
  863.  
  864.    dig . @rs.internic.net >named.cache.new
  865.  
  866.    echo "The named.boot file has been updated to contain the following
  867.   information:"
  868.    echo
  869.    cat named.boot.new
  870.  
  871.    chown root.root named.cache.new
  872.    chmod 444 named.cache.new
  873.    rm -f named.cache.old
  874.    mv named.cache named.cache.old
  875.    mv named.cache.new named.cache
  876.    ndc restart
  877.    echo
  878.    echo "The nameserver has been restarted to ensure that the update is complete.
  879.   "
  880.    echo "The previous named.cache file is now called
  881.   /var/named/named.cache.old."
  882.   ) 2>&1 | /usr/lib/sendmail -t
  883.   exit 0
  884.   ______________________________________________________________________
  885.  
  886.   6.  Automatic setup for dialup connections.
  887.  
  888.   This section explains how I have set things up to automate everything.
  889.   My way might not suit you at all, but you might get a idea from
  890.   something I've done.  Also, I use ppp for dialup, while many use slip
  891.   or cslip, so almost everything in your setup can be different from
  892.   mine.  But slip's dip program should be able to do many of the things
  893.   I do.
  894.  
  895.   Normally, when I'm not connected to the net I have a resolv.conf file
  896.   simply containing the line
  897.  
  898.        domain uio.no
  899.  
  900.   This ensures I don't have to wait for the hostname resolving library
  901.   to try to connect to a nameserver that can't help me.  But when I
  902.   connect I want to start my named and have a resolv.conf looking like
  903.   the one described above.  I have solved this by keeping two
  904.   resolv.conf 'template' files named resolv.conf.local and
  905.   resolv.conf.connected.  The latter looks like the resolv.conf
  906.   described before in this document.
  907.  
  908.   To automatically connect to the net I run a script called 'ppp-on':
  909.  
  910.   ______________________________________________________________________
  911.   #!/bin/sh
  912.   echo calling...
  913.   pppd
  914.   ______________________________________________________________________
  915.  
  916.   pppd has a file called options that tells it the particulars of how to
  917.   get connected.  Once my ppp connection is up the pppd starts a script
  918.   called ip-up (this is described in the pppd man page).  This is parts
  919.   of the script:
  920.  
  921.   ______________________________________________________________________
  922.   #!/bin/sh
  923.   interface="$1"
  924.   device="$2"
  925.   speed="$3"
  926.   myip="$4"
  927.   upip="$5"
  928.    ...
  929.   cp -v /etc/resolv.conf.connected /etc/resolv.conf
  930.    ...
  931.   /usr/sbin/named
  932.   ______________________________________________________________________
  933.  
  934.   I.e. I start my named there.  When ppp is disconnected pppd runs a
  935.   script called ip-down:
  936.  
  937.   ______________________________________________________________________
  938.   #!/bin/sh
  939.   cp /etc/resolv.conf.local /etc/resolv.conf
  940.   read namedpid </var/run/named.pid
  941.   kill $namedpid
  942.   ______________________________________________________________________
  943.  
  944.   So this gets things configured and up when connecting and Dis-
  945.   configured and down when disconnecting.
  946.  
  947.   Some programs, irc and talk come to mind, make a few too many
  948.   assumptions, and for irc the dcc features and talk to work right you
  949.   have to fix your hosts file.  I insert have this in my ip-up script:
  950.  
  951.   ______________________________________________________________________
  952.   cp /etc/hosts.ppp /etc/hosts
  953.   echo $myip      roke >>/etc/hosts
  954.   ______________________________________________________________________
  955.  
  956.   hosts.ppp simply contains
  957.  
  958.   ______________________________________________________________________
  959.   127.0.0.1       localhost
  960.   ______________________________________________________________________
  961.  
  962.   and the echo thing inserts the ip# i have received for my host name
  963.   (roke).  You should use the name your host knows itself by instead.
  964.   This can be found with the hostname command.
  965.  
  966.   It is probably not smart to run named when you are not connected to
  967.   the net, this is because named will try to send queries to the net and
  968.   it has a long timeout, and you have to wait for this timeout every
  969.   time some program tries to resolve a name.  If you're using dialup you
  970.   should start named when connecting and kill it when disconnecting.  I
  971.   have received mail saying it isn't so, but I have not been able to
  972.   make it work having to wait for long timeouts.  Please mail all
  973.   details if you have better information.
  974.  
  975.   Some people like to use a forwarders directive on slow connections.
  976.   If your internet provider has DNS servers at 1.2.3.4 and 1.2.3.5 you
  977.   can insert the line
  978.  
  979.   ______________________________________________________________________
  980.   forwarders 1.2.3.4 1.2.3.5
  981.   ______________________________________________________________________
  982.  
  983.   in the named.boot file.  Also leave the named.cache file empty.  That
  984.   will decrease the amount of IP traffic your host originates, any
  985.   possibly speed things up.  This especially important if you're paying
  986.   pr. byte that goes over the wire.  This has the added value of letting
  987.   you off the one maintenance duty you have as a caching named
  988.   maintainer: you don't have to update a empty named.cache file.
  989.  
  990.   7.  How to become a bigger time DNS admin.
  991.  
  992.   Documentation and tools.
  993.  
  994.   Real Documentation exists.  Online and in print.  The reading of
  995.   several of these is required to make the step from small time DNS
  996.   admin to a big time one.  In print the standard book is DNS and BIND
  997.   by C. Liu and P. Albitz from O'Reilly & Associates, Sebastopol, CA,
  998.   ISBN 0-937175-82-X.  I read this, it's excellent.  There is also a
  999.   section in on DNS in TCP/IP Network Administration, by Craig Hunt from
  1000.   O'Reilly..., ISBN 0-937175-82-X.  Another must for Good DNS
  1001.   administration (or good anything for that matter) is Zen and the Art
  1002.   of Motorcycle Maintenance by Robert M. Prisig :-) Available as ISBN
  1003.   0688052304 and others.
  1004.  
  1005.   Online you will find stuff on  <http://www.dns.net/dnsrd/>,
  1006.   <http://www.vix.com/isc/bind.html>; A FAQ, a reference manual (BOG;
  1007.   Bind Operations Guide) as well as papers and protocol definitions and
  1008.   DNS hacks.  I have not read most of these, but then I'm not a big-time
  1009.   DNS admin either.  Arnt Gulbrandsen on the other hand has read BOG and
  1010.   he's extatic about it :-).  The newsgroup comp.protocols.tcp-
  1011.   ip.domains is about DNS.  In addition there are a number of RFCs about
  1012.   DNS, the most important are probably these:
  1013.  
  1014.      RFC 1918
  1015.         Y. Rekhter, R. Moskowitz, D. Karrenberg, G. de Groot, E. Lear,
  1016.         Address Allocation for Private Internets, 02/29/1996.
  1017.  
  1018.      RFC 1912
  1019.         D. Barr, Common DNS Operational and Configuration Errors,
  1020.         02/28/1996.
  1021.  
  1022.      RFC 1713
  1023.         A. Romao, Tools for DNS debugging, 11/03/1994.
  1024.  
  1025.      RFC 1712
  1026.         C. Farrell, M. Schulze, S. Pleitner, D. Baldoni, DNS Encoding of
  1027.         Geographical Location, 11/01/1994.
  1028.  
  1029.      RFC 1183
  1030.         R. Ullmann, P. Mockapetris, L. Mamakos, C. Everhart, New DNS RR
  1031.         Definitions, 10/08/1990.
  1032.  
  1033.      RFC 1035
  1034.         P. Mockapetris, Domain names - implementation and specification,
  1035.         11/01/1987.
  1036.  
  1037.      RFC 1034
  1038.         P. Mockapetris, Domain names - concepts and facilities,
  1039.         11/01/1987.
  1040.  
  1041.      RFC 1033
  1042.         M. Lottor, Domain administrators operations guide, 11/01/1987.
  1043.  
  1044.      RFC 1032
  1045.         M. Stahl, Domain administrators guide, 11/01/1987.
  1046.  
  1047.      RFC 974
  1048.         C. Partridge, Mail routing and the domain system, 01/01/1986.
  1049.  
  1050.