How Install DNS Server in Linux?

//

Scott Campbell

How to Install DNS Server in Linux

If you’re looking to set up a DNS server on your Linux machine, you’ve come to the right place. In this tutorial, we’ll guide you through the process of installing and configuring a DNS server on your Linux system. Let’s get started!

Step 1: Update Your System

Before we begin, it’s always a good idea to update your system to ensure that you have the latest software packages and security patches. Open your terminal and run the following command:

sudo apt update && sudo apt upgrade -y

This will update your package lists and upgrade any outdated packages on your system.

Step 2: Install BIND9

The most popular DNS server used in Linux distributions is BIND9. To install BIND9, open your terminal and enter the following command:

sudo apt install bind9 -y

This will download and install the BIND9 package on your system.

Step 3: Configure BIND9

Once BIND9 is installed, you need to configure it to suit your needs. The configuration file for BIND9 is located at /etc/bind/named.conf.options. Open the file using a text editor with administrative privileges:

sudo nano /etc/bind/named.options

In this file, you can specify various options such as forwarders, listening interfaces, and more. Make sure to read the comments in the file for guidance on each option. Once you’ve made all necessary changes, save and exit the editor.

Step 4: Create Zone Files

In order for your DNS server to resolve domain names, you need to create zone files. These files contain the information about your domain names and their corresponding IP addresses.

Zone files are stored in the /etc/bind/ directory. Each zone file has a specific format and consists of resource records (RRs) that define various DNS records such as A, CNAME, MX, and more.

To create a new zone file, navigate to the /etc/bind/ directory and create a new file using a text editor:

cd /etc/bind/
sudo nano example.com.zone

Replace example.com with your actual domain name. Inside the file, you’ll need to define the necessary resource records for your domain. Here’s an example of an A record:

$TTL 1d
@ IN SOA ns1.example. admin.

(
2022030301 ; Serial
3h ; Refresh
15m ; Retry
1w ; Expire
1d ; Minimum TTL
)
@ IN NS ns1. @ IN A 192.168.0.10

In this example, we’ve defined an A record for the domain example.com with the IP address 192.10.

Step 5: Configure Zone Files in named.options

After creating your zone files, you need to configure them in the BIND9 configuration file (/etc/bind/named.options). Open the file using a text editor:

In this file, add the following lines at an appropriate place:

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

Replace example.com with your actual domain name and /etc/bind/example.zone with the path to your zone file.

Step 6: Restart BIND9

Once you’ve made all the necessary configurations, you need to restart the BIND9 service for the changes to take effect. Run the following command in your terminal:

sudo systemctl restart bind9

This will restart the DNS server and load the new configurations.

Step 7: Test Your DNS Server

To test your DNS server, you can use tools like nslookup or dig. For example, to query an A record for a domain, run the following command:

nslookup example.com

If everything is set up correctly, you should see the IP address associated with the domain name.

Congratulations!

You have successfully installed and configured a DNS server on your Linux machine. Now you can manage your own DNS records and resolve domain names within your network.

  • Note:
    • If you’re using a firewall on your system, make sure to allow incoming connections on port 53 (UDP/TCP) for DNS traffic.
    • If you want to use your DNS server as a caching resolver, consider configuring forwarders in /etc/bind/named.
    • You can add additional resource records (RRs) in your zone files to suit your needs.

Thank you for following along with this tutorial. We hope you found it helpful!