This tutorial will cover how to set up an internal DNS server using the BIND name server software (BIND9) on Ubuntu 18.04 (install bind on Ubuntu) that your servers can use to resolve private hostnames and private IP addresses.
BIND (Berkely Internet Name Domain) is a popular software for translating domain names into IP addresses and is usually found on Linux VPS & Dedicated Servers. This article will explain the basic concepts of DNS BIND and analyze the associated files required to successfully set up your DNS BIND server.
Install BIND on Ubuntu 18.04
Before we install BIND, we will enter the following command to update the repository packages.
sudo apt-get update
Now that the packages are updated, we can enter the following command to install BIND 9 from the official Ubuntu package repository.
sudo apt-get install bind9
Once the installation completes, you will see a success message as follows:
* Starting domain name service... bind9 [OK]
BIND configurations
Now that we have successfully installed BIND on the server, the next step is to make the appropriate configurations. The following configurations are done to resolve your domain to the server. First, we will enter the named.conf.local file using the nano command:
nano /etc/bind/named.conf.local
Enter the following configurations into the file:
zone "1gbits.com" {
type master;
file "/etc/bind/zones/1gbits.com.db";
allow-transfer { 10.198.200.112; };
};
zone "3.2.1.in-addr.arpa" {
type master;
file "/etc/bind/zones/rev.3.2.1.in-addr.arpa";
allow-transfer { 10.198.200.112; };
};
However, note that in the above configuration text, you will need to make some changes that will be suitable for your server. Instead of 1gbits.com, you should add your domain name and corresponding TLD.
Another thing to note is to replace the IP address (10.198.200.112) with the IP address of your server. Once the necessary values have been updated, you can save and exit the nano text editor.
To do this Ctrl + x > y > Enter.
The configurations in the named.conf.local file has been completed. Now let’s move on to the next part, to make the database file. So first enter the bind directory using the cd command as follows:
cd /etc/bind
Create a new directory called “zones” inside it using this command:
mkdir zones
Enter the newly created directory and create the databases file. Be sure to change the domain.com with the name corresponding to you:
cd zones
nano 1gbits.com.db
Now in the opened text editor, add the following text:
; BIND data file for 1gbits.com
;
$TTL 14400
@ IN SOA ns1.1gbits.com. host.1gbits.com. (
201006601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800) ; Default TTL
;
1gbits.com. IN NS ns1.1gbits.com.
1gbits.com. IN NS ns2.1gbits.com.
1gbits.com. IN MX 10 mail.1gbits.com.
1gbits.com. IN A 10.198.200.112
ns1 IN A 10.198.200.112
ns2 IN A 10.198.200.112
www IN CNAME 1gbits.com.
mail IN A 10.198.200.112
ftp IN CNAME 1gbits.com.
1gbits.com. IN TXT "v=spf1 ip4:10.198.200.112 a mx ~all"
mail IN TXT "v=spf1 a -all"
As you can see here, you should replace the domain name (1gbits.com) with your domain name and then for the IP addresses, be sure to change it to your server IP address. If you have two IPs, you can replace “ns2 IN A xxx.xxx.xxx.xxx” with your second IP address. Otherwise, simply use the same IP.
Once the necessary configurations have been updated, you can save and exit the nano text editor.
To do this Ctrl + x > y > Enter.
The next part of setting up BIND on Ubuntu 18.04 is to define the reverse DNS lookup. To do this, we will be editing another configuration file.
nano /etc/bind/zones/rev.3.2.1.in-addr.arpa
Once the file is opened, enter the following text. Don’t forget to replace “1gbits.com” with your own server’s hostname.
@ IN SOA 1gbits.com. host.1gbits.com. (
2010081401;
28800;
604800;
604800;
86400 );
IN NS ns1.1gbits.com.
4 IN PTR 1gbits.com.
Once the necessary configurations have been updated, you can save and exit the nano text editor.
To do this Ctrl + x > y > Enter.
As the final configuration, we will add a single line to the following configuration file:
nano /etc/resolv.conf
Add the following at the beginning of the configuration file before any text. (Replace 1gbits.com with your domain name)
search 1gbits.com
Save and exit the nano text editor by pressing Ctrl + x > y > Enter.
Now all the configurations are done, and BIND is ready to use. However, for extra measures, it is recommended to restart the BIND 9 service using the following command:
sudo systemctl restart bind9
Testing the DNS
Now we will try to test your server's DNS by adding a a tool known as “DNS Utility”. You can install this by entering the following command on your terminal:
apt-get install dnsutils
Once the installation is finished, enter the following:
dig 1gbits.com
If everything is set up correctly, you will see an output similar to the one below:
; <<>> DiG 9.11.3-1ubuntu1.15-Ubuntu <<>> 1gbits.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53995
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;1gbits.com. IN A
;; ANSWER SECTION:
1gbits.com. 158 IN A 104.21.91.235
1gbits.com. 158 IN A 172.67.181.233
;; Query time: 17 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Wed Jun 02 02:29:21 PDT 2021
;; MSG SIZE rcvd: 71
Conclusion
This tutorial sets up BIND 9 on your Ubuntu 18.04 server. If you're using a VPS with Ubuntu, the instructions will be directly applicable. Note that once you set up BIND, you should also pay close attention to the BIND9 configurations and set it up according to the abovementioned steps. If you encounter any problems along the way, be sure to let us know in the comments below.
For those who require remote desktop access, you might also need to configure an Ubuntu RDP server. Setting up RDP on Ubuntu involves additional steps that are not covered in this tutorial but are crucial for accessing your server remotely in a graphical environment.
People also read: