How to Install and Configure dnsmasq in Linux

Introduction

Dnsmasq is a lightweight DNS forwarder and resource constrained routers and firewalls. It is widely used for tethering on smartphones and portable hotspots, and to support virtual networking in virtualisation frameworks. Dnsmasq is included in most Linux distributions like FreeBSD, OpenBSD and NetBSD.

Step 1: Install dnsmasq

First install dnsmasq package using yum command.

# yum -y install dnsmasq

Step 2: Configuration

Configure dnsmasq service as per following settings.

# vi /etc/dnsmasq.conf
# line 19: uncomment (never forward plain names)
domain-needed
# line 21: uncomment (never forward addresses in the non-routed address spaces)
bogus-priv
# line 41: uncomment (query with each server strictly in the order in resolv.conf)
strict-order
# line 55: add if you need
# query the specific domain name to the specific DNS server
# the example follows means query [server.education] domain to the [10.0.0.10] server
server=/server.education/10.0.0.10
# line 123: uncomment (add domain name automatically)
expand-hosts
# line 133: add (define domain name)
domain=tecdistro

Step 3: Start Service

Run the DHCP service by using below command and start service.

# systemctl start dnsmasq
# systemctl enable dnsmasq

Step 4: Entry in hosts file

# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
# add records
10.0.0.30   dlp.tecdistro dlp 

Restart the dnsmasq service.

# systemctl restart dnsmasq

Step 5: Add service in firewall

# firewall-cmd --add-service=dns --permanent 
success
# firewall-cmd --reload 
success

How to create DNS server in linux

Introduction

Domain Name System (DNS) is a standard technology for managing public names of Web sites and other Internet domains. The Internet maintains two principal namespaces: the domain name hierarchy and the IP address system. The Domain Name System maintains the domain namespace and provides translation services between these two namespaces. Internet name servers implement the Domain Name System. The top hierarchy of the Domain Name System is served by the root name servers maintained by delegation by the Internet Corporation for Assigned Names and Numbers (ICANN). Below the root, Internet resources are organized into a hierarchy of domains, administered by the respective registrars and domain name holders. A DNS name server is a server that stores the DNS records, such as address (A, AAAA) records, name server (NS) records, and mail exchanger (MX) records for a domain name and responds with answers to queries against its database.

By Default Port # 53
Dns-query

Step 1: Installation

To create a DNS server, firstly we have to install the bind packages:

# yum -y install bind.* bind-utils
Loaded plugins: amazon-id, rhui-lb
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-18.el7_1.1 will be installed
--> Processing Dependency: bind-libs = 32:9.9.4-18.el7_1.1 for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
--> Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-9.9.4-18.el7_1.1.x86_64
---> Package bind-utils.x86_64 32:9.9.4-18.el7_1.1 will be installed
--> Running transaction check
---> Package bind-libs.x86_64 32:9.9.4-18.el7_1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                       Arch                      Version                                   Repository                                           Size
=============================================================================================================================================================
Installing:
 bind                          x86_64                    32:9.9.4-18.el7_1.1                       rhui-REGION-rhel-server-releases                    1.8 M
 bind-utils                    x86_64                    32:9.9.4-18.el7_1.1                       rhui-REGION-rhel-server-releases                    199 k
Installing for dependencies:
 bind-libs                     x86_64                    32:9.9.4-18.el7_1.1                       rhui-REGION-rhel-server-releases                    1.0 M

Transaction Summary
=============================================================================================================================================================
Install  2 Packages (+1 Dependent package)

Total download size: 2.9 M
Installed size: 7.2 M
Downloading packages:
(1/3): bind-9.9.4-18.el7_1.1.x86_64.rpm                                                                                               | 1.8 MB  00:00:00
(2/3): bind-libs-9.9.4-18.el7_1.1.x86_64.rpm                                                                                          | 1.0 MB  00:00:00
(3/3): bind-utils-9.9.4-18.el7_1.1.x86_64.rpm                                                                                         | 199 kB  00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        5.0 MB/s | 2.9 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 32:bind-libs-9.9.4-18.el7_1.1.x86_64                                                                                                      1/3
  Installing : 32:bind-utils-9.9.4-18.el7_1.1.x86_64                                                                                                     2/3
  Installing : 32:bind-9.9.4-18.el7_1.1.x86_64                                                                                                           3/3
  Verifying  : 32:bind-utils-9.9.4-18.el7_1.1.x86_64                                                                                                     1/3
  Verifying  : 32:bind-libs-9.9.4-18.el7_1.1.x86_64                                                                                                      2/3
  Verifying  : 32:bind-9.9.4-18.el7_1.1.x86_64                                                                                                           3/3

Installed:
  bind.x86_64 32:9.9.4-18.el7_1.1                                            bind-utils.x86_64 32:9.9.4-18.el7_1.1

Dependency Installed:
  bind-libs.x86_64 32:9.9.4-18.el7_1.1

Complete!

Step 2: Configuration

Edit the file named.conf and make the changes:

# vi /etc/named.conf
options {
listen-on port 53 { 127.0.0.1; 192.168.0.100;};
allow-query     { localhost; 192.168.1.0/24; };     
# vi /etc/resolv.conf
server 192.168.0.100

To flush the DNS cache

# rnds flush
# vi /etc/named.rfc1912.zones