Skip to content

Private DNS server using BIND

To set up a private DNS server on Linux using BIND (Berkeley Internet Name Domain), you can follow these steps:

  1. Update the package lists and install BIND by running the following commands in the terminal:

    sudo apt update
    sudo apt install bind9
    

  2. Configure BIND by editing the main configuration file /etc/bind/named.conf.options. Open the file using a text editor:

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

  3. Inside the file, you can modify the options section to include the IP addresses of your DNS server. You can add the following lines at the end of the options section:

    forwarders {
        8.8.8.8;
        8.8.4.4;
    };
    
    These IP addresses are Google's public DNS servers, which will be used as forwarders for external DNS queries if your DNS server doesn't have the necessary information.

  4. Create a new zone file for your domain. Zone files contain the DNS records for a specific domain. In this example, we will create a zone file for a domain named "example.com":

    sudo vim /etc/bind/named.conf.local
    
    Add the following lines to the file:
    zone "example.com" {
        type master;
        file "/etc/bind/db.example.com";
    };
    

  5. Create the zone file /etc/bind/db.example.com and add the necessary DNS records. Replace "your_IP_address" with the IP address of your DNS server:

    sudo vim /etc/bind/db.example.com
    
    Add the following lines to the file:
    $TTL 86400
    @       IN      SOA     ns1.example.com. admin.example.com. (
                           2023062401     ; Serial
                           3600           ; Refresh
                           1800           ; Retry
                           604800         ; Expire
                           86400 )        ; Minimum TTL
    
    @       IN      NS      ns1.example.com.
    ns1     IN      A       your_IP_address
    

  6. Restart the BIND service to apply the changes:

    sudo service bind9 restart
    

  7. Configure your DNS client machines to use your private DNS server. You can usually do this by modifying the DNS server settings in the network configuration of each client.

That's it! You have now set up a private DNS server using BIND on Linux. You can add additional DNS records to the zone file to suit your needs. Remember to replace "example.com" with your actual domain name and "your_IP_address" with the IP address of your DNS server.