Friday, August 14, 2020

Quick DNS Server on Centos 8 using dnsmasq

To setup a quick and easy DNS server for CentOS 8, I choose dnsmasq. Bind is powerful, but too complicated for a simple DNS in a small LAN environment. So let's get started.


Install dnsmasq

# yum install dnsmasq -y


Backup original dnsmasq.conf configuration file

# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.ori


Insert some settings into dnsmasq.conf. This is assuming our CentOS box IP address is 192.168.0.120, and it's interface is enp0s3. The "server" settings are for upstream DNS addresses.

# cat > /etc/dnsmasq.conf <<EOF

listen-address=::1,127.0.0.1,192.168.0.120

interface=enp0s3

expand-hosts

domain=local.lan

server=192.168.0.1

server=8.8.8.8

server=8.8.4.4

address=/local.lan/127.0.0.1

address=/local.lan/192.168.0.120

EOF


Test your configuration for any syntax error
# dnsmasq --test

Now to put in some dns records. Dnsmasq will read all records from /etc/hosts of the dnsmasq server (how easy & convenient is that?!)
# cat >> /etc/hosts <<EOF
dns 192.168.0.120
web 192.168.0.120
EOF

Start your dnsmasq service
# systemctl start dnsmasq

Allow DNS in firewall
# firewall-cmd --add-service dns
# firewall-cmd --add-service dns --permanent

Now to put your DNS to test. The best is to use other machine. My other machine is using DHCP, so I need to configure the DNS setting to point to my brand new dnsmasq server, and ignore the dns given by my DHCP
# nmcli connection modify enp0s3 ipv4.ignore-auto-dns yes
# nmcli connection modify enp0s3 ipv4.dns 192.168.0.120
# nmcli connection down enp0s3
# nmcli connection up enp0s3

Ping test
# ping web
PING web (192.168.0.120) 56(84) bytes of data.
64 bytes from web.local.lan (192.168.0.120): icmp_seq=1 ttl=64 time=0.134 ms
64 bytes from web.local.lan (192.168.0.120): icmp_seq=2 ttl=64 time=0.129 ms

You have got yourself a brand new DNS server, congratulations!


No comments:

Post a Comment