1. Install the BIND DNS server package.
sudo apt install bind9
2. Create a directory for your zone files.
sudo mkdir /etc/bind/zones
3. Create a zone file for your domain.
For example, if your domain is [Link], you would create a file called
[Link] in the /etc/bind/zones directory.
The contents of your zone file will vary depending on your specific needs, but here is a
basic example:
$TTL 86400
@ IN SOA [Link]. [Link]. (
2023100901 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
; Name servers
@ IN NS [Link].
@ IN NS [Link].
; A records
[Link]. IN A [Link]
[Link]. IN A [Link]
4. Create a reverse zone file for your network.
This file will map IP addresses to hostnames.
For example, if your network address is [Link]/24, you would create a file called
[Link] in the /etc/bind/zones directory.
The contents of your reverse zone file will vary depending on your specific network
configuration, but here is a basic example:
$TTL 86400
@ IN SOA [Link]. [Link]. (
2023100901 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
; Reverse records
1 IN PTR [Link].
2 IN PTR [Link].
5. Edit the BIND configuration file.
Open the file /etc/bind/[Link] in a text editor and make the following
changes:
Add the following line to the end of the file:
include "/etc/bind/zones";
Make sure that the following lines are uncommented:
listen-on { any; };
allow-query { any; };
6. Restart the BIND DNS server.
sudo systemctl restart bind9
7. Configure your clients to use the new DNS server.
8. Once you have completed these steps, your new DNS server will be up and
running. You can test it by trying to resolve a hostname on your network. For
example, you could try pinging [Link].
The contents of my zone file would be similar to the following:
$TTL 86400
@ IN SOA [Link]. [Link]. (
2023101001 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
; Name servers
@ IN NS [Link].
@ IN NS [Link].
; A records
[Link]. IN A [Link]
[Link]. IN A [Link]
This zone file defines the following:
The $TTL record specifies that all records in the zone file have a time to live (TTL)
of 86400 seconds (one day).
The SOA record specifies the start of authority record for the zone. It includes the
name of the primary name server for the zone ([Link]), the name of the
administrator for the zone ([Link]), the serial number of the zone
(2023101001), and the refresh, retry, expire, and minimum TTL values for the
zone.
The NS records specify that the name servers for the zone
are [Link] and [Link].
The A records map the hostnames [Link] and [Link] to the IP
addresses [Link] and [Link], respectively.
This zone file would be used to configure a DNS server to authoritatively answer DNS
queries for the domain [Link].
Here is a more detailed explanation of each line in the zone file:
$TTL 86400: This line specifies that all records in the zone file have a time to live
(TTL) of 86400 seconds (one day). This means that other DNS servers will cache
the records for 86400 seconds before querying your server again.
@ IN SOA [Link]. [Link]. (2023101001 3600 1800 604800
86400): This line specifies the start of authority record for the zone. It includes the
name of the primary name server for the zone ([Link]), the name of the
administrator for the zone ([Link]), the serial number of the zone
(2023101001), and the refresh, retry, expire, and minimum TTL values for the
zone.
o The serial number is a number that is incremented each time the zone file
is changed. This allows other DNS servers to know that the zone file has
changed and that they need to refresh their cache of records.
o The refresh value specifies how often other DNS servers should check
with your server to see if the zone file has changed.
o The retry value specifies how often other DNS servers should retry
querying your server if they do not receive a response the first time.
o The expire value specifies how long other DNS servers should keep a
record in their cache even if they do not receive a response from your
server.
o The minimum TTL value specifies the minimum amount of time that other
DNS servers should cache a record.
@ IN NS [Link]. @ IN NS [Link].: These lines specify that the name
servers for the zone are [Link] and [Link].
[Link]. IN A [Link] [Link]. IN A [Link]: These lines
map the hostnames [Link] and [Link] to the IP
addresses [Link] and [Link], respectively.
This is just a basic example of a zone file. You can add other types of records to your
zone file, such as MX records for mail servers, CNAME records for aliases, and TXT records
for text records.
To create a zone file for your domain in DNS on Ubuntu 20.04, follow these steps:
1. Create a directory for your zone files.
sudo mkdir /etc/bind/zones
2. Create a zone file for your domain.
For example, if your domain is [Link], you would create a file called
[Link] in the /etc/bind/zones directory.
The contents of your zone file will vary depending on your specific needs, but here is a
basic example:
$TTL 86400
@ IN SOA [Link]. [Link]. (
2023100901 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
; Name servers
@ IN NS [Link].
@ IN NS [Link].
; A records
[Link]. IN A [Link]
[Link]. IN A [Link]
3. Edit the BIND configuration file.
Open the file /etc/bind/[Link] in a text editor and make the following
changes:
Add the following line to the end of the file:
include "/etc/bind/zones";
Make sure that the following lines are uncommented:
listen-on { any; };
allow-query { any; };
4. Restart the BIND DNS server.
sudo systemctl restart bind9
5. Configure your clients to use the new DNS server.
On each client machine, open the network configuration settings and change the DNS
server addresses to the IP addresses of your new DNS servers.
Once you have completed these steps, your new DNS server will be up and running.
You can test it by trying to resolve a hostname on your network. For example, you could
try pinging [Link].
Here are some additional tips for creating a zone file:
The $TTL record specifies the time to live (TTL) for all records in the zone file.
The TTL is the amount of time that other DNS servers should cache the records
before querying your server again.
The SOA record specifies the start of authority record for the zone. It includes the
name of the primary name server for the zone, the name of the administrator for
the zone, the serial number of the zone, and the refresh, retry, expire, and
minimum TTL values for the zone.
The NS record specifies the name servers for the zone.
The A record maps a hostname to an IP address.
You can add other types of records to your zone file, such as MX records for mail
servers, CNAME records for aliases, and TXT records for text records.