This article will show to configure a simple lightweight local DNS with DNSMASQ in Oracle Linux 7.

This is handy for a small private network and quite useful for a oracle homelab, especially to resolv hostname and domain name.

In this article, you'll need ...
... Oracle Linux 7 installed (see oel7 installation here)
... root access is needed

Install dnsmasq

# install dnsmasq
[root]$ yum install dnsmasq -y

# make dnsmasq start a automatically on reboot
[root]$ chkconfig dnsmasq on
    Note: Forwarding request to 'systemctl enable dnsmasq.service'.
    ln -s '/usr/lib/systemd/system/dnsmasq.service' '/etc/systemd/system/'

# start dnsmasq
[root]$ service dnsmasq start
    Redirecting to /bin/systemctl start  dnsmasq.service

Configure dnsmasq

we are going to configure dnsmasq for the following hostname

As root, use the following commands:

# make sure your hostname is configured
[root]$ cat /etc/hostname

# add listening address
[root]$ echo $( echo && hostname -I 2>/dev/null ) | xargs -d" " -I{} echo listen-address={} > /etc/dnsmasq.d/

# add domain information
[root]$ echo "" | xargs -I{} echo "local=/{}/ domain={}" | tr ' ' '\n' >> /etc/dnsmasq.d/

# make dhcp/networkmanager to generate /etc/resolv.conf for localhost dns
[root]$ ls /etc/sysconfig/network-scripts/ifcfg-eth* | xargs -I{} echo "cat {} | \
grep -v -e ^PEERDNS -e ^DOMAIN -e ^DNS > /tmp/ifcfg.tmp; \
echo PEERDNS=no DNS1= | tr ' ' '\n' >> /tmp/ifcfg.tmp; \
cat /tmp/ifcfg.tmp > {} && rm /tmp/ifcfg.tmp;" | sh

# restart eth0
[root]$  ifdown eth0 && ifup eth0
    Device 'eth0' successfully disconnected.
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)

# check /etc/resolv.conf
[root]$ cat /etc/resolv.conf
    # Generated by NetworkManager

If you need to add more nameservers, do as below.

# add/change this line in /etc/dnsmasq.conf 
[root]$ vi /etc/dnsmasq.conf

# create/edit /etc/resolv.dnsmasq.conf
[root]$ vi /etc/resolv.dnsmasq.conf
    # Google's nameservers, for example

Then simply add entries to /etc/hosts file to make dnsmasq to resolve hostname

# add/change entries in /etc/hosts 
[root]$ vi /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6	oralab01	oralab02

# restart dnsmasq
[root]$ service dnsmasq restart
    Redirecting to /bin/systemctl restart  dnsmasq.service


If you are using the Linux firewall, you need to open port 53 specifically.
For the iptables firewall, use the following commands.

[root]$ iptables -I INPUT -p tcp --dport 53 -j ACCEPT
[root]$ iptables -I INPUT -p udp --dport 53 -j ACCEPT
[root]$ service iptables save

For the firewalld firewall, use the following commands to open the port for the current runtime and permanently to persist through reboots.

[root]$ firewall-cmd --zone=public --add-port=53/tcp
[root]$ firewall-cmd --zone=public --add-port=53/udp

[root]$ firewall-cmd --permanent --zone=public --add-port=53/tcp
[root]$ firewall-cmd --permanent --zone=public --add-port=53/udp

Please leave comments and suggestions,

dnsmasq (
Dnsmasq : For Simple DNS Configurations (

Enjoyed this article? Please like it or share it.

Add comment

Please connect with one of social login below (or fill up name and email)


Security code