How to Set Up DNS with BIND and Web Server on AWS

A comprehensive guide to configure DNS and web server using Bind, AWS, and Let's Encrypt

Introduction

This guide walks you through the process of setting up DNS on a server using BIND and configuring a web server with Apache on AWS. We'll also secure the web server with SSL using Let's Encrypt. Follow the steps to ensure proper DNS resolution and server accessibility.

Step 1: Setting Up DNS Server

  1. Install BIND on your server:
  2. sudo apt update
    sudo apt install bind9 bind9utils bind9-doc
  3. Configure DNS with Zone Files:
  4. Create a directory to store your zone files:

    sudo mkdir -p /etc/bind/zones

    Create the zone file for your domain:

    sudo vi /etc/bind/zones/db.soham.sbs

    In the file, define the A records for your domain:

    $TTL    604800
    @       IN      SOA     ns1.soham.sbs. admin.soham.sbs. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
    
    ; Name servers
    @       IN      NS      ns1.soham.sbs.
    
    ; A records
    @       IN      A       3.7.174.57
    ns1     IN      A       15.206.90.100
    ns2     IN      A       15.206.90.100
    www     IN      A       3.7.174.57
  5. Configure BIND to load the zone file:
  6. sudo vi /etc/bind/named.conf.local

    Add this configuration:

    zone "soham.sbs" {
        type master;
        file "/etc/bind/zones/db.soham.sbs";
    };
  7. Restart BIND service:
  8. sudo systemctl restart bind9

Step 2: Set up Name Servers with Hostinger

  1. Log into your Hostinger account:
  2. Navigate to the domain management section where you have the domain registered.

  3. Configure your name servers:
  4. Add the following name servers:

    ns1.soham.sbs
    ns2.soham.sbs

    Make sure the name servers point to the correct IPs of your BIND server (e.g., 15.206.90.100).

  5. Verify the changes:
  6. Use tools like dig to verify that your domain resolves correctly:

    dig @15.206.90.100 soham.sbs

Step 3: Configuring Apache Web Server

  1. Install Apache on your web server:
  2. sudo apt update
    sudo apt install apache2
  3. Create Virtual Host Configuration:
  4. Create a virtual host file for your domain:

    sudo vi /etc/apache2/sites-available/soham.sbs.conf

    In the file, configure your web server settings:

    <VirtualHost *:80>
        ServerAdmin admin@soham.sbs
        DocumentRoot /var/www/soham.sbs
        ServerName soham.sbs
        ServerAlias www.soham.sbs
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
  5. Enable the site and restart Apache:
  6. sudo a2ensite soham.sbs.conf
    sudo systemctl restart apache2

Step 4: Installing Let's Encrypt SSL

  1. Install Certbot and the Apache plugin:
  2. sudo apt install certbot python3-certbot-apache
  3. Obtain SSL certificates for your domain:
  4. sudo certbot --apache -d soham.sbs -d www.soham.sbs
  5. Test SSL Certificate Renewal:
  6. sudo certbot renew --dry-run

Step 5: Final Verification

  1. Verify DNS:
  2. Ensure your domain resolves correctly to your web server's IP:

    dig @15.206.90.100 soham.sbs
  3. Verify SSL:
  4. Check if SSL is installed by accessing your site via HTTPS in a browser.

Author: Tanmoy Chatterjee
Date: May 2025