Friday, May 3, 2019

Setup easy DNS server using dnsmasq on CentOS 7

Install dnsmasq

# yum install dnsmasq -y

Put in upstream dns server in /etc/resolv.conf. In this case, I want to use opendns as my upstream dns server.
# cat >> /etc/resolv.conf <<EOF
nameserver 208.67.222.222
EOF

For dns records, just use /etc/hosts
# cat >> /etc/hosts <<EOF
192.168.0.99 mydns.local
192.168.0.100 myportal.local
192.168.0.101 myworkspace.local
EOF

With just these 2 settings, you are good to go. Start dnsmasq, and your dns server should be able to resolve those 3 domains.
# systemctl start dnsmasq

Allow on firewall
# firewall-cmd --add-service dns
# firewall-cmd --add-service dns --permanent

Test with dig
# dig +short @localhost myportal.local
192.168.0.100

Test from other machine
# dig +short @192.168.0.99 myworkspace.local
192.168.0.101


It can even forward to upstream DNS
# dig +short @192.168.0.99 www.google.com
216.58.196.36

No comments: