You can install Dnsmasq, a lightweight DNS forwarder and DHCP server software, using the following command:
[root@dlp ~]# dnf -y install dnsmasq
Edit the Dnsmasq configuration file to configure DNS settings:
[root@dlp ~]# vi /etc/dnsmasq.conf
Uncomment line 19 to prevent forwarding addresses in non-routed address spaces:
domain-needed
Uncomment line 21 to query each server strictly in the order in resolv.conf:
bogus-priv
Uncomment line 53 to query each server strictly in the order in resolv.conf:
strict-order
Add specific DNS server configurations as needed, for example:
server=/server.education/10.0.0.10
Comment out line 108 and line 134:
#interface=lo
#bind-interfaces
Uncomment line 145 to add domain names automatically to hostnames:
expand-hosts
Add your own domain name (replace emc.world with your domain):
domain=emc.world
Enable and start the Dnsmasq service:
[root@dlp ~]# systemctl enable --now dnsmasq
To configure DNS records, add them to the /etc/hosts file:
[root@dlp ~]# vi /etc/hosts
Add records like this:
10.0.0.30 dlp.emc.world dlp
10.0.0.31 www.emc.world www
Restart the Dnsmasq service:
[root@dlp ~]# systemctl restart dnsmasq
If Firewalld is running, allow the DNS service. DNS uses ports 53/TCP and 53/UDP.
[root@dlp ~]# firewall-cmd --add-service=dns
[root@dlp ~]# firewall-cmd --runtime-to-permanent
You can verify name or address resolution from a client host on your network. First, install DNS utilities:
[root@node01 ~]# dnf -y install bind-utils
Change DNS settings to point to your Dnsmasq server (replace [enp1s0] with your network interface):
[root@node01 ~]# nmcli connection modify enp1s0 ipv4.dns 10.0.0.30
[root@node01 ~]# nmcli connection down enp1s0; nmcli connection up enp1s0
Test DNS resolution with dig:
[root@node01 ~]# dig dlp.emc.world
Edit the Dnsmasq configuration file for DHCP:
[root@dlp ~]# vi /etc/dnsmasq.conf
Add DHCP lease range and lease term, for example:
dhcp-range=10.0.0.200,10.0.0.250,12h
Add entries for Gateway, NTP, DNS, and Subnetmask:
dhcp-option=option:router,10.0.0.1
dhcp-option=option:ntp-server,10.0.0.10
dhcp-option=option:dns-server,10.0.0.10
dhcp-option=option:netmask,255.255.255.0
Restart the Dnsmasq service:
[root@dlp ~]# systemctl restart dnsmasq
If Firewalld is running, allow the DHCP service. DHCP Server uses port 67/UDP.
[root@dlp ~]# firewall-cmd --add-service=dhcp
[root@dlp ~]# firewall-cmd --runtime-to-permanent
This completes the installation and configuration of Dnsmasq for DNS and DHCP services.