Install Dnsmasq
[root@cent7devops ~]# yum -y install dnsmasq
initial state after yum install
[root@cent7devops ~]# grep -v -e "^#.*" -e "^$" /etc/dnsmasq.conf conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig [root@cent7devops ~]#
[root@cent7devops ~]# systemctl status dnsmasq ● dnsmasq.service - DNS caching server. Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; disabled; vendor preset: disabled) Active: inactive (dead) [root@cent7devops ~]#
[root@cent7devops ~]# ls -l /etc/dnsmasq.conf -rw-r--r-- 1 root root 26832 Apr 11 09:53 /etc/dnsmasq.conf [root@cent7devops ~]# [root@cent7devops ~]# ls -l /etc/dnsmasq.d/ total 0 [root@cent7devops ~]#
Configure 'dnsmasq.conf' and hosts file
[root@cent7devops ~]# diff /etc/dnsmasq.conf /etc/dnsmasq.conf.org 19c19 < domain-needed --- > #domain-needed 21c21 < bogus-priv --- > #bogus-priv 53c53 < strict-order --- > #strict-order [root@cent7devops ~]#
[root@cent7devops ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.10.111 gitlab.node01.devlocal node01 172.16.10.112 node02.devlocal node02 172.16.10.113 node03.devlocal node03 172.16.10.90 devops.devlocal devops [root@cent7devops ~]#
and Start Dnsmasq
[root@cent7devops ~]# systemctl start dnsmasq [root@cent7devops ~]# [root@cent7devops ~]# systemctl is-active dnsmasq active [root@cent7devops ~]#
operation check
confirm to access Dnsmasq. In this case, "172.16.10.90" is the IP Address of server running Dnsmasq.
[root@localhost ~]# nmcli -t -f ipv4.dns c s enp0s3 ipv4.dns:172.16.10.90 [root@localhost ~]# [root@localhost ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 172.16.10.90 [root@localhost ~]#
The hosts file in server for test have only localhost.
[root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [root@localhost ~]#
Try to execute dig command.
[root@localhost ~]# dig node02 +noall +answer ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> node02 +noall +answer ;; global options: +cmd node02. 0 IN A 172.16.10.112 [root@localhost ~]#
[root@localhost ~]# dig node03 +short 172.16.10.113 [root@localhost ~]#