How To Configure Basic DNS in Linux Operating Systems?

How To Configure Basic DNS in Linux Operating Systems?

In today’s article, we will learn how to do Basic DNS Configuration (dnsmasq) in Linux Operating Systems. For us, “dnsmasq“, which we will use for name resolution in small-scale network structures, will analyze the records we enter in our server’s “/ etc / hosts” file without requiring a very large configuration. will provide the possibility.

Now we will see how this is done in 6 steps.

Step 1. We download and install the “dnsmasq” package from the “yum repository” defined in our operating system

# yum install dnsmasq

Step 2. We start our Dnsmasq service and make the necessary settings to start automatically when your server is turned on.

-- We run the command below to start our service.

# service dnsmasq start

-- When we start our service, if we get the error as below

dnsmasq: failed to create listening socket: Address already in use

-- We can use the commands below to fix this.
# killall -9 dnsmasq
# service dnsmasq start

-- We can use the command below to start our service automatically when opening our server.

# chkconfig dnsmasq on

Step 3. If it is necessary to start, stop and restart our Dnsmasq service, we can use the commands below.

-- The command to use to start our service.
# service dnsmasq start

-- The command to use to stop our service.

# service dnsmasq stop

--The command to use to restart our service.

# service dnsmasq restart

Step 4. If the “firewall” service is turned on in our server, we give the required permissions with the necessary commands and the desired permissions by the following commands. If our “firewall” service is off then we do not need to take any action.

-- The command to be used if we want to close our firewall service completely.

-- We stop our service.

# service iptables stop

-- We turn off our service so that our server does not start automatically when opening.

# chkconfig iptables off

-- If your firewall service will remain active, we make the following settings.

# iptables -I INPUT -p tcp --dport 53 -j ACCEPT

# iptables -I INPUT -p udp --dport 53 -j ACCEPT

# service iptables save

# firewall-cmd --zone=public --add-port=53/tcp

# firewall-cmd --zone=public --add-port=53/udp

# firewall-cmd --permanent --zone=public --add-port=53/tcp

# firewall-cmd --permanent --zone=public --add-port=53/udp

Step 5. You can use two different configuration files for your Dnsmasq configuration. The choice of this is up to you. Configuration files are given below.

-- We can find the "dnsmasq" configuration settings in our server in the file below.

# vim /etc/dnsmasq.conf

-- We will use the "hosts" file for name resolution on our server.
 In this file, we enter the server ip addresses and names locally.

# vim /etc/hosts

# RAC IP Address

# Public
192.168.2.121           tchsftcntrac1.localdomain             tchsftcntrac1
192.168.2.122           tchsftcntrac2.localdomain             tchsftcntrac2

# Virtual
192.168.2.131           tchsftcntrac1-vip.localdomain         tchsftcntrac1-vip
192.168.2.132           tchsftcntrac2-vip.localdomain         tchsftcntrac2-vip

# Private
192.168.117.141         tchsftcntrac1-priv.localdomain        tchsftcntrac1-priv
192.168.117.143         tchsftcntrac1-priv2.localdomain       tchsftcntrac1-priv2
192.168.117.142         tchsftcntrac2-priv.localdomain        tchsftcntrac2-priv
192.168.117.144         tchsftcntrac2-priv2.localdomain       tchsftcntrac2-priv2

# Scan IP
192.168.2.125         	tchsftcntrac-scan.localdomain         tchsftcntrac-scan
192.168.2.126         	tchsftcntrac-scan.localdomain         tchsftcntrac-scan
192.168.2.127         	tchsftcntrac-scan.localdomain         tchsftcntrac-scan

# Server IP Address

# File Server
192.168.2.130           techsoftcenter-fs.localdomain         techsoftcenter-fs

Step 6. We need to enter the address of the server that we configure “dnsmasq” in the “/etc/resolv.conf” file on the servers or computers that will do name resolution.

-- In order for our servers and clients to perform name resolution, 
we enter the IP address of our server where we run the "dnsmasq" service in the "resolv.conf" file.

# vim /etc/resolv.conf

# Generated by NetworkManager
search localdomain
nameserver 192.168.2.120

In this article, we have seen “Basic DNS Configuration in Linux Operating Systems. If you want to install a more detailed DNS server,“ How to Configure DNS and DHCP Server on Linux Operating Systems? ” you can review our article.

I hope it was a useful article.