home *** CD-ROM | disk | FTP | other *** search
/ Caldera Network Desktop 1.0 / caldera-network-desktop-1.0.bin / doc / HOWTO / mini / Caching-named < prev    next >
Text File  |  1995-11-30  |  16KB  |  433 lines

  1. Caching named mini howto.
  2.  
  3. Version 1.1
  4.  
  5. (C)opyright 1995 Nicolai Langfeldt.  Do not modify without amending
  6. copyright, distribute freely but retain copyright message.
  7.  
  8. Please send money, comments and/or questions to janl@ifi.uio.no.
  9.  
  10. I would appreciate it if someone sent me a section 3 for (c)slip
  11. users.
  12.  
  13. Contents:
  14. 1. Introduction
  15. 2. Setting it up
  16. 3. Automatic setup when connecting (and disconnecting).
  17. 4. Getting a new root.cache file.
  18. 5. Of forwarders and slaves.
  19.  
  20. 1. Introduction
  21.  
  22. This mini howto describes how to set up set up a caching name server.
  23. This is primarily usefull for people connected to the net with a
  24. (dialup) modem, using SLIP, PPP and similar protocols, because name
  25. lookups can be slow due to the slownes of modem comunications.
  26.  
  27. A clearification: When I say 'your machine' I mean the macine you dial
  28. up to the net from, for most people this is their home machine.  There
  29. is room for confusion because quite a few people dial up to their own
  30. internet connected machine at work, _that_ is not the machine I talk
  31. of in this howto, I talk about the machine you call up from, the one
  32. you connect to the net with a modem.
  33.  
  34. Before you start on this you should configure your machine so that you
  35. can telnet in and out of it, and make successfuly make all kinds of
  36. connections to the net, and you should be able to do 'telnet
  37. 127.0.0.1' and get your own machine. You also need good
  38. /etc/host.conf, /etc/resolve.conf and /etc/hosts files as a starting
  39. point.  If you don't already have all this set up and working the
  40. networking howto explains how to set it up.
  41.  
  42. I also assume you're not behind any kind of firewall that blocks name
  43. queries.  If you are you will need a special configuration that's
  44. mentioned in section 5.
  45.  
  46. Name serving on unix is done by a program called named.  This is a
  47. part of the bind package that's coordinated by Paul Vixie.  This can
  48. be gotten on Linux ftp sites, but chances are that you already have a
  49. named.  It's usualy called /usr/sbin/named.  You can use that if you
  50. already have it.
  51.  
  52. If you need to set up named for more than just caching, for example
  53. for setting up your own internet domain I sugest you get the book "DNS
  54. and BIND" by C. Liu and P. Albitz from O'Reilly & Associates,
  55. Sebastopol, CA, ISBN 0-937175-82-X 1992.  There are also docs in the
  56. bind distribution, including a FAQ and a manual as well as papers.
  57.  
  58. 2. Setting it up
  59.  
  60. Tip: Make backup copies of all the files I instruct you to change if
  61. you already have them, so if after going thru this nothing works you
  62. can get it back to your old, working state.
  63.  
  64. First you need a file called /etc/named.boot.  This is read when named
  65. starts.  For our purpose it should simply contain (remove leading
  66. spaces):
  67.  
  68.   ;  Boot file for nicolais caching name server
  69.   ;
  70.   directory /var/named
  71.   ;
  72.   ; type          domian                          source file or host
  73.   cache           .                               root.cache
  74.  
  75. A file named /var/named/root.cache is named in this.
  76. /var/named/root.cache should contain this (remove leading spaces
  77. again):
  78.  
  79.   ; ---- Root hint cache dump ----
  80.   .    IN    NS    A.ROOT-SERVERS.NET
  81.   .    IN    NS    B.ROOT-SERVERS.NET
  82.   .    IN    NS    C.ROOT-SERVERS.NET
  83.   .    IN    NS    D.ROOT-SERVERS.NET
  84.   .    IN    NS    E.ROOT-SERVERS.NET
  85.   .    IN    NS    F.ROOT-SERVERS.NET
  86.   .    IN    NS    G.ROOT-SERVERS.NET
  87.   .    IN    NS    H.ROOT-SERVERS.NET
  88.   .    IN    NS    I.ROOT-SERVERS.NET
  89.   ;
  90.   ;  Prep the cache (hotwire the addresses).  Order does not matter
  91.   ;
  92.   A.ROOT-SERVERS.NET.    IN    A    198.41.0.4
  93.   B.ROOT-SERVERS.NET.    IN    A    128.9.0.107
  94.   C.ROOT-SERVERS.NET.    IN    A    192.33.4.12
  95.   D.ROOT-SERVERS.NET.    IN    A    128.8.10.90
  96.   E.ROOT-SERVERS.NET.    IN    A    192.203.230.10
  97.   F.ROOT-SERVERS.NET.    IN    A    39.13.229.241
  98.   G.ROOT-SERVERS.NET.    IN    A    192.112.36.4
  99.   H.ROOT-SERVERS.NET.    IN    A    128.63.2.53
  100.   I.ROOT-SERVERS.NET.    IN    A    192.36.148.17
  101.  
  102. It describes the root name servers in the world.  This changes over
  103. time, see below for how to get updated data.
  104.  
  105. These two files are supposedly described in the named man page.  I say
  106. supposedly because that man page is probably one of the least clear
  107. man pages in creation if you don't already know how to set up named.
  108.  
  109. Next, when you're connected to the net you need a /etc/resolv.conf
  110. looking like this:
  111.  
  112.   search subdomain.your-domain.edu your-domain.edu
  113.   nameserver 127.0.0.1
  114.  
  115. The 'search' line specifies what domains should be searched for any
  116. hostnames want to connect to.  The 'nameserver' line specifies what
  117. address your machine can reach a nameserver at, in this case your own
  118. machine since that is where your named runs.
  119.  
  120. The example assumes you belong in the domain
  121. subdomain.your-domain.edu, your machine then, is probably called
  122. your-machine.subdomain.your-domain.edu.  The search line would
  123. normaly not contain your top domain ('edu' in this case).  If you
  124. frequently need to connect to hosts in another domain you can add that
  125. domain to the search line like this:
  126.  
  127.   search subdomain.your-domain.edu your-domain.edu other-domain.com
  128.  
  129. and so on. Obviosly you need to put real domain names in instead.
  130.  
  131. The last file you have to fix is /etc/host.conf.  There should be a
  132. line starting with 'order' and it should look like this:
  133.  
  134.   order hosts,bind
  135.  
  136. If there is no order line you should stick one in.  It tells the host
  137. name resolving routinges to first look in /etc/hosts, then ask the
  138. name server (which you in resolve.conf said is at 127.0.0.1)
  139.  
  140. These two latest files are documented in the resolv(8) manpage (do
  141. 'man 8 resolv').  That man page is IMHO readable, and everyone should
  142. read it.
  143.  
  144. Now you can connect to the world and test your setup.  Dial up and
  145. establish your connection the usual way.  Once the connection is
  146. established (and /etc/resolve.conf has the right 'nameserver' line)
  147. you start /usr/sbin/named.  If you look in your syslog message file
  148. (usualy called /var/adm/messages, use the command 'tail
  149. /var/adm/messages' to see it's end) after you start named you should
  150. see something like:
  151.  
  152.   Jan 14 23:13:14 roke named[671]: starting.  named 4.9.3-BETA9 Sat Jan 14 21:19:55 MET 1995    janl@roke:/usr/src/bind-4.9.3-BETA9/named
  153.   Jan 14 23:13:14 roke named[672]: Ready to answer queries. 
  154.  
  155. If there is any messages about errors then there is a mistake
  156. somewhere in the file named named in the message (one of named.boot
  157. and root.cache I hope :-) Kill named and go back and check the files.
  158.  
  159. Once named does not complain you can start querying it.  The program
  160. designed for this is nslookup. Start it by giving linux the command
  161. 'nslookup':
  162.  
  163.   $ nslookup
  164.   Default Server:  localhost
  165.   Address:  127.0.0.1
  166.  
  167.   > 
  168.  
  169. If it does not say 'localhost' and '127.0.0.1' there is something
  170. wrong in resolv.conf, go back and check it.
  171.  
  172. Now you can enter a query.  Try looking up some machine close to you.
  173. mnemosyne.uio.no is a Linux machine I run at the university of Oslo:
  174.  
  175.   > mnemosyne.uio.no
  176.   Server:  localhost
  177.   Address:  127.0.0.1
  178.  
  179.   Name:    mnemosyne.uio.no
  180.   Address:  129.240.21.233
  181.  
  182. nslookup now asked your named to look for the machine
  183. mnemosyne.uio.no.  It then contacted one of the name server machines
  184. named in your root.cache file, and asked it's way from there.  It
  185. might take some seconds before you get the result as it searches all
  186. the domains you named in /etc/resolve.conf.  If you try again you get
  187. this:
  188.  
  189.   > mnemosyne.uio.no
  190.   Server:  localhost
  191.   Address:  127.0.0.1
  192.  
  193.   Non-authoritative answer:
  194.   Name:    mnemosyne.uio.no
  195.   Address:  129.240.21.233
  196.  
  197. Note 'Non-authoritative answer:'.  That means that named did not go
  198. out on the network to ask this time, it instead looked in it's cache
  199. and found it there.  But the cached information _might_ be out of date
  200. (also called 'stale').  So you are informed of this by it saying
  201. 'Non-authorative answer:'.  So when nslookup says this the second time
  202. you ask for a host it's a sign it caches the information and the
  203. desired effect of setting up the named has been reached. You exit
  204. nslookup by giving the command 'exit'.
  205.  
  206. A warning: It is not smart to run named when you are not connected to
  207. the net, this is because named will try to send queries to the net and
  208. it has a long timeout, and you have to wait for this timeout every
  209. time some program tries to resolve a name.  The next section explains
  210. how I deal with seting up and taking down named when connecting and
  211. disconnecting to the net.
  212.  
  213. So now you know how to set up the different configuration files so
  214. named works.
  215.  
  216. 3. Automatic setup when connecting (and disconnecting).
  217.  
  218. This section explains how I have set things up to automate everything.
  219. My way might not suit you at all, but you might get a idea from
  220. something I've done.  Also, I use ppp for dialup, while many use slip
  221. or cslip, so almost everything in your setup can be different from
  222. mine. But slip's dip program should be able to do many of the things I
  223. do.
  224.  
  225. Normaly, when I'm not connected to the net I have a resolv.conf file
  226. simply containing the line
  227.  
  228.   domain uio.no
  229.  
  230. This ensures I don't have to wait for the hostname resolving library
  231. to try to connect to a nameserver that can't help me.  But when I
  232. connect I want to start my named and have a resolv.conf looking like
  233. the one described above.  I have solved this by keeping two
  234. resolv.conf 'template' files named resolv.conf.local and
  235. resolve.conf.connected.  The latter looks like the resolve.conf
  236. described before in this document.
  237.  
  238. To automaticaly connect to the net I run a script called 'ppp-on':
  239.  
  240.   #!/bin/sh
  241.   cp -v /etc/resolv.conf.connected /etc/resolv.conf
  242.   echo calling...
  243.   pppd
  244.  
  245. pppd has a file called 'options' that tells it the particulars of how
  246. to get connected.  Once my ppp connection is up the pppd starts a
  247. script called ip-up (this is described in the pppd man page).  This is
  248. parts of the script:
  249.  
  250.   #!/bin/sh
  251.   ...
  252.   echo 1>&2 PPP: IP up
  253.   ...
  254.   /usr/sbin/named
  255.   echo PPP: ip-up finished
  256.  
  257. I.e. I start my named there.  When ppp is disconnected pppd runs a
  258. script called ip-down:
  259.  
  260.   #!/bin/sh
  261.   echo 1>&2 PPP: IP down
  262.   cp /etc/resolv.conf.local /etc/resolv.conf
  263.   kill `cat /var/run/named.pid`
  264.  
  265. So this gets things configured and up when connecting and
  266. disconfigured and down when disconnecting.
  267.  
  268. It's also a good idea to insert
  269.  
  270.   cp /etc/resolv.conf.local /etc/resolv.conf
  271.  
  272. in your bootup scripts.  The best place is /etc/rc.d/rc.inet1 if you
  273. have it, if not in /etc/rc.d/rc.local or /etc/rc.local.
  274.  
  275. 4. Getting a new root.cache file.
  276.  
  277. I mentioned that the root.cache information changes from time to time.
  278. So you might want to update it once in a long while.  Start nslookup thus:
  279.  
  280.   nslookup | tee nslookup.log
  281.  
  282. then give the command
  283.  
  284.   > set type=ns
  285.  
  286. This means that nslookup should ask for 'ns' (or NameServer) records,
  287. it usualy asks for A, address records.
  288.  
  289.   > .
  290.  
  291. This means, get me root information.  In a unix filesystem the root
  292. is '/', in the name server system the root is '.' and is often written
  293. so.  The answer to my query was:
  294.  
  295.   Server:  localhost
  296.   Address:  127.0.0.1
  297.  
  298.   Non-authoritative answer:
  299.   (root)  nameserver = B.ROOT-SERVERS.NET
  300.   (root)  nameserver = C.ROOT-SERVERS.NET
  301.   (root)  nameserver = D.ROOT-SERVERS.NET
  302.   (root)  nameserver = E.ROOT-SERVERS.NET
  303.   (root)  nameserver = I.ROOT-SERVERS.NET
  304.   (root)  nameserver = F.ROOT-SERVERS.NET
  305.   (root)  nameserver = G.ROOT-SERVERS.NET
  306.   (root)  nameserver = A.ROOT-SERVERS.NET
  307.   (root)  nameserver = H.ROOT-SERVERS.NET
  308.  
  309.   Authoritative answers can be found from:
  310.   (root)  nameserver = B.ROOT-SERVERS.NET
  311.   (root)  nameserver = C.ROOT-SERVERS.NET
  312.   (root)  nameserver = D.ROOT-SERVERS.NET
  313.   (root)  nameserver = E.ROOT-SERVERS.NET
  314.   (root)  nameserver = I.ROOT-SERVERS.NET
  315.   (root)  nameserver = F.ROOT-SERVERS.NET
  316.   (root)  nameserver = G.ROOT-SERVERS.NET
  317.   (root)  nameserver = A.ROOT-SERVERS.NET
  318.   (root)  nameserver = H.ROOT-SERVERS.NET
  319.   B.ROOT-SERVERS.NET      internet address = 128.9.0.107
  320.   C.ROOT-SERVERS.NET      internet address = 192.33.4.12
  321.   D.ROOT-SERVERS.NET      internet address = 128.8.10.90
  322.   E.ROOT-SERVERS.NET      internet address = 192.203.230.10
  323.   I.ROOT-SERVERS.NET      internet address = 192.36.148.17
  324.   F.ROOT-SERVERS.NET      internet address = 39.13.229.241
  325.   G.ROOT-SERVERS.NET      internet address = 192.112.36.4
  326.   A.ROOT-SERVERS.NET      internet address = 198.41.0.4
  327.   H.ROOT-SERVERS.NET      internet address = 128.63.2.53
  328.  
  329. It says that the answer is non-authorative, and that an authorative
  330. answer can be gotten from one of a list of hosts.  We want a
  331. authorative answer so we tell nslookup to use one of the named
  332. servers.  I pick i.root-servers.net because everyone else probably use
  333. a :-) You can choose any you fancy.
  334.  
  335.   > server i.root-servers.net
  336.   Default Server:  i.root-servers.net
  337.   Address:  192.36.148.17
  338.  
  339. Now to ask for the root ns records again:
  340.  
  341.   > .
  342.   Server:  i.root-servers.net
  343.   Address:  192.36.148.17
  344.  
  345.   (root)  nameserver = H.ROOT-SERVERS.NET
  346.   (root)  nameserver = B.ROOT-SERVERS.NET
  347.   (root)  nameserver = C.ROOT-SERVERS.NET
  348.   (root)  nameserver = D.ROOT-SERVERS.NET
  349.   (root)  nameserver = E.ROOT-SERVERS.NET
  350.   (root)  nameserver = I.ROOT-SERVERS.NET
  351.   (root)  nameserver = F.ROOT-SERVERS.NET
  352.   (root)  nameserver = G.ROOT-SERVERS.NET
  353.   (root)  nameserver = A.ROOT-SERVERS.NET
  354.   (root)  nameserver = H.ROOT-SERVERS.NET
  355.   (root)  nameserver = B.ROOT-SERVERS.NET
  356.   (root)  nameserver = C.ROOT-SERVERS.NET
  357.   (root)  nameserver = D.ROOT-SERVERS.NET
  358.   (root)  nameserver = E.ROOT-SERVERS.NET
  359.   (root)  nameserver = I.ROOT-SERVERS.NET
  360.   (root)  nameserver = F.ROOT-SERVERS.NET
  361.   (root)  nameserver = G.ROOT-SERVERS.NET
  362.   (root)  nameserver = A.ROOT-SERVERS.NET
  363.   H.ROOT-SERVERS.NET      internet address = 128.63.2.53
  364.   B.ROOT-SERVERS.NET      internet address = 128.9.0.107
  365.   C.ROOT-SERVERS.NET      internet address = 192.33.4.12
  366.   D.ROOT-SERVERS.NET      internet address = 128.8.10.90
  367.   E.ROOT-SERVERS.NET      internet address = 192.203.230.10
  368.   I.ROOT-SERVERS.NET      internet address = 192.36.148.17
  369.   F.ROOT-SERVERS.NET      internet address = 39.13.229.241
  370.   G.ROOT-SERVERS.NET      internet address = 192.112.36.4
  371.   A.ROOT-SERVERS.NET      internet address = 198.41.0.4
  372.  
  373. Mission acomplished, quit nslookup:
  374.  
  375.   > exit
  376.  
  377. You now have the complete nslookup seesion log in a file called
  378. nslookup.log.  Start a editor and remove all but the results of the
  379. last query.  To make a named.cache file of the rest you change it in
  380. this manner:
  381.  
  382.   (root)  nameserver = H.ROOT-SERVERS.NET
  383.  
  384. should become
  385.  
  386.   .    IN    NS    H.ROOT-SERVERS.NET.
  387.  
  388. Note the _trailing_ '.', it's _very_ significant.  It specifies that
  389. net is a root domain, and should be there.  There need only be line
  390. for each name server, you can delete the duplicate ones.  Then you
  391. change lines on the form
  392.  
  393.   H.ROOT-SERVERS.NET    internet address = 128.63.2.53
  394.  
  395. to
  396.  
  397.   H.ROOT-SERVERS.NET.    999999    IN    A    128.63.2.53
  398.  
  399. Note the trailing '.' after 'NET' . again.  Then save the file again.
  400. If you examine the result of the edit and your /var/named/root.cache
  401. they should be remarkably alike, so this corresponds to the root.conf
  402. file.  Move the new file to /var/named/root.cache.  Now run
  403. /usr/sbin/named.restart and test your new setup by connecting to
  404.  
  405. 5. Of forwarders and slaves.
  406.  
  407. There are one or two enhancements you can make on this setup.  One
  408. involves asking other close by name servers if they have the name
  409. cached, thus (possebly, if we're lucky) avoiding having to wait for a
  410. reply from halfway across the globe.  You can't use _any_ close by
  411. nameserver for forwarding; it has to accept recursive queries (to
  412. quote the named manpage).  If you don't know any close-by forwarders
  413. ask your provider if they know any name servers you can use as
  414. forwarder.  In My Humble Opinion your provider should be be able to be
  415. your forward server.  Never, ever use another server as forwarder
  416. without the permission of it's admin, it's rude.
  417.  
  418. A forwarders line should be in the named.boot file, and looks like
  419. this (DO NOT USE THIS LINE, IT WILL NOT WORK! Use your local
  420. forwarders instead):
  421.  
  422.   forwarders 127.0.0.2 127.0.0.3
  423.  
  424. You can list as many forwarders as you like.
  425.  
  426. A line like this
  427.  
  428.   slave
  429.  
  430. in named.boot will put your name server in slave mode, this means it
  431. will only query it's forwarders.  If you're behind a firewall or
  432. perhaps have to pay for all network traffic this is usefull.
  433.