A DNS server is a computer that acts as a translator between the IP address and the domain name. It is responsible for translating the domain name into its corresponding IP address. By setting up a DNS server on Ubuntu, you will be able to manage your DNS records and improve the performance of your website.
Are you looking for an easy way to set up a DNS server on Ubuntu? Well, you have come to the right place! In this blog article, I will provide you with a comprehensive step-by-step guide on how to quickly and easily set up a DNS server on Ubuntu.
Whether you are a beginner or an expert, this guide will help you set up a DNS server on Ubuntu in no time. So, let’s get started!
Step 1: Install Packages
The very first thing you need to do when setting up a DNS server on Ubuntu is to install the DNS software. It’s a simple process. All you have to do is type a command into the computer, and it will install the software you need to get your DNS server running.
sudo apt update
sudo apt install bind9 -y
Step 2: Create Forward Zone File
A forward DNS zone is responsible for translating the domain name into the corresponding IP address. To set up a forward DNS zone, you need to create a zone file for each domain that you want the DNS server to manage. For example, if your domain is example.net, then create the zone files by running the following command:
sudo nano /etc/bind/example.net.zone
Add the following content
; Forward Zone file for example.net
$TTL 14400
@ 86400 IN SOA ns1.example.net. webmaster.example.net. (
3013040200 ; serial, todays date+todays
86400 ; refresh, seconds
7200 ; retry, seconds
3600000 ; expire, seconds
86400 ; minimum, seconds
)
ns1 IN A 192.168.1.212
ns2 IN A 192.168.1.212
example.net. 86400 IN NS ns1.example.net.
example.net. 86400 IN NS ns2.example.net.
example.net. IN A 192.168.1.100
www IN CNAME example.net.
Save the file and close it.
Then use named-checkzone command to verify the syntax of the configuration file.
sudo named-checkzone example.net /etc/bind/example.net.zone
On successful, an OK message will appear on the output screen.
Step 3: Create Reverse Zone File (Optional)
Generally, reverse DNS configuration is not required, but in some cases, you may need to configure it. This is used to resolve the domain name corresponding to an IP address. For example, we are using the 192.168.1.0/32 IP range in our intranet. Create reverse DNS file named /etc/bind/db.1.168.192 with following content.
sudo vi /etc/bind/db.1.168.192
and add following content
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA ns1.example.net. root.ns1.example.net. (
3013040200 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.example.net.
100 IN PTR example.net.
101 IN PTR otherdomain.com.
Save the file and verify the file syntax:
named-checkzone 192.168.01.0/32 /etc/bind/db.1.168.192
On successful, an OK message will appear on the output screen.
Step 4: Update Bind9 Main Configuration
The next step in setting up a DNS server on Ubuntu is to configure the DNS server. You can do this by editing the configuration file. You can find the configuration file by running the following command:
sudo nano /etc/bind/named.conf.local
Append following content
zone "example.net" IN {
type master;
file "/etc/bind/example.net.zone";
};
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.1.168.192";
};
Save the file and check the configuration files:
named-checkconf /etc/bind/named.conf.local
named-checkconf /etc/bind/named.conf
On successful, nothing will appear on the output screen.
Step 5: Restart bind9 Service
After verifying all configuration files, restart the bind9 service to apply changes with:
sudo systemctl restart bind9
then check its status using:
sudo systemctl status bind9
Output● named.service - BIND Domain Name Server Loaded: loaded (/lib/systemd/system/named.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2024-01-04 12:17:31 IST; 2h 16min ago Docs: man:named(8) Process: 10725 ExecStart=/usr/sbin/named $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 10726 (named) Tasks: 4 (limit: 2271) Memory: 5.6M CPU: 146ms CGroup: /system.slice/named.service └─10726 /usr/sbin/named -u bind
The bind9 service should be active and running.
Step 6: Testing the DNS Server
Once you have configured the DNS server, you need to test it to make sure that it is working properly. You can do this by running the following command:
dig your_domain.com
This command will query the DNS server for information about the domain example.com. If the DNS server is configured correctly, you should be able to see the IP address of the domain in the output.
Verify Forward Zone:
dig example.net
Output; <<>> DiG 9.16.1-Ubuntu <<>> example.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42007 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ; COOKIE: b8e8bae7636ea5990100000062665dfb3fce096db82322ba (good) ;; QUESTION SECTION: ;example.net. IN A ;; ANSWER SECTION: example.net. 14400 IN A 192.168.1.100 ;; Query time: 4 msec ;; SERVER: 192.168.1.212#53(192.168.1.212) ;; WHEN: Mon Apr 25 14:04:08 IST 2022 ;; MSG SIZE rcvd: 84
Verify Reverse Zone:
dig -x 192.168.1.100
Output; <<>> DiG 9.16.1-Ubuntu <<>> -x 192.168.1.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26175 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ; COOKIE: df64db0c13af750e0100000062665e1e52dc99d0a2d5dd41 (good) ;; QUESTION SECTION: ;100.1.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 100.1.168.192.in-addr.arpa. 604800 IN PTR example.net. ;; Query time: 0 msec ;; SERVER: 192.168.1.212#53(192.168.1.212) ;; WHEN: Mon Apr 25 14:04:43 IST 2022 ;; MSG SIZE rcvd: 108
Conclusion
Setting up a DNS server on Ubuntu is a relatively straightforward process. In this blog article, I have provided you with a comprehensive step-by-step guide on how to quickly and easily setup a DNS server on Ubuntu, Debian and Linux Mint. I hope this guide was helpful and that you were able to set up a DNS server on Ubuntu without any issues.
If you have any questions or comments, please feel free to leave them in the comments section below. I would love to hear your feedback!
2 Comments
another site with no help for beginners don’t understand what’s suppose to be done or how to
How did you disable / remove dnsmasq so that port 53 was available for bind9 to use as a dns server?
This is a problem on Linux Mint 17 which puts bind9 on port 953 when dnsmasq is already installed. (it is installed and active and attached to port 53 by default when you install Linux Mint 17 )
I added bind9 to my system and am now experiencing 15 second or longer delays in responses to queries from remote hosts. This delay blows mail services out of the water and delays client access to the web server. My bind9 server is being used as an authoritative dns for my domain so this affects everything associated to the domain.