[root@vdevops ~]# yum -y install dnsmasq
[root@vdevops ~]# vi /etc/dnsmasq.conf # 取消 domain-needed、bogus-priv、strict-order、expand-hosts 的註釋 server=/linuxprobe.org/10.1.1.53 domain=srv.world [root@vdevops ~]# systemctl start dnsmasq [root@vdevops ~]# systemctl enable dnsmasq
將 DNS 記錄加入 /etc/hosts,Dnsmasq 便會回應客戶端查詢:
127.0.0.1 localhost localhost.localdomain vdevops.com 10.1.1.53 linuxprobe.org 10.1.1.56 vdevops.com vdevops [root@vdevops ~]# systemctl restart dnsmasq
若防火牆開啟,需放行 DNS 服務:
[root@vdevops ~]# firewall-cmd --add-service=dns --permanent [root@vdevops ~]# firewall-cmd --reload
在客戶端安裝 bind-utils 並將 DNS 指向 Dnsmasq 伺服器:
[root@linuxprobe ~]# nmcli c modify eno16777736 ipv4.dns 10.1.1.56 [root@linuxprobe ~]# nmcli c down eno16777736; nmcli c up eno16777736
用 dig 驗證解析:
[root@linuxprobe ~]# dig vdevops.org [root@linuxprobe ~]# dig -x 10.1.1.56
[root@vdevops ~]# vi /etc/dnsmasq.conf # line 146: dhcp-range=10.1.1.10,10.1.1.30,12h # line 316: dhcp-option=option:router,10.1.1.1 # line 325: dhcp-option=option:dns-server,10.1.1.56 # dhcp-option=option:netmask,255.255.255.0 [root@vdevops ~]# systemctl restart dnsmasq [root@vdevops ~]# systemctl status dnsmasq
啟動日誌會顯示 IP 範圍、租期與使用的 nameserver 等資訊,代表 DHCP 已生效。
參考:https://wiki.archlinux.org/index.php/Dnsmasq