| 1 | Building a DNS cache with BIND |
|---|
| 2 | ------------------------------ |
|---|
| 3 | |
|---|
| 4 | 1. Check the version of BIND which is installed |
|---|
| 5 | ----------------------------------------------- |
|---|
| 6 | |
|---|
| 7 | $ named -v |
|---|
| 8 | BIND 9.8.1 |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | 2. Configure your cache to accept queries from neighbors |
|---|
| 12 | -------------------------------------------------------- |
|---|
| 13 | |
|---|
| 14 | Edit the file /etc/namedb/named.conf (using vi or ee) |
|---|
| 15 | |
|---|
| 16 | Then find the line: |
|---|
| 17 | |
|---|
| 18 | listen-on { 127.0.0.1; }; |
|---|
| 19 | |
|---|
| 20 | ... and REMOVE IT. |
|---|
| 21 | |
|---|
| 22 | Instead, add another line: |
|---|
| 23 | |
|---|
| 24 | allow-recursion { 127.0.0.1; 10.10.0.0/16; }; |
|---|
| 25 | |
|---|
| 26 | Double check to see that there aren't any zones configured in your |
|---|
| 27 | DNS. For instance, if you see a line like follows: |
|---|
| 28 | |
|---|
| 29 | zone "10.in-addr.arpa" { type master; file "/etc/namedb/master/empty.db"; }; |
|---|
| 30 | |
|---|
| 31 | ... remove it, and save the file. |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | Be careful about the semicolons ';' and braces { } - BIND |
|---|
| 35 | will complain if they are not placed correctly |
|---|
| 36 | |
|---|
| 37 | By removing the line "listen-on ..." and adding the line |
|---|
| 38 | "allow-recursion", we are telling BIND: |
|---|
| 39 | |
|---|
| 40 | - please listen to the network for queries, not only on |
|---|
| 41 | the local interface "127.0.0.1"; |
|---|
| 42 | |
|---|
| 43 | - please allow clients in the 10.10.0.0/16 to send queries |
|---|
| 44 | to me, as well as myself; |
|---|
| 45 | |
|---|
| 46 | 3. Restart the cache and check it is running |
|---|
| 47 | -------------------------------------------- |
|---|
| 48 | |
|---|
| 49 | If you haven't done so earlier, edit `/etc/rc.conf` and add two lines saying: |
|---|
| 50 | |
|---|
| 51 | named_chrootdir="" |
|---|
| 52 | named_enable="YES" |
|---|
| 53 | |
|---|
| 54 | Then run these commands: |
|---|
| 55 | |
|---|
| 56 | # /etc/rc.d/named stop |
|---|
| 57 | # /etc/rc.d/named start |
|---|
| 58 | # ps auxwww | grep named |
|---|
| 59 | # tail /var/log/messages |
|---|
| 60 | |
|---|
| 61 | Check for successful startup with no error messages (you can ignore errors |
|---|
| 62 | about missing `master/localhost.rev` and `master/localhost-v6.rev`, as well |
|---|
| 63 | as messages regarding managed-keys-zone) |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | 4. Reconfigure your resolver to use your own cache only |
|---|
| 67 | ------------------------------------------------------- |
|---|
| 68 | |
|---|
| 69 | If you haven't done so earlier, edit `/etc/resolv.conf` as follows: |
|---|
| 70 | |
|---|
| 71 | Remove any existing 'nameserver' lines, or comment them out by inserting '#' |
|---|
| 72 | at the front. 127.0.0.1 is the loopback address; that is, an IP address |
|---|
| 73 | which means 'send the packet to myself', and we'll use it as our nameserver: |
|---|
| 74 | |
|---|
| 75 | search ws.nsrc.org |
|---|
| 76 | nameserver 127.0.0.1 |
|---|
| 77 | |
|---|
| 78 | 5. Test resolution |
|---|
| 79 | ------------------ |
|---|
| 80 | |
|---|
| 81 | Issue a query, for instance: |
|---|
| 82 | |
|---|
| 83 | $ dig google.com NS |
|---|
| 84 | $ dig noc.ws.nsrc.org A |
|---|
| 85 | |
|---|
| 86 | For each query: |
|---|
| 87 | |
|---|
| 88 | 1. Is the server responding ? |
|---|
| 89 | 2. How do you know that you are talking to your OWN server ? |
|---|
| 90 | 3. What do you notice ? |
|---|
| 91 | |
|---|
| 92 | If your neighbour has got their cache working, then try sending some queries |
|---|
| 93 | to their cache: |
|---|
| 94 | |
|---|
| 95 | $ dig @10.10.X.1 somedomain.name |
|---|
| 96 | |
|---|
| 97 | ... where XXX is the IP of the machine in the class you want to send the |
|---|
| 98 | query to, and "somedomain.name" is the query you would like to perform. |
|---|
| 99 | |
|---|
| 100 | Try and make some of the same queries you did before. Do the nameservers |
|---|
| 101 | of the other machines answer you ? |
|---|
| 102 | |
|---|
| 103 | Help your neighbours to get their cache working if required. |
|---|
| 104 | |
|---|
| 105 | 6. Watch the cache in operation |
|---|
| 106 | ------------------------------- |
|---|
| 107 | |
|---|
| 108 | You can take a snapshot of the cache contents like this: |
|---|
| 109 | |
|---|
| 110 | # ln -s /var/named/var/dump /var/dump |
|---|
| 111 | # /usr/sbin/rndc dumpdb |
|---|
| 112 | # less /var/named/var/dump/named_dump.db |
|---|
| 113 | |
|---|
| 114 | (Don't do this on a busy cache - you will generate a huge dump file!) |
|---|
| 115 | |
|---|
| 116 | You can watch the cache making queries to the outside world using |
|---|
| 117 | `tcpdump` in a different window (log in again via SSH): |
|---|
| 118 | |
|---|
| 119 | # tcpdump -n -s1500 -i eth0 udp port 53 |
|---|
| 120 | |
|---|
| 121 | If your ethernet interface isn't named `eth0`, then use the name of |
|---|
| 122 | your ethernet interface - e.g. `em0` or `bge0` - run "ifconfig" to find out |
|---|
| 123 | what your ethernet interface is named. |
|---|
| 124 | |
|---|
| 125 | While tcpdump is running, in the first window flush your cache (so it forgets |
|---|
| 126 | all existing data) and then issue some queries. |
|---|
| 127 | |
|---|
| 128 | # rndc flush |
|---|
| 129 | # dig www.tiscali.co.uk. -- and watch tcpdump output. What do you see? |
|---|
| 130 | |
|---|
| 131 | # dig www.tiscali.co.uk. -- watch tcpdump again. This time? |
|---|