Network & System

Home / DNS

Domain Name System

Domain Name System

4 comments

DNS (Domain Name System) is a hierarchical decentralized naming system for computers, services, or any resource connected to the Internet or a private network. It translates easily memorizable domain names to the numerical IP addresses needed for locating and identifying computer services and devices with the underlying network protocols.

Functions of DNS:

  • Name Resolution: DNS resolves domain names to IP addresses, allowing users to access websites, services, and resources using human-readable names instead of numerical IP addresses.
  • IP Address Assignment: DNS also assigns IP addresses to domain names, enabling communication between devices on the internet or within a private network.
  • Load Balancing: DNS can distribute incoming network traffic across multiple servers to improve performance, enhance redundancy, and achieve high availability.nal entities see only the public IP address, making it more difficult for attackers to directly access devices within the private network.
  • Email Routing: DNS is used to route emails by mapping email domain names to mail server IP addresses through MX (Mail Exchange) records.
  • Domain Registration: DNS facilitates the registration and management of domain names through domain registrars, enabling individuals and organizations to claim unique internet identities.
  • Caching: DNS servers cache DNS lookup results to improve performance and reduce the load on DNS infrastructure by storing recently accessed domain records.

Configuring DNS (Domain Name System) on Ubuntu involves setting up a DNS server, typically using BIND (Berkeley Internet Name Domain) software, and configuring the server to resolve domain names for clients on the network. Here's a basic guide to configure DNS on Ubuntu:

  • Step 1: Install BIND (DNS Server) Package:

    First, update the package index and install the BIND package:

    sudo apt update
    sudo apt install bind9
    
  • Step 2: Configure BIND:
    • Edit Configuration File: Open the BIND configuration file (/etc/bind/named.conf.options) in a text editor:
    • sudo nano /etc/bind/named.conf.options
    • Configure Forwarders (Optional): Add DNS servers provided by your ISP or other public DNS servers to forward DNS queries if the local DNS server can't resolve them directly:
    • forwarders {
                              8.8.8.8;
                              8.8.4.4;
                          };
                          
    • Allow Querying from Local Network: Ensure BIND allows querying from the local network by adding or modifying the allow-query directive:
    • allow-query { any; };
    • Save and Close the File: Press Ctrl + X, then Y, and Enter to save and exit.
  • Step 3: Create DNS Zone Files:
    • Forward Lookup Zone: Create a forward lookup zone file (/etc/bind/db.example.com):
    • sudo cp /etc/bind/db.local /etc/bind/db.example.com
                                  sudo nano /etc/bind/db.example.com
                              
    • Edit Zone File: Update the zone file with your domain information. Replace example.com with your domain name:
    • ;
                                  ; BIND data file for example.com
                                  ;
                                  $TTL    604800
                                  @       IN      SOA     ns.example.com. admin.example.com. (
                                                                     3         ; Serial
                                                                604800         ; Refresh
                                                                 86400         ; Retry
                                                               2419200         ; Expire
                                                               604800 )       ; Negative Cache TTL
                                  ;
                                  @       IN      NS      ns.example.com.
                                  @       IN      A       192.168.1.10
                                  ns      IN      A       192.168.1.10
                                  
    • Reverse Lookup Zone (Optional): If you need reverse DNS lookup, create a reverse lookup zone file (/etc/bind/db.192):
    • sudo cp /etc/bind/db.127 /etc/bind/db.192
                                  sudo nano /etc/bind/db.192
                                  
    • Edit Reverse Zone File: Update the reverse zone file with your network information. Replace 1.168.192 with your network address in reverse order (e.g., for 192.168.1.0, use 1.168.192):
    •                                 ;
                                  ; BIND reverse data file for local loopback interface
                                  ;
                                  $TTL    604800
                                  @       IN      SOA     ns.example.com. admin.example.com. (
                                                                     2         ; Serial
                                                                604800         ; Refresh
                                                                 86400         ; Retry
                                                               2419200         ; Expire
                                                                604800 )       ; Negative Cache TTL
                                  ;
                                  @       IN      NS      ns.example.com.
                                  10      IN      PTR     ns.example.com.
      
                                  
    • Save and Close the Files: Press Ctrl + X, then Y, and Enter to save and exit.
  • Step 4: Update BIND Configuration:
    • Edit BIND Configuration File: Open the BIND configuration file (/etc/bind/named.conf.local) in a text editor:
    • sudo nano /etc/bind/named.conf.local
    • Add Zone Configuration: Add zone configuration for your domain:
    • zone "example.com" {
                          type master;
                          file "/etc/bind/db.example.com";
                          };
                          
    • Add Reverse Zone Configuration (Optional): If you created a reverse lookup zone, add its configuration:
    • zone "1.168.192.in-addr.arpa" {
                              type master;
                              file "/etc/bind/db.192";
                          };
                          
    • Save and Close the File: Press Ctrl + X, then Y, and Enter to save and exit.
  • Step 5: Restart BIND:
    sudo systemctl restart bind9
  • Step 6: Update DNS Resolver Configuration (Optional):

    Edit the DNS resolver configuration file (/etc/resolv.conf) to point to your local DNS server:

    sudo nano /etc/resolv.conf

    Update the nameserver directive to point to your DNS server IP address:

    nameserver 192.168.1.10

    Save and close the file.

  • Step 7: Test DNS Resolution:

    Use the nslookup or dig command to test DNS resolution:

    nslookup example.com

That's it! You've now configured a DNS server on your Ubuntu system. Remember to replace example.com and 192.168.1.10 with your actual domain name and server IP address.

Prajan Dangol.

Leave a comment