faqts : Computers : Internet : Domain Names : djbdns

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 20 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

What should I use instead of CNAMEs?

Jun 2nd, 2001 19:35
Brian Coogan,


A common reason for using CNAMEs is to ensure that the IP address is 
only defined in one place in your DNS data which also has the effect of 
making the alias definitions understandable.  Although there are 
problems with using CNAMEs you may decide to just continue using them.  
However, if you are interested in alternatives, this entry describes 
the alternative and gives a way that you can avoid using CNAMEs without 
repeating IP address definitions throughout your data file and without 
making it less human readable.
The base alternative to using CNAMEs is to use aliases  (‘+’ data lines 
in tinydns-data language) giving the IP address you want the alias to 
end up with.  For instance, to alias the name www.example.com to the 
name example.com with an IP address of 1.2.3.4, you would use:
  .example.com:1.2.3.4:a
  +www.example.com:1.2.3.4
(Note that the . line actually created the SOA, NS and A records)
Alternatively, you could use the provided add-alias command:
     cd /service/tinydns/root
     ./add-alias www.heaven.af.mil 1.2.3.4
     make
This is kind of clumsy as it inolves using the IP address over and over 
again and is definitely not human readable when there's a lot of them!! 
Something we'd probably like to do here instead is to put the actual 
name of the target host in the second field instead of using the IP 
address, for example:
  =server1.example.com:1.2.3.4
  +pop.example.com:server1.example.com
  +smtp.example.com:server1.example.com
This would of course have the advantage that it allows the lines to 
make more human sense whilst reducing the number of times a particular 
IP address is defined.  The catch here is that tinydns does not yet 
directly support this; the comment at the end of the tinydns-data 
manual page/web page indicating that tinydns-data could support a name 
wherever an IP address was required is made in the context of future 
directions only.
However, Rob Mayoff has written a script called tinydns-fixup that does 
support this functionality by translating hostnames in aliases into IP 
addresses for you, allowing you to use names wherever you use IP 
addresses by converting the names into IP addresses before handing them 
on to tinydns-data.
As an example, this means that, as above, you can write a data file 
containing the following:
  =server.example.org:192.168.1.1
  +www.example.org:server.example.org
  +web.example.org:server.example.org
  +sec.example.org:server.example.org
  +prv.example.org:server.example.org
and the script would then convert it to the following tinydns-data 
input:
  =server.example.org:192.168.1.1
  +www.example.org:192.168.1.1
  +web.example.org:192.168.1.1
  +sec.example.org:192.168.1.1
  +prv.example.org:192.168.1.1
The script also supports ., -, @, and & records.
The script is at http://dqd.com/~mayoff/programs/tinydns-fixup.pl
The manpage follows:
NAME
   tinydns-fixup - Substitute addresses for names in tinydns data
SYNOPSIS
   tinydns-fixup data.f > data
DESCRIPTION
   tinydns-fixup reads data.f. For each ".", "&", "=", "+",
   "-", or "@" record that associates a name with an IP
   address, tinydns-fixup stores the IP address in a hash
   table with the name as the key. If the record contains a
   location code, then the location code is also part of the
   key.
   tinydns-fixup then reads data.f a second time. For each
   ".", "&", "=", "+", "-", or "@" record that contains a
   name where it should contain an IP address, tinydns-fixup
   looks up the name in its hash table. If the record
   contains a location code, then the location code is also
   used in the lookup. If the name (and location) is in the
   table, tinydns-fixup substitutes the IP address for the
   name in the record. tinydns-fixup then prints the record
   (regardless of whether it performed a substitution).
   The input data file must be seekable; a named pipe will
   not work.