Methods to Setup a DNS/DHCP Server Utilizing dnsmasq on CentOS/RHEL 8/7

A Dynamic Host Configuration Protocol (DHCP) server dynamically assigns IP addresses and different community configuration parameters to every machine on a community. A DNS forwarder on a LAN forwards DNS queries for non-local domains to upstream DNS servers (outdoors that community). A DNS caching server solutions recursive requests from shoppers in order that the DNS question could be resolved quicker, thus bettering DNS lookup speeds to beforehand visited websites.

dnsmasq is a light-weight, straightforward to configure DNS forwarder, DHCP server software program and router commercial subsystem for small networks. Dnsmasq helps Linux, *BSD, Mac OS X in addition to Android.

It includes a DNS subsystem that gives an area DNS server for the community, with forwarding of all question varieties to upstream recursive DNS servers and caching of widespread report varieties. The DHCP subsystem helps DHCPv4, DHCPv6, BOOTP, PXE, and a TFTP server. And the router commercial subsystem helps primary autoconfiguration for IPv6 hosts.

On this article, we are going to stroll you thru the directions on tips on how to set up and setup DNS/DHCP Server Utilizing dnsmasq on CentOS/RHEL 8/7 distributions.

Putting in dnsmasq in CentOS and RHEL Linux

1. The dnsmasq bundle is accessible within the default repositories and could be simply put in utilizing the YUM bundle supervisor as proven.

# yum set up dnsmasq

Install dnsmasq in CentOS

Set up dnsmasq in CentOS

2. As soon as the dnsmasq bundle set up is full, you might want to begin the dnsmasq service for now and allow it to robotically begin at system boot. In addition to, examine its standing to make sure that it’s up and operating utilizing the next systemctl instructions.

# systemctl begin dnsmasq
# systemctl allow dnsmasq
# systemctl standing dnsmasq

Start and Verify dnsmasq Status

Begin and Confirm dnsmasq Standing

Configuring dnsmasq Server in CentOS and RHEL Linux

3. The dnsmasq server could be configured through the /and so on/dnsmasq.conf file (which accommodates effectively commented and defined choices), and user-defined configuration recordsdata will also be added within the /and so on/dnsmasq.d listing.

DNS is enabled by default, so earlier than making any modifications, be certain that to create a backup of /and so on/dnsmasq.conf file.

# cp /and so on/dnsmasq.conf /and so on/dnsmasq.conf.orig

4. Now open the /and so on/dnsmasq.conf file utilizing your favourite text-based editor and make the next urged configuration settings.

# vi /and so on/dnsmasq.conf

The listen-address the choice is used to set the IP handle, the place dnsmasq will pay attention on. To make use of your CentOS/RHEL server to pay attention for DHCP and DNS requests on the LAN, set the listen-address choice to its LAN IP addresses (bear in mind to incorporate 127.0.0.1) as proven. Be aware that the server IP have to be static.

listen-address=::1,127.0.0.1,192.168.56.10

Associated to the above, you’ll be able to prohibit the interface dnsmasq listens on utilizing the interface possibility (add extra strains for a couple of interface).

interface=eth0

5. If you wish to have a website (which you’ll be able to set as proven subsequent) robotically added to easy names in a hosts-file, uncomment the expand-hosts possibility.

expand-hosts

6. To set the area for dnsmasq, which implies DHCP shoppers may have totally certified domains so long as the set area is matched, and units the “area” DHCP possibility for all shoppers.

area=tecmint.lan

7. Subsequent, additionally outline the upstream DNS server for non-local domains utilizing the server possibility (within the type server=dns_server_ip) as proven.

# Google’s nameservers
server=8.8.8.8
server=8.8.4.4

8. Then you’ll be able to drive your native area to an IP handle(es) utilizing the handle possibility as proven.

handle=/tecmint.lan/127.0.0.1
handle=/tecmint.lan/192.168.56.10

9. Save the file and examine the configuration file syntax for errors as proven.

# dnsmasq –test

Check dnsmasq Configuration

Verify dnsmasq Configuration

Configuring dnsmasq with /and so on/resolv.conf File

10. On this step, you might want to make all queries to be despatched to dnsmasq by including the localhost addresses as the one nameservers in /and so on/resolv.conf file.

# vi /and so on/resolv.conf

Set Localhost Address in /etc/resolv.conf File

Set Localhost Handle in /and so on/resolv.conf File

11. The /and so on/resolv.conf file is maintained by an area daemon particularly the NetworkManager, due to this fact any user-made modifications will probably be overwritten. To stop this, write-protect it by setting the immutable file attribute (disabling write entry to the file) utilizing the chattr command as proven.

# chattr +i /and so on/resolv.conf
# lsattr /and so on/resolv.conf

Set File Attribute

Set File Attribute

Defining DNS Hosts and Names

12. The Dnsmasq reads all of the DNS hosts and names from the /and so on/hosts file, so add your DNS hosts IP addresses and identify pairs as proven.

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

Add DNS hosts IP addresses

Add DNS hosts IP addresses

Essential: Native DNS names will also be outlined by importing names from the DHCP subsystem, or by the configuration of a variety of helpful report varieties.

13. To use the above modifications, restart the dnsmasq service as proven.

# systemctl restart dnsmasq

14. You probably have the firewalld service operating, you might want to open DNS and DHCP providers within the firewall configuration, to permit requests from hosts in your LAN to cross to the dnsmasq server.

# firewall-cmd –add-service=dns –permanent
# firewall-cmd –add-service=dhcp –permanent
# firewall-cmd –reload

Testing Native DNS

15. To check if the native DNS server or forwarding is working wonderful, you might want to use instruments reminiscent of dig or nslookup for performing DNS queries. These instruments are supplied by the bind-utils bundle which can not come pre-installed on CentOS/RHEL 8, however you’ll be able to set up it as proven.

# yum set up bind-utils

16. After getting put in, you’ll be able to run a easy question in your native area as proven.

# dig tecmint.lan
OR
# nslookup tecmint.lan

Query Local Domain

Question Native Area

17. You may as well attempt to question the FQDN of one of many servers.

# dig webserver1.tecmint.lan
OR
# nslookup webserver1.tecmint.lan

Query Domain DNS

Question Area DNS

18. To check a reverse IP lookup, run an analogous command.

# dig -x 192.168.56.25
OR
# nslookup 192.168.56.25

Query Reverse IP Lookup

Question Reverse IP Lookup

Allow DHCP Server Utilizing dnsmasq

19. You may allow the DHCP server by uncommenting the dhcp-range possibility and provide the vary of addresses out there for lease and optionally a lease time e.g (repeat for a couple of community).

dhcp-range=192.168.0.50,192.168.0.150,12h

20. The next possibility defines the place the DHCP server will hold its lease database, this can lets you simply examine IP addresses it has assigned.

dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases

21. To make the DHCP server to authoritative mode, uncomment the choice.

dhcp-authoritative

22. Save the file and restart the dnsmasq service to use the current modifications.

# systemctl restart dnsmasq

That brings us to the tip of this information. To achieve us for any questions or ideas you wish to share about this information, use the suggestions type under.

Supply

Germany Devoted Server

Leave a Reply