
The goal of this lab is to set up a fully operational Domain Name System (DNS) with Recursive and Authoritative DNS Servers.
The configuration examples shown are based on the following setup:
| DNS Server | Fully Qualified Domain Name (FQDN) | IPv4 Address | IPv6 Address |
|---|---|---|---|
| Recursive Server | 202.249.25.242 | 2001:D30:AF1E:8000:81::2 | |
| Primary Authoritative NS | ns1.example.apiecamp.asia | 202.249.25.243 | 2001:D30:AF1E:8000:81::3 |
| Secondary Authoritative NS | ns2.example.apiecamp.asia | 202.249.25.244 | 2001:D30:AF1E:8000:81::4 |
example.apiecamp.asia202.249.25.240/282001:D30:AF1E:8000::/64test.apiecamp.asia and their address blocks are 202.249.25.128/28 and 2001:D30:AF1E:1000::/64Install Berkeley Internet Name Domain (BIND) in all your name servers (one Recursive DNS Server and two Authoritative DNS Servers) using Ubuntu's package manager. Type your password if required by the sudo commands.
$ cd ~
$ sudo apt-get update
$ sudo apt-get install -y bind9 bind9utils bind9-doc dnsutilsThis will install the latest stable version of BIND compiled for that operating system.
Verify the installation.
Find the location where BIND or named is installed.
$ which namedCheck the version.
$ named -vCheck whether BIND is running.
$ sudo systemctl status named
$ sudo systemctl status bind9Check the related files installed.
$ ls -lah /etc/bind
$ ls -lah /usr/share/dns
$ ls -lah /var/cache/bindReconfigure BIND working directory and logging with the following steps.
Create the file for DNS logs and update the permissions:
$ sudo mkdir /var/log/named
$ sudo touch /var/log/named/bind.log /var/log/named/xfer.log
$ sudo chown bind:bind -R /var/log/namedCheck the files and their permissions:
$ ls -lah /var/log/namedUpdate named.conf.options configuration file to update directory and add a logging statement:
$ cd /etc/bind/
$ ll
$ sudo nano named.conf.optionsFind the directory section (usually in line# 2) and set it to /etc/bind as shown below:
directory "/etc/bind";And, add the following logging section at the end of the page:
logging {
channel named_log {
file "/var/log/named/bind.log" versions 3 size 2m;
severity info;
print-severity yes;
print-time yes;
print-category yes;
};
channel xfer_log {
file "/var/log/named/xfer.log" versions 3 size 2m;
severity info;
print-time yes;
print-category yes;
};
category default { named_log; };
category config { named_log; };
category queries { named_log; };
category query-errors { named_log; };
category dnssec { named_log; };
category security { named_log; };
category xfer-in { xfer_log; };
category xfer-out { xfer_log; };
};Once you are happy with the changes, use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Change the owner to bind for the files in /etc/bind directory.
$ sudo chown bind:bind -R /etc/bindCheck the configuration with named-checkconf if there's any error. If there is no configuration error, it should NOT print any message (yes, no message means okay :-) ).
$ named-checkconfIf there's no error, restart BIND to apply the settings:
$ sudo systemctl restart bind9
$ sudo systemctl status bind9It should confirm that BIND is running.
Active: active (running)Then show the logs:
$ sudo tail –f /var/log/named/bind.logThe log should confirm that all zones are loaded and running.
==> /var/log/named/bind.log <==
zoneload: info: managed-keys-zone: loaded serial 2
zoneload: info: zone 0.in-addr.arpa/IN: loaded serial 1
zoneload: info: zone localhost/IN: loaded serial 2
zoneload: info: zone 127.in-addr.arpa/IN: loaded serial 1
zoneload: info: zone 255.in-addr.arpa/IN: loaded serial 1
general: notice: all zones loaded
general: notice: runningSimilar to systemctl, there is another utility called Remote Name Daemon Control (RNDC) that can be used to check and reconfigure bind. This allows control of BIND without having to restart the service. Let's check it.
$ sudo rndc statusAlong with several other information, the last line should confirm if the server is running.
server is up and runningCheck the rndc.key file that was created during install. This is used by default if no other configuration or key file is specified.
$ cd /etc/bind
$ sudo more rndc.keyRNDC can be used to reload any configuration or zone files. You may need to use the commands in later sections but now it's just for your reference.
To reload configuration and zones:
$ sudo rndc reloadTo reload specified zone only:
$ sudo rndc reload zoneTo reload configuration and new zones only:
$ sudo rndc reconfigYou can also generate rndc.conf for more control on the allow list. We won’t be doing this in this lab.
Permit DNS ports in your server's firewall (if any).
$ sudo ufw allow 53/udp
$ sudo ufw allow 53/tcp
BIND comes with a very handy setup for the Recursive DNS Server when installed in Ubuntu/Debian. It has pretty much everything pre-configured with recursion enabled by default.
However, for this lab, we will set recursion explicitly in the options statement.
Go to the /etc/bind directory and pdate the named.conf.options file.
$ sudo nano named.conf.optionsJust write the following line anywhere within the options statement:
recursion yes;Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Reload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusOr, restart BIND.
$ sudo systemctl restart bind9
$ sudo systemctl status bind9If any error is encountered, check the logs and try to figure it out:
$ sudo tail –f /var/log/named/bind.logor, mention the number of lines that you want to read from the latest logs:
$ sudo tail -15 /var/log/named/bind.logUse dig command to test the Recursive DNS Server. Take note of the ANSWER SECTION in the output.
$ dig @127.0.0.1 academy.apnic.net
$ dig @localhost www.apiecamp.asia
$ dig +trace www.apiecamp.asia
$ dig -x 133.27.114.27
$ dig academy.apnic.net AAAAOptional tasks:
- What is the IPv4 and IPv6 addresses of "apnic.net"?
- What are the FQDN of the Authoritative DNS Servers of "www.apnic.net"?
Hint: Query the parent domain to get NS info.
- What are the available PTR records for "apnic.net"?
Register your domain name and provide your Authoritative DNS Servers' FQDNs and IP addresses to the domain name registry. For this lab, approach the instructors for registration. Instructors are managing the parent zone apiecamp.asia and will be creating the delegation for your subdomains. In summary, decide about the following information and share with your instructors:
+ Your Domain Name:
+ Your Primary Authoritative DNS
- FQDN:
- IPv4 Address:
- IPv6 Address:
+ Your Secondary Authoritative DNS
- FQDN:
- IPv4 Address:
- IPv6 Address:All examples shown in this lab instruction are based on this setup:
+ My Domain Name: example.apiecamp.asia
+ My Primary Authoritative DNS
- FQDN: ns1.example.apiecamp.asia
- IPv4 Address: 202.249.25.243
- IPv6 Address: 2001:D30:AF1E:8000:81::3
+ My Secondary Authoritative DNS
- FQDN: ns2.example.apiecamp.asia
- IPv4 Address: 202.249.25.244
- IPv6 Address: 2001:D30:AF1E:8000:81::4Add the zone to the configuration file. Please note that the zone type is primary or master.
Open the configuration file:
$ cd /etc/bind
$ sudo nano named.conf.localAdd your zone configuration:
zone "example.apiecamp.asia." {
type primary;
file "/etc/bind/db.example.apiecamp.asia";
};Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Check for any syntax errors in the configuration files or in the zone files.
$ named-checkconfCreate the zone file for your domain.
$ sudo nano db.example.apiecamp.asiaAdd necessary resource records:
;; Forward zone for example.apiecamp.asia.
$ORIGIN example.apiecamp.asia.
$TTL 300
@ IN SOA ns1.example.apiecamp.asia. root.example.apiecamp.asia. (
2025021201 ; Serial No.
1800 ; Refresh
3600 ; Retry
604800 ; Expire
300 ; Negative TTL
)
IN NS ns1.example.apiecamp.asia.
ns1 IN A 202.249.25.243
IN AAAA 2001:D30:AF1E:8000:81::3
www IN A 202.249.25.245
IN AAAA 2001:D30:AF1E:8000:81::5
mail01 IN A 202.249.25.246
IN AAAA 2001:D30:AF1E:8000:81::6
mail02 IN A 202.249.25.247
IN AAAA 2001:D30:AF1E:8000:81::7
@ IN MX 10 mail01.example.apiecamp.asia.
IN MX 20 mail02.example.apiecamp.asia.
@ IN TXT "Example Authoritative DNS"
Information: Pay attention to the resource records with and without the . (dot) at the end of their names in the zone file.
Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Change the owner to bind for the files in /etc/bind/
$ sudo chown bind:bind -R /etc/bind/Check for any syntax errors in the zone files.
$ named-checkzone example.apiecamp.asia /etc/bind/db.example.apiecamp.asiaIf you encounter any issues, check the logs:
$ sudo tail –f /var/log/named/bind.logReload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusOnce BIND is running, go back to your Recursive DNS Server and do some basic test using dig command.
Test your Authoritative DNS Server and display the SOA records for your domain:
$ dig www.example.apiecamp.asia SOA +multiTest the Authoritative DNS Server to display NS records:
$ dig example.apiecamp.asia NSTest the Authoritative DNS Server to display other resource records (A, MX, TXT):
$ dig ns1.example.apiecamp.asia A
$ dig example.apiecamp.asia MX
$ dig example.apiecamp.asia TXTOptional tasks:
- Publish your Secondary Authoritative DNS Server's FQDN in
your zone file as another new TXT record.
- Publish your Secondary Authoritative DNS Server's IPv4 address in
your zone file as another new TXT record.
- Publish your Secondary Authoritative DNS Server's IPv6 address in
your zone file as another new TXT record.
- For your neighbor group, find their Primary Authoritative DNS Server's
FQDN, IPv4 address, and IPv6 address using "dig" utility.
- For your neighbor group, find their Secondary Authoritative DNS Server's
FQDN, IPv4 address, and IPv6 address using "dig" utility.
For this task, your Secondary Authoritative DNS Server will be authoritative for a zone from another team. You will need to work together to allow zone transfer and test. By now, you should have the following information of your neighbor group:
- Their Domain Name:
+ Their Primary Authoritative DNS
- FQDN:
- IPv4 Address:
- IPv6 Address:
+ Their Secondary Authoritative DNS
- FQDN:
- IPv4 Address:
- IPv6 Address:All examples shown in this lab instruction are based on this setup:
- Their Domain Name: test.apiecamp.asia
+ Their Primary Authoritative DNS
- FQDN: ns1.test.apiecamp.asia
- IPv4 Address: 202.249.25.131
- IPv6 Address: 2001:D30:AF1E:1000:11::131
+ Their Secondary Authoritative DNS
- FQDN: ns2.test.apiecamp.asia
- IPv4 Address: 202.249.25.132
- IPv6 Address: 2001:D30:AF1E:1000:11::132Since you are going to serve as the secondary server for their zone, access your Secondary Authoritative DNS Server.
Open the configuration file:
$ cd /etc/bind
$ sudo nano named.conf.localAdd configurations for their zone, the zone type is secondary or slave:
zone "test.apiecamp.asia." {
type secondary;
primaries {
202.249.25.131;
2001:D30:AF1E:1000:11::131;
};
file "/var/cache/bind/db.test.apiecamp.asia";
};In Ubuntu/Debian, /var/cache/bind is the default location for non-authoritative zones but you can change the directory with proper permission.
Check for any syntax error.
$ named-checkconfYour neighbor's Secondary Authoritative DNS Server is the secondary server for your zone, so you are adding their server's FQDN in your Primary Authoritative DNS Server's configuration.
Edit the zone database:
$ cd /etc/bind
$ sudo nano db.example.apiecamp.asiaAdd the NS record for the Secondary Authoritative Server for the zone:
;; Forward zone for example.apiecamp.asia.
$ORIGIN example.apiecamp.asia.
$TTL 300
@ IN SOA ns1.example.apiecamp.asia. root.example.apiecamp.asia. (
2025021202 ; Serial No.
1800 ; Refresh
3600 ; Retry
604800 ; Expire
300 ; Negative TTL
)
IN NS ns1.example.apiecamp.asia.
IN NS ns2.test.apiecamp.asia.
ns1 IN A 202.249.25.243
IN AAAA 2001:D30:AF1E:8000:81::3
ns2 IN A 202.249.25.132
IN AAAA 2001:D30:AF1E:1000:11::132
;; output trimmed for brevity
Important: Do not forget to update the serial number in SOA record (usually by 1) every time you make any changes in your zone database. This is important for zone data synchronization. Failure to do so would result inconsistent name resolution.
Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Check for any syntax errors in the zone files.
$ named-checkzone example.apiecamp.asia /etc/bind/db.example.apiecamp.asiaReload zones and configurations to apply the changes in Authoritative DNS Servers (both Primary and Secondary).
$ sudo rndc reconfig
$ sudo rndc statusTalk to your neighbor, similar to the step 2 and 4 mentioned earlier, they need to
example.apiecamp.asia. in their secondary DNS (see step 2)ns2.example.apiecamp.asia. as their secondary server in their zone file (see step 4)After configurations for both groups (you and your neighbor) are completed. Check whether zone transfer occurs in the Secondary Authoritative DNS Server.
To manually do zone transfer, issue this command:
$ dig @202.249.25.131 test.apiecamp.asia. AXFRor, with IPv6
$ dig @2001:d30:af1e:1000:11::131 test.apiecamp.asia. AXFRYou can also check the logs to see if transfer has been completed
$ sudo tail -20 /var/log/named/xfer.log
zone example.apiecamp.asia/IN: Transfer started.
transfer of 'test.apiecamp.asia/IN' from 202.249.25.131#53:
connected using 202.249.25.131#53
zone test.apiecamp.asia/IN: transferred serial 2025021202
transfer of 'test.apiecamp.asia/IN' from 202.249.25.131#53:
Transfer status: success
transfer of 'test.apiecamp.asia/IN' from 202.249.25.131#53:
Transfer completed: 1 messages, 14 records, 327 bytes,
0.001 secs (327000 bytes/sec) (serial 2025021202)Talk to your neighbor, and make sure they do the same for your zone.
Optional tasks:
- In your Secondary Authoritative DNS Server, find the zone file that
you have just received from your neighbor's Primary Authoritative
DNS Server. What do you see when you try to open/read it?
- In your Recursive DNS Server, run dig queries on both the Primary and the
Secondary Authoritative DNS Server of your domain and show it to the instructors.
(e.g. dig @ns2.test.apiecamp.asia example.apiecamp.asia MX)
Check the delegated IPv4 prefixes for your group. The reverse DNS zone is written in a special reverse order of the numbers in the prefixes. For instance, if you have been assigned with 202.249.25.240/28 for your group, let's consider the following situation:
202.249.25.128/25, hence the IPv4 reverse DNS zone would be written as 128/25.25.249.202.in-addr.arpa. (see how the octates have been repsented in reverse order).202.249.25.240/28 by the parent zone 128/25.25.249.202.in-addr.arpa. that would mean that the group's reverse DNS zone would be 240/28.128/25.25.249.202.in-addr.arpa.. This may seem complicated in the first look, but if you follow the DNS hierarchy, it would make sense.In your Primary Authoritative DNS Server, add the IPv4 reverse zone to the configuration file (named.conf.local).
Remember:
Zone Name: Needs to strictly follow the syntax
Zone File/DB name: It's just a file, hence any name can be chosen
For our group:
Reverse Zone Name (naming syntax): 240/28.128/25.25.249.202.in-addr.arpa.
Zone File/DB Name (chosen name): db.240.25.249.202.in-addr.arpaOpen the configuration file:
$ cd /etc/bind
$ sudo nano named.conf.localAdd the following configuration:
zone "240/28.128/25.25.249.202.in-addr.arpa." {
type primary;
file "/etc/bind/db.240.25.249.202.in-addr.arpa";
};This is called "Classless IN-ADDR.ARPA delegation".
Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Check for any syntax error.
$ named-checkconfCreate a new zone file in /etc/bind/ directory. Remember, you need to use the same name that you have used in zone configuration above.
Create the zone file:
$ cd /etc/bind
$ sudo nano db.240.25.249.202.in-addr.arpaAdd necessary resource records like NS record and PTR record. For this lab, we are just adding the PTR records for the mail servers, but in real-world network operations, more PTR records may be needed.
;; Reverse DNS for 202.249.25.240/28
$ORIGIN 240/28.128/25.25.249.202.in-addr.arpa.
$TTL 300
@ IN SOA ns1.example.apiecamp.asia. root.example.apiecamp.asia. (
2025021201 ; Serial No.
1800 ; Refresh
3600 ; Retry
604800 ; Expire
300 ; Negative TTL
)
IN NS ns1.example.apiecamp.asia.
IN NS ns2.test.apiecamp.asia.
246 IN PTR mail01.example.apiecamp.asia.
247 IN PTR mail02.example.apiecamp.asia.Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Change the owner to bind for the files in /etc/bind/
$ sudo chown bind:bind -R /etc/bind/Check for any syntax errors in the zone files.
$ named-checkzone 240/28.128/25.25.249.202.in-addr.arpa. \
/etc/bind/db.240.25.249.202.in-addr.arpaReload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusSimilar to the previous steps, we need to configure your Secondary Authoritative DNS Server. So that it acts as the secondary server of your neighbor's reverse zone.
Let's edit the zone file:
$ cd /etc/bind
$ sudo nano named.conf.localAdd the following configuration:
zone "128/28.128/25.25.249.202.in-addr.arpa." {
type secondary;
primaries {
202.249.25.131;
2001:D30:AF1E:1000:11::131;
};
file "/var/cache/bind/db.128.25.249.202.in-addr.arpa";
};Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Talk to your neighbor, and make sure they made similar configuration for your zone.
Check for any syntax error.
$ named-checkconfReload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusTo manually do zone transfer, issue this command:
$ dig @202.249.25.131 128/28.128/25.25.249.202.in-addr.arpa. AXFRor, with IPv6
$ dig @2001:d30:af1e:1000:11::131 128/28.128/25.25.249.202.in-addr.arpa. AXFRYou can check the logs to see if transfer has been completed
$ sudo tail -20 /var/log/named/xfer.logTalk to your neighbor, and make sure they do the same for your zone.
Once BIND is running, run dig in your Recursive DNS Server to validate the configuration:
$ dig -x 202.249.25.246
$ dig -x 202.249.25.247Similar to the steps above, create the reverse zone for the /64 IPv6 prefix. Again, the reverse DNS zone is written in a reverse order of the numbers in the prefixes. Let's consider the following example:
IPv6 Address: 2001:D30:AF1E:8000::/64
Remove separator (colon): 20010D30AF1E8000
Add dot between numbers: 2.0.0.1.0.d.3.0.a.f.1.e.8.0.0.0
Write in reverse order: 0.0.0.8.E.1.F.A.0.3.D.0.1.0.0.2
Append "ip6.arpa." domain: 0.0.0.8.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa.In your Primary Authoritative DNS Server, add the IPv6 reverse zone to the configuration file (named.conf.local).
Open the configuration file:
$ cd /etc/bind
$ sudo nano named.conf.localAdd the following configuration:
zone "0.0.0.8.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa" {
type primary;
file "/etc/bind/db.8000.af1e.d30.2001.ip6.arpa";
};Remember, Zone file/DB name is just a given name. For simplicity, we are using db.8000.af1e.d30.2001.ip6.arpa as our reverse zone DB.
Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Check for any syntax error.
$ named-checkconfCreate a corresponding zone file
$ cd /etc/bind
$ sudo nano db.8000.af1e.d30.2001.ip6.arpaAdd the resource records:
;; Reverse DNS for 2001:D30:AF1E:8000::/64
$ORIGIN 0.0.0.8.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa.
$TTL 300
@ IN SOA ns1.example.apiecamp.asia. root.example.apiecamp.asia. (
2025021201 ; Serial No.
1800 ; Refresh
3600 ; Retry
604800 ; Expire
300 ; Negative TTL
)
IN NS ns1.example.apiecamp.asia.
IN NS ns2.test.apiecamp.asia.
6.0.0.0.0.0.0.0.0.0.0.0.1.8.0.0 IN PTR mail01.example.apiecamp.asia.
7.0.0.0.0.0.0.0.0.0.0.0.1.8.0.0 IN PTR mail02.example.apiecamp.asia.Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Change ownership of file.
$ sudo chown bind:bind -R /etc/bind/Check if there's any syntax error:
$ named-checkzone 0.0.0.8.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa. \
/etc/bind/db.8000.af1e.d30.2001.ip6.arpaReload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusSimilar to the previous steps, we need to configure Secondary Authoritative DNS Server for the reverse zone. Again, your Secondary Authoritative DNS Server would act as the secondary server of your neighbor's zone. Hence, the configuration in named.conf.local of your Secondary Authoritative DNS Server would look like:
zone "0.0.0.1.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa." {
type secondary;
primaries {
202.249.25.131;
2001:D30:AF1E:1000:11::131;
};
file "/var/cache/bind/db.1000.af1e.d30.2001.ip6.arpa";
};Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.
Talk to your neighbor, and make sure they made similar configuration for your zone.
Check for any syntax error.
$ named-checkconfReload zones and configurations to apply the changes.
$ sudo rndc reconfig
$ sudo rndc statusTo manually do zone transfer, issue this command:
$ dig @202.249.25.131 0.0.0.1.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa. AXFRor, with IPv6
$ dig @2001:d30:af1e:1000:11::131 0.0.0.1.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa. AXFRYou can check the logs to see if transfer has been completed
$ sudo tail -20 /var/log/named/xfer.logTalk to your neighbor, and make sure they do the same for your zone.
Once BIND is running, run dig in your Recursive DNS Server to validate the configuration:
$ dig -x 2001:D30:AF1E:8000:81::6
$ dig -x 2001:D30:AF1E:8000:81::7
Nothing to do in the lab.
ACL for Recursive DNS:
Configure ACL to allow queries from the class IP block only.
$ sudo nano named.conf.optionsCreate an ACL to allow only your subnets (no one outside your network will be able to use your resolver)
acl localnet {
202.249.25.240/28;
2001:D30:AF1E:8000::/64;
localhost;
};Then update the options statement to add the last 4 lines:
allow-recursion { localnet; };
allow-query { localnet; };
allow-query-cache { localnet; };Additionally, we can restrict/limit the socket by running DNS/Port 53 only on the intended IP/interface of the DNS server by configuring
listen-on { 127.0.0.1; 202.249.25.242; };
listen-on-v6 { ::1; 2001:d30:af1e:8000:81::2; };Check if there is any syntax errors, restart BIND and check the status.
$ named-checkconf
$ sudo systemctl restart bind9
$ sudo systemctl status bind9ACL for Authoritative DNS Servers (both Primary and Secondary):
Configure ACL to restrict queries to only authoritative zones and disable recursion.
$ sudo nano named.conf.optionsUpdate the options statements.
recursion no;
allow-query { any; };
allow-query-cache { none; };Additionally, we can restrict/limit the socket by running DNS/Port 53 only on the intended IP/interface of the DNS server by configuring
listen-on { 127.0.0.1; 202.249.25.243; };
listen-on-v6 { ::1; 2001:d30:af1e:8000:81::3; };Similarly, configure the secondary DNS with its corresponding IP addresses.
Check configuration and restart BIND and check the status.
$ named-checkconf
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Insecure Zone Transfer: In your own laptop, open a new terminal and run the dig command:
dig @ns1.example.apiecamp.asia example.apiecamp.asia. AXFRAlert: You can get a full copy of the zone which is NOT secure.
Keep this terminal open for now.
In the Primary Authoritative DNS Server, restrict who can get the zone file.
$ cd /etc/bind/
$ sudo nano named.conf.localAdd allow-transfer within the zone statement as below. Add the Secondary Authoritative DNS Server's IP address.
zone "example.apiecamp.asia." {
type primary;
file "/etc/bind/db.example.apiecamp.asia";
allow-transfer {
// These are the Secondary Authoritative DNS Server' addresses
202.249.25.132;
2001:D30:AF1E:1000:11::132;
};
};Check configuration and restart BIND and check the status.
$ named-checkconf
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Go to the previously opened terminal and run the same dig command for insecure zone transfer:
dig @ns1.example.apiecamp.asia example.apiecamp.asia. AXFRThis time, the zone transfer fails. You might find the output similar as below:
; Transfer failed.In the Secondary Authoritative DNS Server, delete the zone file transferred previously.
$ sudo rm /var/cache/bind/db.test.apiecamp.asiaRestart BIND and check the status.
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Check the log file to see the zone transfer.
$ sudo tail -20 /var/log/named/xfer.logAlso try to manually do zone transfer using dig command:
$ dig @202.249.25.131 test.apiecamp.asia. AXFRTalk to your neighbor, and make sure they do the same for your zone.
Discussions:
- In Task #5, was the transfer successful? Why?
- In Task #4, why the transfer failed?
The following should be done in the Primary Authoritative DNS Server:
Generate the TSIG key in the Primary Authoritative DNS Server.
$ cd /etc/bind
$ tsig-keygen -a hmac-sha256 ns1-ns2-tsig | sudo tee ns1-ns2-tsig.keyCheck the contents of the file:
$ sudo cat ns1-ns2-tsig.keyUpdate named.conf.options to include the key.
$ sudo nano /etc/bind/named.conf.optionsAppend the following to the file.
include "/etc/bind/ns1-ns2-tsig.key";Change ownership of file.
$ sudo chown bind:bind -R /etc/bind/Update named.conf.local file to modify the allow-transfer part.
$ sudo nano /etc/bind/named.conf.localRemove the addresses and replace with key.
allow-transfer {
//202.249.25.132;
//2001:D30:AF1E:1000:11::132;
key ns1-ns2-tsig;
};Check the configuration and restart BIND and check the status.
$ named-checkconf
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Send the key to the Secondary Authoritative DNS Server:
$ sudo scp /etc/bind/ns1-ns2-tsig.key apie@202.249.25.132:/home/apieTalk to your neighbor, and make sure they do the same.
The following should be done in the Secondary Authoritative DNS Server:
Move the transferred key to the BIND working directory.
$ sudo mv /home/apie/ns1-ns2-tsig.key /etc/bindChange ownership of file
$ sudo chown bind:bind -R /etc/bind/Try zone transfer as you did earlier in the previous section:
$ dig @202.249.25.131 test.apiecamp.asia. AXFRThis should result to Transfer failed. But why?
Try zone transfer with a key:
$ dig @202.249.25.131 test.apiecamp.asia. AXFR -k /etc/bind/ns1-ns2-tsig.keyThis should be successful. But why?
Update named.conf.options to add the TSIG key.
$ sudo nano named.conf.optionsAppend the following include statement and server statement:
include "/etc/bind/ns1-ns2-tsig.key";
server 202.249.25.131 {
keys { ns1-ns2-tsig; };
};
server 2001:D30:AF1E:1000:11::131 {
keys { ns1-ns2-tsig; };
};Check configuration and restart BIND and check the status.
$ named-checkconf
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Verify zone transfer with TSIG key:
In the Secondary Authoritative DNS Server, delete the zone file transferred previously.
$ sudo rm /var/cache/bind/db.test.apiecamp.asiaRestart BIND and check the status.
$ sudo systemctl restart bind9
$ sudo systemctl status bind9Check the log file to see the zone transfer.
$ sudo tail -20 /var/log/named/xfer.logTalk to your neighbor, and make sure they do the same for your zone.
Congratulations! You have reached the end of this lab.
APIE Camp DNS Lab
Version 1.7
Last update 10 Feb 2025