Install and configure DNS in Ubuntu

For those who do not know that DNS is a domain name system, which is used to convert the name to the PC's IP address and back. Thus, when you enter the web page address in the browser, the domain name system converts it to the IP address of the hosting hosting the specific domain. In this article we will analyze in detail how to install and configure the Ubuntu DNS server. Let's get started. Go!

From this article, you will learn exactly how to install and configure the Ubuntu DNS server correctly.

First stage

The first stage is installation. It is recommended to use the Bind9 server. To do this, go to the terminal and enter:

sudo apt install bind9

Next, you need to generate a key to update the records or use an existing one. To generate it, run:

dnssec-keygen -a HMAC-MD5 -b 128 -r / dev / urandom -n USER DHCP_UPDATER

to display the key on the screen, enter

cat Kdhcp_updater. *. private | grep Key

You must save it, since you will need the secret key in the future.

To use the existing key, add an entry to /etc/bind/named.conf. First you need to do:

sudo nano /etc/bind/named.conf,

and then add the line to the file:

include "/etc/bind/rndc.key";

Bind9 Setup

Now let's move on to setting up Bind9. Open the configuration file by typing in the terminal:

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

and add the following lines there:

forwarders {

8.8.8.8;

8.8.4.4;

};

listen-on {

127.0.0.1;

192.168.0.1;

};

forwaders is a superior DNS used in cases when the URL request cannot be found in the database.

listen-on - addresses through which your DNS server will be serviced.

Restart bind9

Next, you need to restart bind9. To do this, write in the terminal:

sudo service bind9 restart

Now specify the forward and reverse lookup zones, and also enter them in the bind9 configuration. The baseline data are as follows:

Domain Name - dom

Server IP Address - 192.168.0.1

Server name - ns.dom

To configure the forward lookup zone, create the appropriate file and copy its sample:

sudo cp /etc/bind/db.local /var/lib/bind/db.dom

further open with the command:

sudo nano /var/lib/bind/db.dom

and edit as follows:

$ ORIGIN.

$ TTL 604800; 1 week

dom IN SOA ns.dom. root.ns.dom. (

201605277; serial

604800; refresh (1 week)

86400; retry (1 day)

2419200; expire (4 weeks)

604800; minimum (1 week)

)

@ IN NS ns.dom.

@ IN A 192.168.0.1

@ IN AAAA :: 1

$ ORIGIN dom.

$ TTL 604800; 1 week

ns IN A 192.168.0.1

Next, you need to configure the reverse. To do this, make a copy of the live view file you just created:

sudo cp /var/lib/bind/db.dom /var/lib/bind/db.192.dom

open it with the command:

sudo nano /var/lib/bind/db.192.dom

and also edit:

$ ORIGIN.

$ TTL 604800; 1 week

0.168.192.in-addr.arpa IN SOA ns.dom. root.ns.dom. (

2016052655; serial

604800; refresh (1 week)

86400; retry (1 day)

2419200; expire (4 weeks)

604800; minimum (1 week)

)

@ IN NS ns.

$ ORIGIN 0.168.192.in-addr.arpa.

$ TTL 604800; 1 week

1 IN PTR ns.dom.

To configure zones in the bind9 configuration, you need to open the configuration file with the command:

sudo nano /etc/bind/named.conf.local,

and then two variants of succession appear again. If you created the secret key in the first way, write:

key DHCP_UPDATER {

algorithm HMAC-MD5.SIG-ALG.REG.INT;

secret "9DxMmNw7J813qviXajG7rQ ==";

};

// direct view zone

zone "dom" {

type master;

file "/var/lib/bind/db.dom";

allow-update {key DHCP_UPDATER; };

};

// reverse lookup zone

zone "0.168.192.in-addr.arpa" {

type master;

file "/var/lib/bind/db.192";

allow-update {key DHCP_UPDATER; };

};

key DHCP_UPDATER - information about the secret key that you recorded at the very beginning (you must write it in quotes). If earlier, you used the second method, enter:

// direct view zone

zone "dom" {

type master;

file "/var/lib/bind/db.dom";

allow-update {key rndc-key; };

};

// reverse lookup zone

zone "3.168.192.in-addr.arpa" {

type master;

file "/var/lib/bind/db.192";

allow-update {key rndc-key; };

};

where key rndc-key is the key data taken from the system, and zone “dom” is the data on the domain name system application zone. It remains to save the whole thing, then close and restart bind9 by typing:

sudo /etc/init.d/bind9 restart

Checking the operation of the domain name system

Now check the operation of the domain name system:

nslookup ns.dom

as a result, you should get something like:

Server: 127.0.0.1

Address: 127.0.0.1 # 53

Name: ns.dom

Address: 192.168.0.1

As you can see, the live view zone is working. Now make sure that the reverse also works:

nslookup 192.168.0.1

As a result, you should see:

Server: 127.0.0.1

Address: 127.0.0.1 # 53

1.0.168.192.in-addr.arpa name = ns.dom.

As a result, you should get the server name by entering its IP. If you have everything displayed in this way, then the setting was made correctly. If not, then the mistake was made earlier.

Configure Dynamic Update

To configure a dynamic update, open /etc/dhcp/dhcpd.conf by running the following command:

sudo nano /etc/dhcp/dhcpd.conf

The ddns-update-style none string should be replaced with the ddns-update-style interim. Next, add the line update-static-leases on, which is responsible for creating zones for clients with a static IP. Make sure that the option domain-name contains the domain name “dom”. In the “key” line should be the name of your key (if you have previously chosen the first method, write down DHCP_UPDATER, if the second, then rndc-key), contains your secret key. To view the rndc-key run:

cat /etc/bind/rndc.key | grep secret

the result should be something like this:

secret "2mu11eRajAdm4KV0x0Pmcg ==";

On this with the DHCP settings everything. Now you need to restart bind9 and dhcp. To do this, write down:

sudo service bind9 restart

sudo service isc-dhcp-server restart

It remains to check how everything works. Start the client machine that is online with the server. After launch, the machine will receive an IP from DHCP, and it, in turn, will create a client-pc.dom entry. For the query "nslookup client_name machine", you should get an answer. After restarting the server, it will be possible to view the forward and reverse view files If at the previous stages you configured everything correctly, there you will see information about new cars. Is done. Setup complete.

Results

Now you know how to configure a DNS server in Ubuntu. Write in the comments how you coped with this task, share your experience with other users, and ask any questions you may have about the topic of this article.