Setting Up a DNS Server on My Local System (BIND9)

teetoflame

Victor Okonkwo

Posted on November 22, 2024

Setting Up a DNS Server on My Local System (BIND9)

Step 1: Update the System

Get to WSL (Ubuntu for Windows).
Update the package list:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Step 2: Install BIND9

Install the DNS server software:

sudo apt install bind9 bind9utils bind9-doc -y
Enter fullscreen mode Exit fullscreen mode

Start and enable BIND9:

sudo systemctl enable bind9
sudo systemctl start bind9
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

sudo systemctl status bind9
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure BIND9 Options

Open the BIND9 options file:

sudo nano /etc/bind/named.conf.options
Enter fullscreen mode Exit fullscreen mode

Modify or add the following configuration to enable forwarding to public DNS servers:

options {
    directory "/var/cache/bind";

    // Enable recursion to allow the server to resolve queries
    recursion yes;

    // Allow queries from any IP
    allow-query { any; };

    // Use Google's public DNS servers as forwarders
    forwarders {
        8.8.8.8;
        8.8.4.4;
    };

    // Disable authoritative answers for NXDOMAIN responses
    auth-nxdomain no;

    // Listen on all IPv6 interfaces
    listen-on-v6 { any; };

    // Optional: Enable DNSSEC validation
    dnssec-validation auto;
};
Enter fullscreen mode Exit fullscreen mode

Save the file and restart BIND9:

sudo systemctl restart bind9
Enter fullscreen mode Exit fullscreen mode

Step 4: Configure DNS Zones

Open the local configuration file for zones:

sudo nano /etc/bind/named.conf.local
Enter fullscreen mode Exit fullscreen mode

Add the forward and reverse lookup zones for your domain (use your local IP and domain name of choice):

zone "victorokonkwo.com" {
    type master;
    file "/etc/bind/db.victorokonkwo.com";
};

zone "74.31.172.in-addr.arpa" {
    type master;
    file "/etc/bind/db.172";
};
Enter fullscreen mode Exit fullscreen mode

Save the file.

Step 5: Create Zone Files

Create the forward zone file (use your local IP and domain name of choice):

sudo nano /etc/bind/db.victorokonkwo.com
Enter fullscreen mode Exit fullscreen mode

Add the following content:

;
; BIND data file for victorokonkwo.com
;
$TTL    604800
@       IN      SOA     ns1.victorokonkwo.com. admin.victorokonkwo.com. (
                          2023111801 ; Serial
                          604800     ; Refresh
                          86400      ; Retry
                          2419200    ; Expire
                          604800 )   ; Negative Cache TTL

        IN      NS      ns1.victorokonkwo.com.
ns1     IN      A       172.31.74.133
@       IN      A       172.31.74.133
www     IN      A       172.31.74.133
Enter fullscreen mode Exit fullscreen mode

Create the reverse zone file:

sudo nano /etc/bind/db.172
Enter fullscreen mode Exit fullscreen mode

Add the following content:

;
; Reverse DNS file for 172.31.74.0/24
;
$TTL    604800
@       IN      SOA     ns1.victorokonkwo.com. admin.victorokonkwo.com. (
                          2023111801 ; Serial
                          604800     ; Refresh
                          86400      ; Retry
                          2419200    ; Expire
                          604800 )   ; Negative Cache TTL

        IN      NS      ns1.victorokonkwo.com.
133     IN      PTR     victorokonkwo.com.
Enter fullscreen mode Exit fullscreen mode

Step 6: Test the Configuration

Check the syntax of the configuration files:

sudo named-checkconf
sudo named-checkzone victorokonkwo.com /etc/bind/db.victorokonkwo.com
sudo named-checkzone 74.31.172.in-addr.arpa /etc/bind/db.172
Enter fullscreen mode Exit fullscreen mode

Restart the BIND9 service:

sudo systemctl restart bind9
Enter fullscreen mode Exit fullscreen mode

Step 7: Test DNS Resolution

Use the dig tool to test the setup:

dig @localhost victorokonkwo.com
dig @localhost www.victorokonkwo.com
dig -x 172.31.74.133
Enter fullscreen mode Exit fullscreen mode

Verify that the correct responses are returned.

Step 8: Configure Firewall

Allow DNS traffic through the firewall:

sudo ufw allow 53
sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

💖 💪 🙅 🚩
teetoflame
Victor Okonkwo

Posted on November 22, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related