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/multi-user.target.wants/dnsmasq.service'

# 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 oralab01.uxora.com

As root, use the following commands:

# make sure your hostname is configured
[root]$ cat /etc/hostname 
    oralab01.uxora.com

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

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

# 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=127.0.0.1 DOMAIN=uxora.com | 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
    search uxora.com
    nameserver 127.0.0.1

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

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

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

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

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

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

Firewall

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,
Michel.

Reference
dnsmasq (wiki.archlinux.org)
Dnsmasq : For Simple DNS Configurations (oracle-base.com)

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
Refresh