dnsmasq 常用作部署简单的 DNS 服务器 和 DHCP 服务器,下文将介绍如何使用 dnsmasq 部署一个简单的 DNS 服务器
参考这里
sudo vi /etc/dnsmasq.conf
domain-needed
bogus-priv
no-resolv
server=8.8.8.8 # forward 的服务器
server=8.8.4.4 # forward 的服务器
local=/mydomain.org/ # mydomain.org 使用本地解析,不进行forward
listen-address=::1,127.0.0.1,192.168.1.10 # 绑定指定的网卡接口
expand-hosts # 使用下面domain自动补全域名解析,例如/etc/hosts 配置了 "test 127.0.0.1" , 这时候客户端查询 "dig test.mydomain.org" 可以获取到对应的解析
# 下面 DHCP 相关,domain 字段上面 DNS 配置会使用到
domain=mydomain.org
dhcp-range=192.168.1.100,192.168.1.200,24h
dhcp-option=option:router,192.168.1.1
dhcp-authoritative
dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases
直接使用/etc/hosts
的记录用作 dns 解析
sudo vi /etc/hosts
添加下面记录
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
192.168.1.1 router
192.168.1.10 dnsmasq
192.168.1.20 server1
192.168.1.30 server2
sudo systemctl restart dnsmasq
正向解析测试
$ nslookup server1
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: server1.mydomain.org
Address: 192.168.1.20
反向测试
$ nslookup 192.168.1.20
20.1.168.192.in-addr.arpa name = server1.mydomain.org.
测试外部域名解析
$ nslookup fedoramagazine.org
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: fedoramagazine.org
Address: 35.196.109.67
查询一些历史数据,dnsmasq 本来不支持 DNS Round Robin 的,但后续的版本好像已经支持了这个功能
关键是 addn-hosts 这个配置
以刚才的配置为例,添加下面配置
domain-needed
bogus-priv
no-resolv
server=8.8.8.8 # forward 的服务器
server=8.8.4.4 # forward 的服务器
local=/mydomain.org/ # mydomain.org 使用本地解析,不进行forward
listen-address=::1,127.0.0.1,192.168.1.10 # 绑定指定的网卡接口
expand-hosts # 使用下面domain自动补全域名解析,例如/etc/hosts 配置了 "test 127.0.0.1" , 这时候客户端查询 "dig test.mydomain.org" 可以获取到对应的解析
....
addn-hosts=/etc/dnsmasq.addn-hosts/
创建对应的文件,存储域名A解析记录
$ mkdir -p /etc/dnsmasq.addn-hosts/
$ vi /etc/dnsmasq.addn-hosts/test.domain
# 注意,这里需要添加 FQDN(Fully Qualified Domain Name) 域名
192.168.1.30 server2.test.com
192.168.1.31 server2.test.com
192.168.1.32 server2.test.com
最后重启dnsamsq
sudo systemctl restart dnsmasq
这时候,测试记录
$ dig server2.test.com +short
192.168.1.30
192.168.1.31
192.168.1.32
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。