Lightweight DNS Server--DNSmasq

Introduction:

    Dnsmasq is a lightweight DNS server. It is also an open source project with simple and fast configuration. Dnsmasq provides DNS caching and DHCP services. As a domain name resolution server (DNS), dnsmasq can cache DNS requests to improve the connection speed of visited Web sites. As a DHCP server, dnsmasq can provide intranet ip address and routing for LAN computers. DNS and DHCP functions can be implemented simultaneously or separately. Dnsmasq is lightweight and easy to configure. In addition, it comes with a PXE server, support for mx records of mail servers, support for srv records of jabber, etc.


Deployment environment:

Centos 6.5 x86_64 Operating System

When dnsmasq is used, packages in the base source can be installed and deployed directly.

# yum list | grep dnsmasq
dnsmasq.x86_64                              2.48-17.el6                  @base 
dnsmasq-utils.x86_64                        2.48-17.el6                  base

Install the dnsmasq package:

#yum -y install dnsmasq

Backup before operation:

# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

# View the installation file path of dnsmasq:

# rpm -ql dnsmasq
/etc/dbus-1/system.d/dnsmasq.conf
/etc/dnsmasq.conf            #Master Profile
/etc/dnsmasq.d
/etc/rc.d/init.d/dnsmasq
/usr/sbin/dnsmasq
/usr/share/doc/dnsmasq-2.48
/usr/share/doc/dnsmasq-2.48/CHANGELOG
/usr/share/doc/dnsmasq-2.48/COPYING
/usr/share/doc/dnsmasq-2.48/DBus-interface
/usr/share/doc/dnsmasq-2.48/FAQ
/usr/share/doc/dnsmasq-2.48/doc.html
/usr/share/doc/dnsmasq-2.48/setup.html
/usr/share/man/man8/dnsmasq.8.gz
/var/lib/dnsmasq

Point the local resolv parse file configuration to the local machine:

#echo 'nameserver 127.0.0.1' > /etc/resolv.conf

copy as an analytical configuration file for dnsmasq:

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
echo 'nameserver 8.8.8.8' > /etc/resolv.dnsmasq.conf

The configuration files used by dnsmasq are as follows:

# cat /etc/dnsmasq.conf  | grep -v '^#' | grep -v '^$'
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
interface=eth0
listen-address=192.168.30.131,127.0.0.1
bind-interfaces
addn-hosts=/etc/hosts    #Domain name mapping file

The contents of the other two profiles:

[root@sh-puppet-node2 etc]# cat /etc/resolv.conf
nameserver 127.0.0.1

[root@sh-puppet-node2 etc]# cat /etc/resolv.dnsmasq.conf
nameserver 8.8.8.8        #Four 8 Google's dns servers may be slower
nameserver 114.114.114.114

Add domain name mapping

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.30.128    sh-puppet-master.com
192.168.30.130    sh-puppet-node1.com
192.168.30.131    sh-puppet-node2.com

Start the dnsmasq service:

# /etc/init.d/dnsmasq restart
Shutting down dnsmasq:                                     [  OK  ]
Starting dnsmasq:                                          [  OK  ]

Test the ip to view domain name resolution:

# dig sh-puppet-node2.com


In order to prevent the local domain name from duplicating some domain names on the public network, it was changed to 127.0.0.1.       

[root@sh-puppet-node2 ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search shjygw com
#nameserver 202.96.209.5
nameserver 127.0.0.1
[root@sh-puppet-node2 ~]# cat /etc/resolv.dnsmasq.conf
nameserver 127.0.0.1

Baidu found that the test ping baidu is not ok, but does not affect intranet domain name resolution:

[root@sh-puppet-node2 ~]# ping www.baidu.com

ping: unknown host

www.baidu.com


Explanation: If the picture is destroyed, it will not be displayed. If you have time to fill it up.

Tags: DNS yum DBus CentOS

Posted on Sun, 16 Jun 2019 10:57:19 -0700 by stebbi