This article will take you through how to construct a basic BIND Zone file and save it to your PC ready to upload to your Name Sever on the Internet. A Zone file is just a text file. To create the Zone file use any text editor for example Notepad, or (some of my favourites) TextPad or vi.
Create the Zone File
Open any text editor, in this case I'm using TextPad, click File, Save, give the file a name and remember the folder where you saved the file.
Tip: The easiest file naming convention for zone files is to name the file after the domain; example if you have a domain called yourdomain.com, then save the file as yourdomain.com
Tip: The easiet way to remember the folder where you saved the file is to create a folder on your PC called after your name server; example if your Name Server is nameserver.com, then create a folder called c:\nameserver. Then create a sub-folder called c:\nameserver\zones and save your zone files in that folder.
Sample Zone File
Type the following example Zone file into the Text Editor, replacing yourdomain.com with the actual name of your domain and nameserver.com with the actual names of your Name Servers;
|
;bind zone file for yourdomain.com
|
|
;location /var/cache/bind/
|
|
$TTL 1d
|
|
$ORIGIN yourdomain.com.
|
|
@
|
IN
|
SOA
|
|
ns0.nameserver.com. hostmaster.yourdomain.com. (
|
|
|
|
|
|
2008062401 ; serial
|
|
|
|
|
|
3h ; refresh
|
|
|
|
|
|
15m ; update retry
|
|
|
|
|
|
3w ; expiry
|
|
|
|
|
|
3h ; minimum
|
|
|
|
|
|
)
|
|
;Name Servers
|
|
|
|
|
|
|
IN
|
NS
|
|
ns0.nameserver.com.
|
|
|
IN
|
NS
|
|
ns1.nameserver.com.
|
|
|
IN
|
NS
|
|
ns2.nameserver.com.
|
|
|
|
|
|
|
|
;Mail Servers
|
|
|
|
|
|
|
IN
|
MX
|
|
10 mail
|
|
|
|
|
|
|
|
;Host Records
|
|
|
|
|
|
|
IN
|
A
|
|
66.206.198.130
|
|
www
|
IN
|
A
|
|
66.206.198.130
|
|
mail
|
IN
|
A
|
|
205.178.146.50
|
Zone File explained
1. The first thing to note is the semi-colon (;) starting some of the lines above. The semi-colon indicates to BIND that this is a comment and therefore anything after the semi-colon is ignored. In the example above, this means that the first two lines are included for information only. The first line says that the file is the zone file for yourdomain.com (we should already know this as the file is saved and named yourdomain.com). The second line says that the file is located at /var/cache/bind/; this is the location of the directory on the Debian GNU/Linux server where the zone files are stored. The name of your directory may vary depending on your installation.
2. $TTL 1d. TTL means Time To Live. This is the amount of time non-authoritive DNS servers will cache zone records. In this example, the TTL is 1 day. Note: The longer the time set in this value, the longer it will take to propagate any changes you make to your zones across the internet. However, if you set a very short value for the TTL, then your Name Server will work harder because non-authoritive servers will query it more often. 1 day is a sensible value.
Tip: If you know in advance that you need to change a zone record, for example you might plan to move your website to a new server, then decrease the value of the TTL about a week before the change for example set the TTL to 5m (5 minutes), and then when you apply the zone change, the change will take place in approx 5 minutes. Don't forget to set the TTL back to 1d, you don't want to over-work your name server!
3. $ORIGIN yourdomain.com. Notice the dot after the domain name. This is very important and you need to remember to type a dot. $ORIGIN is used in two contexts during zone file processing:
-
The symbol @ is used in BIND to denote 'zone root'. The current value of $ORIGIN is substituted for (replaces) the symbol @.
-
The current value of $ORIGIN is added to any 'unqualified' name (any name which does not end in a 'dot').
4. SOA or Start of Authority Record.
@ IN SOA this is the Start of Authority of your zone. The @ will be replaced by the value you entered in $ORIGIN, in this example yourdomain.com.
ns0.nameserver.com. is the Authoritive (also called Master or Primary) Name Server for your zone and hostmaster.yourdomain.com. (i.e. hostmaster@yourdomain.com) is the email address of the person responsible for the domain.
Serial
The other most important piece of information in the SOA is the Serial. In the example above 2008062401; this is the date and number of times the zone was last changed i.e. 24th June 2008 and it was only changed once that day. It is important to increment this serial number each time you make a change to a zone file e.g. if you added a new A record on 30th June 2008 and this was the second change made that day then the new serial number would be 2008063002.
Tip: Remember to increment the serial number in your zone's SOA (Start of Authority) record after changing the zone data. The Primary Master Name Server reloads the zone regardless of whether you've incremented the serial number because the file's modification time has changed, but your zone's Slaves (also called Backup or Secondary Names Servers) only have the serial number to tell them that the zone data has changed.
The other settings in the SOA are:
Refresh interval.
This is the time that your zones Slaves (Secondary or Backup Name Servers) are set to poll your Primary Master Name Server to check if the serial number has changed indicating the zone needs to be updated on the Slave servers. In the example above the Slave Name Servers (ns1 & ns2) will poll the Primary Master (ns0) every three hours.
Update Retry interval.
This is the time that your Slave Name Servers will keep trying to get an answer from your Primary Master if the Primary Master fails to answer. In the example above if the Primary Master (ns0) does not answer a query from the Slave Name Servers (ns1 & ns2), they will keep trying every 15 minutes.
Expiry interval.
This is the time that the Slave Name Servers will use the zone file data stored on their servers in the event of the Primary Master server failing. After this time the Slave Name Servers will stop answering queries and the domain will fail name resolution i.e. no-one on the internet will be able to find your website or email servers. You need to set this value to a sensible time period. The way I work this out is if the Primary Master Name Server crashes how long will it take me to get it backup up online? I'm guessing three weeks is the worst case senario. In the example above the Slave Name Servers will stop answering queries after three weeks.
Minimum interval
This is the time that the Primary Master requests that other name servers cache the zone. In the example above this is three hours.
5. ;Name Server. This sets the Name Server for the domain. In the example above ns0.nameserver.com (the Primary Master Name Server), ns1.nameserver.com and ns2.nameserver.com (the Slaves, Secondary or Backup Name Servers). Again very important not to forget the dot after the domain name. You can have as many Slave name servers as you like, provided they are configured to accept your zone data. These Slaves may be your own servers, or servers provided by your ISP.
6. ;Mail Servers. This sets the Primary Mail Server as the IP address specified in the ;Host Records section. You can also add a backup mail server. This is useful in the event your mail server is busy or does not answer; in which case mail will be sent to the backup mail servers where your mail will queue until the primary Mail Server is ready to accept mail. The 10 indicates the priority, if you add one or more backup mail servers ensure you set their priority higher than your Primary mail server for example IN MX 15 backup.mailserver.com. (don't forget the dot!).
7. ;Host Records In the example above yourdomain.com and www.yourdomain.com will go to IP address 66.206.198.130 (usually your Web / ftp server) and mail.yourdomain.com will go to IP address 205.178.146.50 (usually your Mail server).
To dot or not to dot, that is the question?
If you put a trailing dot (period) after a domain name then it is considered fully qualified (sometimes referred to as FQDN - Fully Qualified Domain Name). What that means is that it will be used exactly as you have entered it in the zone file.
If you don't put a trailing dot (period) after a domain name then it is unqualified and the value in $ORIGIN will be added to the value. If you have no $ORIGIN in your zone file, then the domain used in named.conf.local will be added.
In the example above, if I forgot the trailing dot (period) after ns0.nameserver.com, then this would become ns0.nameserver.com.yourdomain.com. i.e. that means the zone file will not resolve as the domain name is malformed. There are legitimate reasons why you would not use a trailing dot (period) after the domain name and we will go into this is more detail in subsequent articles.