-
安装dnsmasq
在Debian系统中安装dnsmasq:
sudo apt-get install dnsmasq
-
启动并管理服务
启动并设置dnsmasq作为后台服务:
sudo systemctl start dnsmasq sudo systemctl enable dnsmasq
-
配置dnsmasq
打开默认配置文件进行编辑:
sudo nano /etc/dnsmasq.conf
添加以下配置:
interface= server=192.168.1.100/24
- 接口设置:
interface=可根据需要指定接口,若不指定,默认使用eth。 - 服务器设置:
server=...指定内部DNS服务器,通常设置为本地IP地址。
- 接口设置:
-
添加域名解析记录
在配置文件末尾添加:
host example.com 192.168.1.100 www.example.com CNAME example.com
这样,
example.com将解析到168.1.100,www.example.com则使用CNAME记录指向example.com。 -
添加到DNS主循环
在
/etc/nameservers文件中添加dnsmasq的配置文件:sudo nano /etc/nameservers
添加一行:
..1 example.com
这样,dnsmasq将作为
example.com的DNS服务器。 -
权限设置
确保dnsmasq有权限读取相关文件:
sudo chown -R dnsmasq:dnsmasq /etc/dnsmasq.conf sudo chmod -R 755 /etc/dnsmasq.conf
-
重启服务
应用配置并重启服务:
sudo systemctl restart dnsmasq
-
验证配置
-
检查服务状态:
systemctl status dnsmasq
-
测试DNS解析:
nslookup example.com 127...1 dig www.example.com @127...1
确认解析结果是否正确。
-
-
高级配置(可选)
-
启用缓存:
在配置文件中添加:
cache-to-mem 60 cache-to-file 180
-
集成负载均衡:
使用
round-robin或lb选项。 -
启用SSL:
安装
dnsmasq-tls并配置SSL:sudo apt-get install dnsmasq-tls
在配置文件中添加:
tls-v1 tls-v2 ssl-dnseec
启用TLS:
sudo systemctl restart dnsmasq
-
完成以上步骤后,dnsmasq服务器将能够解析指定的域名和子域名,提供有效的DNS服务。








