APIE Camp – DNS Configuration Lab

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

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

    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 -lah /etc/bind
    $ ls -lah /usr/share/dns
    $ ls -lah /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 /var/log/named/xfer.log
    $ sudo chown bind:bind -R /var/log/named

    Check the files and their permissions:

    $ ls -lah /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;
        };
        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.

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

    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"?
       Hint: Query the parent domain to get NS info.
     - What are the available PTR records 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:

     + 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::4
  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. (
                            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.

  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.

  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. Check for any syntax error.

    $ named-checkconf
  4. 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. (
                            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.

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

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

    $ sudo rndc reconfig
    $ sudo rndc status
  7. Talk to your neighbor, similar to the step 2 and 4 mentioned earlier, they need to

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

    or, with IPv6

    $ dig @2001:d30:af1e:1000:11::131 test.apiecamp.asia. AXFR

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

  9. 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)

STOP here and show the output to the instructors


Task 5: Configure Reverse DNS

5.1. Configure Reverse DNS for IPv4

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

  2. 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.arpa

    Open the configuration file:

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

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

  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.240.25.249.202.in-addr.arpa

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

  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 240/28.128/25.25.249.202.in-addr.arpa. \
        /etc/bind/db.240.25.249.202.in-addr.arpa
  7. Reload zones and configurations to apply the changes.

    $ sudo rndc reconfig
    $ sudo rndc status
  8. 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.128.25.249.202.in-addr.arpa";
    };

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

  9. Talk to your neighbor, and make sure they made similar configuration for your zone.

  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

    or, with IPv6

    $ dig @2001:d30:af1e:1000:11::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/xfer.log

    Talk to your neighbor, and make sure they do the same for your zone.

  13. 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.247

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

  3. Check for any syntax error.

    $ named-checkconf
  4. Create a corresponding zone file

    $ cd /etc/bind
    $ sudo nano db.8000.af1e.d30.2001.ip6.arpa

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

  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.8.E.1.F.A.0.3.D.0.1.0.0.2.ip6.arpa. \
        /etc/bind/db.8000.af1e.d30.2001.ip6.arpa
  7. Reload zones and configurations to apply the changes.

    $ sudo rndc reconfig
    $ sudo rndc status
  8. 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.1000.af1e.d30.2001.ip6.arpa";
    };

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

  9. Talk to your neighbor, and make sure they made similar configuration for your zone.

  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

    or, 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. AXFR

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

    $ sudo tail -20 /var/log/named/xfer.log

    Talk to your neighbor, and make sure they do the same for your zone.

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

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

    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 bind9
  3. Insecure Zone Transfer: In your own laptop, open a new terminal and run the dig command:

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

    Alert: You can get a full copy of the zone which is NOT secure.

    Keep this terminal open for now.

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

    Check configuration and restart BIND and check the status.

    $ named-checkconf
    $ sudo systemctl restart bind9
    $ sudo systemctl status bind9

    Go to the previously opened terminal and run the same dig command for insecure zone transfer:

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

    This time, the zone transfer fails. You might find the output similar as below:

    ; Transfer failed.
  5. In the Secondary Authoritative DNS Server, delete the zone file transferred previously.

    $ sudo rm /var/cache/bind/db.test.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/xfer.log

    Also try to manually do zone transfer using dig command:

    $ dig @202.249.25.131 test.apiecamp.asia. AXFR

    Talk to your neighbor, and make sure they do the same for your zone.

  6. Discussions:

    - In Task #5, was the transfer successful? Why?
    - In Task #4, why the transfer failed?
    

STOP here and show the output to the instructors


Task 8: Secure DNS with 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.

    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.132;
        //2001:D30:AF1E:1000:11::132;
        key ns1-ns2-tsig;
    };
  5. Check the configuration and restart BIND and check the status.

    $ named-checkconf
    $ 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.132:/home/apie

    Talk to your neighbor, and make sure they do the same.

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

  7. 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/
  8. Try zone transfer as you did earlier in the previous section:

    $ dig @202.249.25.131 test.apiecamp.asia. AXFR

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

    This should be successful. But why?

  9. Update named.conf.options to add the TSIG key.

    $ sudo nano named.conf.options

    Append 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; };
    };
  10. Check configuration and restart BIND and check the status.

    $ named-checkconf
    $ sudo systemctl restart bind9
    $ sudo systemctl status bind9
  11. Verify 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.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/xfer.log

    Talk 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