In this article, we will install and configure a DNS server (Domain Name System) with bind9.
- A server machine (debian)
- A client machine (we can use any operating system for that)
Before doing anything, we will update our 2 machines:
apt-get update && apt-get upgrade
CONFIGURATION OF THE SERVER MACHINE
We will start by modify the machine hostname , in the form « MachineName.Domain.tld », to indicate to which domain the machine will belong.
Don’t forget to adapt the hostname of your machine according to your situation.
Then we will modify the /etc/hosts file so that it does a local name resolution without going through the DNS server.
Add these 2 lines to the file without forgetting to adapt your IP address according to your situation.
Finally we will modify the file /etc/resolv.conf to indicate to the machine its domain and on which server(s) it will be able to resolve the host names to IP addresses and vice versa.
INSTALLATION AND CONFIGURATION OF BIND9
For starters, on the server machine, we will install Bind9.
apt-get install -y bind9
Once installed, we will create 2 zones in the file /etc/bind/named.conf.local
- The zone « sio.tp » which will solve the host names of the domain « sio.tp » in IP addresses.
- The zone « 1.168.192.in-addr.arpa » (the IP address of the network (192.168.1.0) written backwards follows from « .in-addr.arpa » which will replace the .0 of the address Network IP) that will resolve the IP addresses in host name.
Now that we have declared the zones, we will create the files we specified in the file /etc/bind/named.conf.local so that we can configure our zones and add the hosts of the domain « sio.tp ».
We will now verify that our zone configuration files are correct with the command
If all your configuration files are correct, the command should return you a similar message:
If your files are not correct, the command will show you which file and which line there is an error.
To finish with the server machine, we restart the service bind9 so that all our changes are taken into account.
service bind9 restart
CONFIGURATION OF THE CLIENT MACHINE
We will now add the client device to the sio.tp domain and indicate which DNS server it should use so that it can resolve the host name of this domain.
Once configured, you can now test using the command ping.
ping SrvBind (from the client machine)
ping Client (from the server machine)
There you go! Now you can for example connect in SSH with the name of the machine without knowing the IP address.