DNS Masq Setup
DNS Masq Setup
Menu
Menu
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 1/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
It features a DNS subsystem that provides a local DNS server for the network, with
forwarding of all query types to upstream recursive DNS servers and caching of
common record types. The DHCP subsystem supports DHCPv4, DHCPv6, BOOTP,
PXE, and a TFTP server. And the router advertisement subsystem supports basic
autoconfiguration for IPv6 hosts.
In this article, we will walk you through the instructions on how to install and setup
DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7 distributions.
2. Once the dnsmasq package installation is complete, you need to start the dnsmasq
service for now and enable it to automatically start at system boot. Besides, check its
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 2/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
status to ensure that it is up and running using the following systemctl commands.
DNS is enabled by default, so before making any changes, make sure to create a
backup of /etc/dnsmasq.conf file.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 3/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
4. Now open the /etc/dnsmasq.conf file using your favorite text-based editor and make
the following suggested configuration settings.
# vi /etc/dnsmasq.conf
The listen-address the option is used to set the IP address, where dnsmasq will
listen on. To use your CentOS/RHEL server to listen for DHCP and DNS requests on
the LAN, set the listen-address option to its LAN IP addresses (remember to
include 127.0.0.1) as shown. Note that the server IP must be static.
listen-address=::1,127.0.0.1,192.168.56.10
Related to the above, you can restrict the interface dnsmasq listens on using the
interface option (add more lines for more than one interface).
interface=eth0
5. If you want to have a domain (which you can set as shown next) automatically
added to simple names in a hosts-file, uncomment the expand-hosts option.
expand-hosts
6. To set the domain for dnsmasq, which means DHCP clients will have fully qualified
domain names as long as the set domain is matched, and sets the “domain” DHCP
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 4/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
domain=tecmint.lan
7. Next, also define the upstream DNS server for non-local domains using the server
option (in the form server=dns_server_ip) as shown.
# Google's nameservers
server=8.8.8.8
server=8.8.4.4
8. Then you can force your local domain to an IP address(es) using the address option
as shown.
address=/tecmint.lan/127.0.0.1
address=/tecmint.lan/192.168.56.10
9. Save the file and check the configuration file syntax for errors as shown.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 5/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
# dnsmasq --test
10. In this step, you need to make all queries to be sent to dnsmasq by adding the
localhost addresses as the only nameservers in /etc/resolv.conf file.
# vi /etc/resolv.conf
# chattr +i /etc/resolv.conf
# lsattr /etc/resolv.conf
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 6/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
12. The Dnsmasq reads all the DNS hosts and names from the /etc/hosts file, so add
your DNS hosts IP addresses and name pairs as shown.
127.0.0.1 dnsmasq
192.168.56.10 dnsmasq
192.168.56.1 gateway
192.168.56.100 maas-controller
192.168.56.20 nagios
192.168.56.25 webserver1
Important: Local DNS names can also be defined by importing names from the DHCP
subsystem, or by the configuration of a wide range of useful record types.
13. To apply the above changes, restart the dnsmasq service as shown.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 7/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
14. If you have the firewalld service running, you need to open DNS and DHCP
services in the firewall configuration, to allow requests from hosts on your LAN to pass
to the dnsmasq server.
15. To test if the local DNS server or forwarding is working fine, you need to use tools
such as dig or nslookup for performing DNS queries. These tools are provided by the
bind-utils package which may not come pre-installed on CentOS/RHEL 8, but you can
install it as shown.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 8/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
16. Once you have installed, you can run a simple query on your local domain as
shown.
# dig tecmint.lan
OR
# nslookup tecmint.lan
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 9/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
17. You can also try to query the FQDN of one of the servers.
# dig webserver1.tecmint.lan
OR
# nslookup webserver1.tecmint.lan
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 10/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
# dig -x 192.168.56.25
OR
# nslookup 192.168.56.25
dhcp-range=192.168.0.50,192.168.0.150,12h
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 11/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
20. The following option defines where the DHCP server will keep its lease database,
this will helps you to easily check IP addresses it has assigned.
dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases
21. To make the DHCP server to authoritative mode, uncomment the option.
dhcp-authoritative
22. Save the file and restart the dnsmasq service to apply the recent changes.
That brings us to the end of this guide. To reach us for any questions or thoughts you
want to share about this guide, use the feedback form below.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 12/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some
outdated info, issue or a typo, do post your valuable feedback or
suggestions in the comments to help improve this article...
TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of
published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee
( or 2 ) as a token of appreciation.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 13/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Related Posts
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 14/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 15/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
How to Build NGINX from Sources in RHEL, CentOS, Rocky and AlmaLinux
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 16/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 17/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 18/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 19/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Sweptnumbernumbernumber
February 13, 2023 at 4:00 pm
I think you did wrong with the resolv.conf permission part. It’s been
overwritten from time to time due to another daemon controlling it.
It’s a link in the place. So instead of making it readonly, you shall do this:
# ls -lh /etc/resolv.conf
Reply
sachin
June 7, 2021 at 2:34 am
Reply
Gineesh
April 24, 2021 at 11:03 am
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 21/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
any idea?
Reply
Guhan Ranganathan
December 14, 2020 at 3:06 pm
Reply
moein
September 7, 2020 at 10:16 pm
Thank you.
I had a question
127.0.0.1/exp1
127.0.0.1/exp2
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 22/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
127.0.0.1/exp3
What should I do if, for example, I want to redirect each site to that directory
as follows?
address=/example1.com/127.0.0.1 /exp1
address=/example2.com/127.0.0.1 /exp2
address=/example3.com/127.0.0.1 /exp3
Reply
SilentOne
May 15, 2021 at 6:17 pm
DNS resolves hostnames to IP’s or the other way around it has nothing to do
with URI’s i.e address=/example1.com/127.0.0.1 resolves example1.com to
ip address 127.0.0.1 nothing more.
If you want some kind of redirect to configure it inside of your web server
DNS can’t do this
Reply
Elijah
March 9, 2020 at 8:15 pm
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 23/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
I want to block access to certain domains on the Internet for individual devices
on my network by using the DNS notation. How do I do that with dnsmasq?
Reply
-P
June 2, 2020 at 1:20 pm
address=/baddomain.com/127.0.0.1
Reply
Elijah
December 15, 2020 at 5:18 pm
Yes, but how to point the devices to read that configuration? My idea was to
reroute all connections (both in- and out-) received and sent by my iPhone
to my Mac instead of the router. That way it would read my host’s file
settings.
Reply
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 24/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
David Woodthorpe
August 1, 2021 at 6:18 pm
I would think you would have to configure your iPhone’s network settings
to use the local DNS server.
Reply
Name *
Email *
Save my name, email, and website in this browser for the next time I comment.
Notify me of followup comments via e-mail. You can also subscribe without commenting.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 25/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Post Comment
Search...
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 26/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 27/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Linux Tricks: Play Game in Chrome, Text-to-Speech, Schedule a Job and Watch
Commands in Linux
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 28/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
BCC – Dynamic Tracing Tools for Linux Performance Monitoring, Networking and
More
7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 29/30
4/6/23, 2:23 PM How to Setup a DNS/DHCP Server Using dnsmasq on CentOS/RHEL 8/7
Tecmint: Linux Howtos, Tutorials & Guides © 2023. All Rights Reserved.
The material in this site cannot be republished either online or offline, without our permission.
https://www.tecmint.com/setup-a-dns-dhcp-server-using-dnsmasq-on-centos-rhel/ 30/30