How to Configure DNS and DHCP Server on Linux Operating Systems?

What is DNS?
DNS (Domain Name System) An IP address is provided to go to every web address on the Internet. It is quite difficult and troublesome to keep the IP addresses of these web addresses one by one in our minds.DNS comes into play here. It gives a name corresponding to the IP of each web address, so the names that are easier to replace than IP addresses are the name of the system that helps us keep in mind. For example techsoftcenter.com (IP value: 172.104.31.121)
What is DHCP?
DHCP (Dynamic Host Configuration Protocol) is simply the service used to give IP addresses to the computers in the system and additional parameters. The main purpose of DHCP is to enable the installer to automatically distribute IP addresses with DHCP the server instead of giving IP to individual devices. In addition, another convenience provided by the DHCP server is the NTP Server. Default Gateway etc. can also assign parameters.
We will use the “Oracle Enterprise Linux” operating system for installation. This article also applies to other operating systems. Compatible with (Red Hat, CentOS, Kali, Ubuntu and so on).
We will examine our setup processes under two headings, “DNS Server Configuration” and “DHCP Server Configuration“.
We disable our “Firewall” and “SELinux” services on our server. If our “Firewall” and “SELinux” services will be active, we will need to allow the ports that our services will use, so we need to disable them.
# vim / etc / selinux / config
-- We open the file and set the line below as "disabled".
SELINUX = disabled
-- We stop and close our firewall service.
# service iptables stop
# chkconfig iptables off
DNS Server Configuration (BIND DNS)
1. We install “BIND DNS” packages that we use in our operating system.
# yum -y install bind*
2. On our server, we edit our DNS Server address in your DNS configuration file “/etc/named.conf” and our DNS addresses that it will direct when it cannot resolve the name.
# vim /etc/named.conf
-- We edit the following lines in the file.
options {
listen-on port 53 { 127.0.0.1; 192.168.2.120; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
forwarders { 8.8.8.8; 8.8.4.4; };
allow-query { localhost; any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "techsoftcenter.com" IN {
type master;
file "techsoftcenter.forward";
allow-update { 192.168.2.0/24; };
};
zone "2.168.192.in-addr.arpa." IN {
type master;
file "techsoftcenter.reverse";
allow-update { 192.168.2.0/24; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
include "/etc/rndc.key";
3. In our server, we make the necessary editing operations in the file “/var/named/localdomain.zone” in order to make your “Forward” DNS records.
# vim /var/named/techsoftcenter.forward
-- We open our file and edit it as follows.
Here we enter the computer names and IP Addresses in our environment.
$TTL 86400
@ IN SOA techsoftcenter-srv.techsoftcenter.com. hostmaster.techsoftcenter.com. (
42 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS techsoftcenter-srv
localhost IN A 127.0.0.1
techsoftcenter-srv IN A 192.168.2.120
tchsftcntrrac1 IN A 192.168.2.121
tchsftcntrrac2 IN A 192.168.2.122
tchsftcntrrac1-priv IN A 192.168.117.141
tchsftcntrrac2-priv IN A 192.168.117.142
tchsftcntrrac1-priv2 IN A 192.168.117.143
tchsftcntrrac2-priv2 IN A 192.168.117.144
tchsftcntrrac1-vip IN A 192.168.2.131
tchsftcntrrac2-vip IN A 192.168.2.132
tchsftcntrrac-scan IN A 192.168.2.125
tchsftcntrrac-scan IN A 192.168.2.126
tchsftcntrrac-scan IN A 192.168.2.127
4. In order to make our Reverse DNS records on our server, we organize it by making the necessary operations in the file “/var/named/0.168.192.in-addr.arpa”.
# vim /var/named/techsoftcenter.com.reverse
-- We open our file and make the necessary arrangements.
Here we create the "reverse" records that we have assigned
We write the last digits of IP addresses. The other part of "DNS
Reverse "will complete the feature.
$ORIGIN 2.168.192.in-addr.arpa.
$TTL 1H
@ IN SOA techsoftcenter.com. hostmaster.techsoftcenter.com. ( 2
3H
1H
1W
1H )
2.168.192.in-addr.arpa. IN NS root.techsoftcenter.com.
120 IN PTR techsoftcenter.com-srv.techsoftcenter.com
121 IN PTR tchsftcntrrac1.techsoftcenter.com
122 IN PTR tchsftcntrrac2.techsoftcenter.com
131 IN PTR tchsftcntrrac1-vip.techsoftcenter.com
132 IN PTR tchsftcntrrac2-vip.techsoftcenter.com
125 IN PTR tchsftcntrrac-scan.techsoftcenter.com
126 IN PTR tchsftcntrrac-scan.techsoftcenter.com
127 IN PTR tchsftcntrrac-scan.techsoftcenter.com
5. After finishing the operations on our server, we activate your service and we take the necessary actions to open it automatically when our server starts.
-- At this stage, rndc.key is created for "securedns" in our server.
-- This process may take some time.
# service named start
Generating /etc/rndc.key:[ OK ]
Starting named: [ OK ]
-- For our service to start automatically on opening our server
we make the necessary setting.
# chkconfig named on
6. We have finished the procedures for DNS configuration on our server. Now we enter the address of this server, which we have configured to “/etc/resolv.conf” on our servers or computers that will resolve the web names.
# vim /etc/resolv.conf
-- Open the file and edit the following We're doing.
search techsoftcenter.com
nameserver 192.168.2.120
7. We check the configurations we have made and make sure that they are working.
# rndc status
version: 9.8.2rc1-RedHat-9.8.2-0.17.rc1.0.2.el6_4.4
CPUs found: 2
worker threads: 2
number of zones: 18
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running
# nslookup techsoftcenter-srv.techsoftcenter.com
Server: 192.168.2.120
Address: 192.168.2.120#53
Name: techsoftcenter-srv.techsoftcenter.com
Address: 192.168.2.120
# nslookup tchsftcntrrac-scan.techsoftcenter.com
Server: 192.168.2.120
Address: 192.168.2.120#53
Name: tchsftcntrrac-scan.techsoftcenter.com
Address: 192.168.2.126
Name: tchsftcntrrac-scan.techsoftcenter.com
Address: 192.168.2.127
Name: tchsftcntrrac-scan.techsoftcenter.com
Address: 192.168.2.125
# nslookup www.google.com.tr
# nslookup www.google.com.tr
Server: 192.168.2.120
Address: 192.168.2.120#53
Non-authoritative answer:
Name: www.google.com.tr
Address: 173.194.44.31
Name: www.google.com.tr
Address: 173.194.44.23
Name: www.google.com.tr
Address: 173.194.44.24
Our DNS Server configuration is complete. Now we will do the “DHCP Server” configuration.
DHCP Server Configuration
1. We are installing our “DHCP Server” package that we will use in our operating system.
# yum install dhcp
2. We organize it according to the IP range that we will distribute in the “/etc/dhcp/dhcpd.conf” file that we will use for configuring “DHCP Server” in our server, as in the example below.
# vim /etc/dhcp/dhcpd.conf
-- We open our file and configure it as follows."option" section,
we will distribute to our computers we can write options.
Allow booting;
Allow bootp;
Allow client-updates;
authoritative;
subnet 192.168.2.0 netmask 255.255.255.0 {
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;
option domain-name "techsoftcenter.com";
option domain-name-servers 192.168.2.120;
option ntp-servers 192.168.2.120;
default-lease-time 21600;
max-lease-time 43200;
range dynamic-bootp 192.168.2.100 192.168.2.253;
}
3. We start the “DHCP Server” service on our server with the settings we make, and when our server is rebooted, we do the necessary operations for automatic operation.
# service dhcpd start
-- For our service to start automatically on opening our server
we make the necessary setting.
# chkconfig dhcpd on
Your DHCP Server configuration is complete. Now, our computers in the network environment can automatically obtain IP addresses and other options from our server that we configure.
I hope it was a useful article.
