habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Setup dnsmasq on CentOS / RHEL / Rocky / Almalinux 7/8/9

1 min read

In the realm of networking and system administration, efficient DNS (Domain Name System) management is crucial for seamless communication between devices. One powerful tool that simplifies DNS configuration is Dnsmasq. This article will guide you through the process Setup dnsmasq CentOS RHEL Rocky 7/8/9, providing step-by-step instructions and examples of its usage.

See Also: Install Unbound Ubuntu 20.04/22.04 With Package Manager

See Also: Install Unbound Ubuntu 20.04/22.04 with Compile

Why Dnsmasq?

Dnsmasq is a lightweight, easy-to-configure as DNS forwarder and DHCP server. It’s particularly useful for small to medium-sized networks, acting as a central hub for DNS resolution and IP address assignment. In this article we have concern in DNSMASQ as local dns authoritative. So we have domain with local IP and resovled with localhost IP address.

Installation and Configuration DNSmasq

Begin by installing Dnsmasq on your CentOS/RHEL/Rocky/AlmaLinux system. Use the package manager to install it.

sudo yum install dnsmasq

Once installed, edit the configuration file at /etc/dnsmasq.conf to customize settings.

Examples of Dnsmasq Usage

We can configure for customize settings for DNSMASQ.

  1. DNS Forwarding

Dnsmasq can forward DNS queries to external servers. Open the configuration file and add the following line to forward DNS requests to Google’s public DNS servers:

server=8.8.8.8
server=8.8.4.4
  1. Local Domain Name Resolution

Define a local domain by adding the following line to the configuration file, allowing you to use custom domain names within your network:

domain=ourdomain.com
  1. Custom DNS Records:
See also  Install Unbound Ubuntu 20.04/22.04 with Compile

We can specify custom DNS records for specific hosts. For instance, if you want to associate the hostname “mail server” with the IP address 192.168.3.2, include the following line:

address=/mail.ourdomain.com/192.168.3.2
  1. Setting Domain MX Record

Dnsmasq can also be configured to handle mail services by setting up Mail Exchange (MX) records.

mx-host=ourdomain.com,mail.ourdomain.com,0

Summary configuration

Here is summary configuration of dnsmasq.

listen-address=127.0.0.1,192.168.3.2
server=8.8.8.8
server=8.8.4.4
domain=ourdomain.com
mx-host=ourdomain.com,mail.ourdomain.com,0
address=/mail.ourdomain.com/192.168.3.2
host-record=mail.ourdomain.com,192.168.3.2

After making changes to the Dnsmasq configuration file, remember to verify config and restart the Dnsmasq service for the changes to take effect:

[root@mail ~]# dnsmasq --test

#result

dnsmasq: syntax check OK.

Restart service dnsmasq. And check port running with netstat.

systemctl restart dnsmasq

Testing Dnsmasq with dig command

Use the dig command to verify and query the DNS records. Here are some examples:

1. Querying A Record:

dig namedomain.com A

This command queries the A record for namedomain.com, returning the associated IPv4 address.

2. Querying MX Record:

dig namedomain.com MX 

Dnsmasq is a versatile and lightweight tool for DNS management and DHCP services. By following the guidelines provided in this article, you can seamlessly Setup dnsmasq CentOS RHEL Rocky linux system, improving network efficiency and simplifying administration tasks.

Hope it usefull, please feel free for comment.


habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Easy Create Laravel Project with Composer

Requirement Laravel, a popular PHP framework, is renowned for its elegant syntax and robust features, making it a top choice for web developers. One...
habibzain
1 min read

Virtualbox Change Storage Size

Changing the storage size of a virtual machine in VirtualBox involves a few steps. Here’s a general guide. Backup your Virtual Machine (VM) Before...
habibzain
35 sec read

Easy Setup Logrotate Nginx Ubuntu

Log rotation is an important aspect of managing log files on a Linux system, including those generated by Nginx. Logrotate is a utility that...
habibzain
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss good article from us, get weekly updates in your inbox