APIE Camp #04 (August 2024) – DNS Configuration

Objectives

The goal of this lab is to set up a fully operational Domain Name System (DNS) with Recursive and Authoritative DNS Servers.

Setup

The configuration examples shown are based on the following setup:

DNS Server Fully Qualified Domain Name (FQDN) IPv4 Address IPv6 Address
Recursive   202.249.25.210 2001:D30:AF1E:6000:61::210
Primary Authoritative ns1.example.apiecamp.asia 202.249.25.211 2001:D30:AF1E:6000:61::211
Secondary Authoritative ns2.example.apiecamp.asia 202.249.25.212 2001:D30:AF1E:6000:61::212

Task 1: Install BIND for Three DNS Servers

  1. Install 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 dnsutils tree mtr
    

    This will install the latest stable version of BIND compiled for that operating system.

  2. Verify the installation.

    Find the location where BIND or named is installed.

    which named
    

    Check the version.

    named -v
    

    Check whether BIND is running.

    sudo systemctl status named
    sudo systemctl status bind9
    
  3. Check the related files installed.

    ls /etc/bind
    ls /usr/share/dns
    ls /var/cache/bind
    
  4. Reconfigure 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
    sudo chown bind:bind -R /var/log/named
    
  5. Update named.conf.options configuration file to update directory and add a logging statement:

    cd /etc/bind/
    ll
    sudo nano named.conf.options
    

    Find 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;
    	};
    	category default { named_log; };
    	category config { named_log; };
    	category queries { named_log; };
    	category query-errors { named_log; };
    	category dnssec { named_log; };
    	category xfer-in { named_log; };
    	category xfer-out { named_log; };
    	category security { named_log; };
    };
    

    Once you are happy with the changes, use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  6. Change the owner to bind for the files in /etc/bind directory.

    sudo chown bind:bind -R /etc/bind
    
  7. Check 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-checkconf
    

    If there's no error, restart BIND to apply the settings:

    sudo systemctl restart bind9
    sudo systemctl status bind9
    

    It should confirm that BIND is running.

    Active: active (running)
    

    Then show the logs:

    sudo tail –f /var/log/named/bind.log
    

    The log should confirm that all zones are loaded and running.

    ==> /var/log/named/bind.log <==
    07-Aug-2024 03:32:55.307 zoneload: info: managed-keys-zone: loaded serial 2
    07-Aug-2024 03:32:55.307 zoneload: info: zone 0.in-addr.arpa/IN: loaded serial 1
    07-Aug-2024 03:32:55.307 zoneload: info: zone localhost/IN: loaded serial 2
    07-Aug-2024 03:32:55.311 zoneload: info: zone 127.in-addr.arpa/IN: loaded serial 1
    07-Aug-2024 03:32:55.311 zoneload: info: zone 255.in-addr.arpa/IN: loaded serial 1
    07-Aug-2024 03:32:55.311 general: notice: all zones loaded
    07-Aug-2024 03:32:55.319 general: notice: running
    
  8. Similar 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 status
    

    Along with several other information, the last line should confirm if the server is running.

    server is up and running
    

    Check 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.key
    

    RNDC 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 reload
      
    • To reload specified zone only:

      sudo rndc reload zone
      
    • To reload configuration and new zones only:

      sudo rndc reconfig
      

    You can also generate rndc.conf for more control on the allow list. We won’t be doing this in this lab.

  9. Permit DNS ports in your server's firewall (if any).

    sudo ufw allow 53/udp
    sudo ufw allow 53/tcp
    

STOP here and show the output to the instructors

Task 2: Configure Recursive DNS Server

  1. 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.options
    

    Just 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.

  2. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    

    Or, restart BIND.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    

    If any error is encountered, check the logs and try to figure it out:

    sudo tail –f /var/log/named/bind.log
    

    or, mention the number of lines that you want to read from the latest logs:

    sudo tail -15 /var/log/named/bind.log
    
  3. Use 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 AAAA
    
  4. Optional tasks:

     - What is the IPv4 and IPv6 addresses of "apnic.net"?
     - What are the FQDN of the Authoritative DNS Servers of "www.apnic.net"?
     - What is the PTR record for "apnic.net"?
    

STOP here and show the output to the instructors

Task 3: Configure Primary Authoritative DNS Server

  1. 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:

     - Your Domain Name:	example.apiecamp.asia
     + Your Primary Authoritative DNS
        - FQDN:		ns1.example.apiecamp.asia
        - IPv4 Address:	202.249.25.211
        - IPv6 Address:	2001:D30:AF1E:6000:61::211
     + Your Secondary Authoritative DNS
        - FQDN:		ns2.example.apiecamp.asia
        - IPv4 Address:	202.249.25.212
        - IPv6 Address:	2001:D30:AF1E:6000:61::212
    
  2. Add 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.local
    

    Add 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.

  3. Check for any syntax errors in the configuration files or in the zone files.

    named-checkconf
    
  4. Create the zone file for your domain.

    sudo nano db.example.apiecamp.asia
    

    Add 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. (
    		2024080801	; Serial No.
    		1800		; Refresh
    		3600		; Retry
    		604800		; Expire
    		300		; Negative TTL 
    )
    		IN	NS	ns1.example.apiecamp.asia.
    
    ns1		IN	A	202.249.25.211
    		IN	AAAA	2001:D30:AF1E:6000:61::211
    ns2		IN	A	202.249.25.212
    		IN	AAAA	2001:D30:AF1E:6000:61::212
    www		IN	A	202.249.25.210
    		IN	AAAA	2001:D30:AF1E:6000:61::210
    mail01		IN	A	202.249.25.213
    		IN	AAAA	2001:D30:AF1E:6000:61::213
    mail02		IN	A	202.249.25.214
    		IN	AAAA	2001:D30:AF1E:6000:61::214
    @		IN	MX	10 mail01
    		IN	MX	20 mail02
    @		IN	TXT	"Example Authoritative DNS"
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  5. Change the owner to bind for the files in /etc/bind/

    sudo chown bind:bind -R /etc/bind/
    
  6. Check for any syntax errors in the zone files.

    named-checkzone example.apiecamp.asia /etc/bind/db.example.apiecamp.asia
    
  7. If you encounter any issues, check the logs:

    sudo tail –f /var/log/named/bind.log
    
  8. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    
  9. Once BIND is running, go back to your Recursive DNS Server and do some basic test using dig command.

    • To test your Authoritative DNS Server and display the SOA records for your domain:

      dig www.example.apiecamp.asia SOA +multi
      
    • To test your Authoritative DNS Server to display NS records:

      dig example.apiecamp.asia NS
      
    • To test your Authoritative DNS Server to display other resource records (A, MX, or TXT):

      dig ns1.example.apiecamp.asia A
      dig example.apiecamp.asia MX
      dig example.apiecamp.asia TXT
      
  10. Optional 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.
    

STOP here and show the output to the instructors

Task 4: Configure Secondary Authoritative DNS Server

  1. 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::132
    
  2. Since 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.local
    

    Add 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.

  3. To change the owner of the files in /var/cache/bind/ use the following command:

    sudo chown bind:bind -R /var/cache/bind/

  4. Check for any syntax error.

    named-checkconf
    
  5. Your 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.asia
    

    Add 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. (
    		2024080802	; 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.211
    		IN	AAAA	2001:D30:AF1E:6000:61::211
    ns2		IN	A	202.249.25.212
    		IN	AAAA	2001:D30:AF1E:6000:61::212
    

    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.

  6. Check for any syntax errors in the zone files.

    named-checkzone example.apiecamp.asia /etc/bind/db.example.apiecamp.asia
    
  7. Reload zones and configurations to apply the changes in Authoritative DNS Servers (both Primary and Secondary).

    sudo rndc reconfig
    sudo rndc status
    
  8. Talk to your neighbor, similar to the steps mentioned earlier, they need to add your Secondary Authoritative DNS Server ns2.example.apiecamp.asia. as their secondary server for the zone test.example.com.

    Their zone file for test.example.com should typically look like this:

    ;; Forward zone for test.apiecamp.asia.
    $ORIGIN test.apiecamp.asia.
    $TTL 300
    @		IN	SOA	ns1.test.apiecamp.asia. root.test.apiecamp.asia. (
    		2024080802	; Serial No.
    		1800		; Refresh
    		3600		; Retry
    		604800		; Expire
    		300		; Negative TTL
    )
    		IN	NS	ns1.test.apiecamp.asia.
    		IN	NS	ns2.example.apiecamp.asia.
    
    ns1		IN	A	202.249.25.131
    		IN	AAAA	2001:D30:AF1E:1000:11::131
    ns2		IN	A	202.249.25.132
    		IN	AAAA	2001:D30:AF1E:1000:11::132
    
  9. 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. AXFR
    

    You can also check the logs to see if transfer has been completed

    sudo tail -20 /var/log/named/bind.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 2024080802
    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 2024080802)
    
  10. Optional tasks:

     - How many resource records has been collected by your Secondary
       Authoritative DNS Server? How many resource records your
       neighbor has added in their Primary Authoritative DNS Server?
     - In your Secondary Authoritative DNS Server, find the zone file that
       you have just received from your neighbor's Primary Authoritative
       DNS Server. Can you read the information of that zone file?
     - In your Recursive DNS Server, run dig queries to the Secondary
       Authoritative DNS Server of your domain and show it to the instructors.
       (e.g. dig @ns2.test.apiecamp.asia example.apiecamp.asia TXT)
    

STOP here and show the output to the instructors

Task 5: Configure Reverse DNS

5.1. IPv4 Reverse DNS

  1. 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.208/28 for your group, let's consider the following situation:

    • APIE has received an IPv4 assignment of 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).
    • APIE has further delegated each group with a /28 subnet. Hence, if a group is delegated with 202.249.25.208/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 208/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.
  2. In your Primary Authoritative DNS Server, add the IPv4 reverse zone to the configuration file (named.conf.local).

    Actually db.208S28.128S25.25.249.202.in-addr.arpa below is just a chosen name:

    • "/" in the zone name has been replaced as β€œS” in the file name.
    • Because "/" is typically used for identifying directory path and therefore cannot be part of a file name.

    It does NOT necessarily need to look like that, you may choose any other name. It is not the syntax of a zone file.

    Reverse Zone Name:		208/28.128/25.25.249.202.in-addr.arpa.
    
    1. Remove tailing dot	==>	208/28.128/25.25.249.202.in-addr.arpa
    2. Replace "/" with "S"	==>	208S28.128S25.25.249.202.in-addr.arpa
    3. Prepend "db."	==>	db.208S28.128S25.25.249.202.in-addr.arpa
    

    Open the configuration file:

    cd /etc/bind
    sudo nano named.conf.local
    

    Add the following configuration:

    zone "208/28.128/25.25.249.202.in-addr.arpa." {
    	type primary;
    	file "/etc/bind/db.208S28.128S25.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.

  3. Check for any syntax error.

    named-checkconf
    
  4. Create 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.208S28.128S25.25.249.202.in-addr.arpa
    

    Add the following configuration:and add necessary resource records like NS record and PTR record.

    ;; Reverse DNS for 202.249.25.208/28
    $ORIGIN 208/28.128/25.25.249.202.in-addr.arpa.
    $TTL 300
    @		IN	SOA	ns1.example.apiecamp.asia. root.example.apiecamp.asia. (
    		2024080801	; Serial No.
    		1800		; Refresh
    		3600		; Retry
    		604800		; Expire
    		300		; Negative TTL
    )
    		IN	NS	ns1.example.apiecamp.asia.
    		IN	NS	ns2.test.apiecamp.asia.	
    
    210		IN	PTR	www.example.apiecamp.asia.
    211		IN	PTR	ns1.example.apiecamp.asia.
    212		IN	PTR	ns2.example.apiecamp.asia.
    213		IN	PTR	mail01.example.apiecamp.asia.
    214		IN	PTR	mail02.example.apiecamp.asia.
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  5. Change the owner to bind for the files in /etc/bind/

    sudo chown bind:bind -R /etc/bind/
    
  6. Check for any syntax errors in the zone files.

    named-checkzone 208/28.128/25.25.249.202.in-addr.arpa. \
    	/etc/bind/db.208S28.128S25.25.249.202.in-addr.arpa
    
  7. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    
  8. Talk to your neighbor, similar to the steps mentioned earlier, they need to add your server ns2.example.apiecamp.asia. as their secondary server for the zone 128/28.128/25.25.249.202.in-addr.arpa..

  9. Similar 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.local
    

    Add 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.128S28.128S25.25.249.202.in-addr.arpa";
    };
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  10. Check for any syntax error.

    named-checkconf
    
  11. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    
  12. To manually do zone transfer, issue this command:

    dig @202.249.25.131 128/28.128/25.25.249.202.in-addr.arpa. AXFR
    

    You can check the logs to see if transfer has been completed

    sudo tail -20 /var/log/named/bind.log
    
  13. Once BIND is running, run dig in your Recursive DNS Server to validate the configuration:

    dig @ns1.example.apiecamp.asia -x 202.249.25.213
    

    Similarly, test your Secondary Authoritative DNS Server:

    dig @ns2.test.apiecamp.asia -x 202.249.25.213
    

STOP here and show the output to the instructors

5.2. Configure Reverse DNS for IPv6

  1. Similar 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:6000::/64
     
    1. Remove separator (colon)	==>	20010D30AF1E6000
    2. Add dot between hex numbers	==>	2.0.0.1.0.d.3.0.a.f.1.e.6.0.0.0
    3. Write in reverse order	==>	0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2
    4. Append "ip6.arpa." domain	==>	0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa.
    
  2. 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.local
    

    Add the following configuration:

    zone "0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa" {
    	type primary;
    	file "/etc/bind/db.0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa";
    };
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  3. Check for any syntax error.

    named-checkconf
    
  4. Create a corresponding zone file db.0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa.

    cd /etc/bind
    sudo nano db.0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa
    

    Add the resource records:

    ;; Reverse DNS for 2001:D30:AF1E:6000::/64
    $ORIGIN 0.0.0.6.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. (
    		2024080801	; Serial No.
    		1800		; Refresh
    		3600		; Retry
    		604800		; Expire
    		300		; Negative TTL
    )
    		IN	NS	ns1.example.apiecamp.asia.
    		IN	NS	ns2.test.apiecamp.asia.		
    
    ;; Prefix 2001:D30:AF1E:6000:61::/112
    $ORIGIN 0.0.0.0.0.0.0.0.1.6.0.0.0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa.
    
    0.1.2.0		IN	PTR	www.example.apiecamp.asia.
    1.1.2.0		IN	PTR	ns1.example.apiecamp.asia.
    2.1.2.0		IN	PTR	ns2.example.apiecamp.asia.
    3.1.2.0		IN	PTR	mail01.example.apiecamp.asia.
    4.1.2.0		IN	PTR	mail02.example.apiecamp.asia.
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  5. Change ownership of file.

    sudo chown bind:bind -R /etc/bind/
    
  6. Check if there's any syntax error:

    named-checkzone 0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa. \
        /etc/bind/db.0.0.0.6.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa
    
  7. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    
  8. Talk to your neighbor, similar to the steps mentioned earlier, they need to add your server ns2.example.apiecamp.asia. as their Secondary Authoritative DNS Server for the zone 0.0.0.1.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa..

  9. Similar 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.0.0.0.1.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa";
    };
    

    Use ctrl + o to save and press enter to confirm. And, press ctrl + x to exit.

  10. Check for any syntax error.

    named-checkconf
    
  11. Reload zones and configurations to apply the changes.

    sudo rndc reconfig
    sudo rndc status
    
  12. To 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. AXFR
    

    You can check the logs to see if transfer has been completed

    sudo tail -20 /var/log/named/bind.log
    
  13. Once BIND is running, run dig in your Recursive DNS Server to validate the configuration:

    dig @ns1.example.apiecamp.asia -x 2001:D30:AF1E:6000:61::213
    

    Similarly, test your Secondary Authoritative DNS Server:

    dig @ns2.test.apiecamp.asia -x 2001:D30:AF1E:6000:61::213
    

STOP here and show the output to the instructors

Task 6: Discussions about DNS Security

Nothing to do in the lab.

Task 7: Configure Access Control List (ACL)

  1. ACL for Recursive DNS:

    Configure ACL to allow queries from the class IP block only.

    sudo nano named.conf.options
    

    Create an ACL by adding the following statement:

    acl localnet {
    	202.249.25.128/25;
    	2001:D30:AF1E::/48;
    	localhost;
    };
    

    Then update the options statement to add the last 4 lines:

    allow-recursion { localnet; };
    allow-query { localnet; };
    allow-query-cache { localnet; };
    

    Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    
  2. ACL for Authoritative DNS Servers (both Primary and Secondary):

    Configure ACL to restrict queries to only authoritative zones and disable recursion.

    sudo nano named.conf.options
    

    Update the options statements.

    recursion no;
    allow-query { any; };
    allow-query-cache { none; };
    

    Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    
  3. Secure Zone Transfer: In your own laptop, open a terminal and run the dig command:

    dig @ns1.example.apiecamp.asia example.apiecamp.asia. AXFR
    

    You can get a full copy of the zone which is not secure.

  4. In the Primary Authoritative DNS Server, restrict who can get the zone file.

    cd /etc/bind/
    sudo nano named.conf.local
    

    Add 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;
    	};
    };
    

    Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    
  5. Verify that secure transfer works. From the Secondary Authoritative DNS Server, delete the zone file transferred previously. You need to ask your neighbor to do this as their Secondary Authoritative DNS Server is secondary server for your zone example.apiecamp.asia.

    sudo rm /var/cache/bind/db.example.apiecamp.asia
    

    Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    

    Check the log file to see the zone transfer.

    sudo tail -20 /var/log/named/bind.log
    

    Also try to manually do zone transfer using dig command:

    dig @202.249.25.211 example.apiecamp.asia. AXFR
    

    Similarly, you need to do it in your Secondary Authoritative DNS Server for your neighbor's zone.

STOP here and show the output to the instructors

Task 8: Configure Transaction Signature (TSIG)

The following should be done in the Primary Authoritative DNS Server:

  1. 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.key
    

    Check the contents of the file:

    sudo cat ns1-ns2-tsig.key
    
  2. Update named.conf.options to include the key.

    sudo nano /etc/bind/named.conf.options
    

    Append the following to the file, insert it beore the options block

    include "/etc/bind/ns1-ns2-tsig.key";
    
  3. Change ownership of file.

    sudo chown bind:bind -R /etc/bind/
    
  4. Update named.conf.local file to modify the allow-transfer part.

    sudo nano /etc/bind/named.conf.local
    

    Remove the addresses and replace with key.

    allow-transfer {
    	//202.249.25.131;
    	//2001:D30:AF1E:1000:11::132;
    	key ns1-ns2-tsig;
    };
    
  5. Check for any syntax error.

    named-checkconf
    

    Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    
  6. Send the key to the Secondary Authoritative DNS Server:

    sudo scp /etc/bind/ns1-ns2-tsig.key apie@202.249.25.131:/home/apie
    

The following should be done in the Secondary Authoritative DNS Server:

  1. Move the transferred key to the BIND working directory.

    sudo mv /home/apie/ns1-ns2-tsig.key /etc/bind
    

    Change ownership of file

    sudo chown bind:bind -R /etc/bind/
    
  2. Update named.conf.options to add the TSIG key.

    sudo nano named.conf.options
    

    Add the following include statement and server statement for the Primary Authoritative DNS Server's IP address:

    include "/etc/bind/ns1-ns2-tsig.key";
    
    server 202.249.25.211 {
    	keys { ns1-ns2-tsig; };
    };
    
    server 2001:D30:AF1E:6000:61::211 {
    	keys { ns1-ns2-tsig; };
    };
    
  3. Restart BIND and check the status.

    sudo systemctl restart bind9
    sudo systemctl status bind9
    
  4. Verify zone transfer.

    Try zone transfer without a key. This should result to Transfer failed.

    dig @202.249.25.211 example.apiecamp.asia. AXFR
    

    Try zone transfer with a key. This should be successful.

    dig @202.249.25.211 example.apiecamp.asia. AXFR -k /etc/bind/ns1-ns2-tsig.key
    

Congratulations! You have reached the end of this lab.