Dnsmasq配置手册

snow chuai汇总、整理、撰写---2020/2/22


1. 实现DNS功能
1) 安装dnsmasq
[root@srv1 ~]# yum install dnsmasq -y
2) 配置DNS功能 [root@srv1 ~]# vim /etc/dnsmasq.conf # 取消19行注释.启用完整的FQDN解析 domain-needed
# 取消21行注释.反向查找的是私有地址时不再转发到上游服务器 bogus-priv
# 取消53行注释.严格按照resolv.conf中的顺序进行查找 strict-order
# 取消66行注释.定义如果查找其他的域资源记录,到指定的DNS-IP查找 server=/1000cc.net/192.168.10.9
# 取消135行注释.自动添加域名 expand-hosts
# 取消144行注释.定义正解、反解zone的域名 domain=niliu.edu,192.168.10.0/24
3) 定义A资源记录 [root@srv1 ~]# vim /etc/hosts ...... ...... ...... ...... ...... ......
# 于最后追加以下A记录信息 192.168.10.11 srv.niliu.edu 192.168.10.13 client.niliu.edu
4) 启动dnsmasq服务 [root@srv1 ~]# systemctl enable --now dnsmasq
[root@srv1 ~]# lsof -i :53 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dnsmasq 29523 nobody 4u IPv4 56218 0t0 UDP *:domain dnsmasq 29523 nobody 5u IPv4 56219 0t0 TCP *:domain (LISTEN) dnsmasq 29523 nobody 6u IPv6 56220 0t0 UDP *:domain dnsmasq 29523 nobody 7u IPv6 56221 0t0 TCP *:domain (LISTEN)
5) 防火墙设定 [root@srv1 ~]# firewall-cmd --add-service=dns --permanent success [root@srv1 ~]# firewall-cmd --reload success
6) 客户端测试 [root@client ~]# vim /etc/resolv.conf # 全文档清空,仅添加dnsmasq的IP地址 nameserver 192.168.10.11
[root@client ~]# host srv.niliu.edu srv.niliu.edu has address 192.168.10.11
[root@client ~]# host client.niliu.edu client.niliu.edu has address 192.168.10.13
[root@client ~]# host 192.168.10.11 11.10.168.192.in-addr.arpa domain name pointer srv.niliu.edu.
[root@client ~]# host 192.168.10.13 13.10.168.192.in-addr.arpa domain name pointer client.niliu.edu.
[root@client ~]# host srv1.1000cc.net srv1.1000cc.net has address 192.168.10.11
[root@client ~]# host client.1000cc.net client.1000cc.net has address 192.168.10.13
2. 实现DHCP功能
1) 编辑dnsmasq.conf
[root@srv1 ~]# vim /etc/dnsmasq.conf
# 取消163行注释,定义所分配的IP地址范围及租约信息
dhcp-range=192.168.10.50,192.168.10.60,255.255.255.0,12h
# 取消334行注释,定义网关信息 dhcp-option=option:router,192.168.10.1
# 取消343行注释,定义ntp server信息 dhcp-option=option:ntp-server,192.168.10.9,192.168.10.11
#344行追加dns serverIP地址 dhcp-option=option:dns-server,192.168.10.11
[root@srv1 ~]# systemctl restart dnsmasq
[root@srv1 ~]# lsof -i udp:67 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dnsmasq 1862 nobody 4u IPv4 23292 0t0 UDP *:bootps
2) 防火墙设定 [root@srv1 ~]# firewall-cmd --add-service=dhcp --permanent success [root@srv1 ~]# firewall-cmd --reload success
3) 客户端测试
4) 在服务器端查看租约信息 [root@srv1 ~]# cat /var/lib/dnsmasq/dnsmasq.leases

 

如对您有帮助,请随缘打个赏。^-^

gold