在CentOS上配置dnsmasq以添加本地解析非常簡單。請按照以下步驟操作:
sudo yum install dnsmasq
/etc/dnsmasq.conf或/etc/dnsmasq/dnsmasq.conf。如果您的配置文件位于其他位置,請相應地修改。sudo vi /etc/dnsmasq.conf
example.local解析為本地IP地址192.168.1.100,則添加以下行:address=/example.local/192.168.1.100
如果您想要為多個域名指定相同的IP地址,可以用逗號分隔它們,如下所示:
address=/example.local,example2.local,example3.local/192.168.1.100
保存并關閉配置文件。
重啟dnsmasq服務以使更改生效:
sudo systemctl restart dnsmasq
現在,dnsmasq應該已經根據您指定的配置解析相應的域名。您可以使用nslookup或dig命令來測試域名解析是否正常工作:
nslookup example.local
或
dig example.local