dnsmasq支持解决DNS,DHCP和router等多方面问题,一个常见的认知dnsmasq是一个本地dns(/etc/resolv.conf)的加强版
官方地址http://www.thekelleys.org.uk/dnsmasq/doc.html
dnsmasq通过多个对Name Server发起访问,获取最快的DNS解析结果,加快了域名解析的速度
传统的域名解析有2个主要过程:
resolv.conf方式有些缺点:
通过man resolv.conf
可以查看到相关默认值
timeout:n
sets the amount of time the resolver will wait for a response
from a remote name server before retrying the query via a dif‐
ferent name server. Measured in seconds, the default is
RES_TIMEOUT (currently 5, see <resolv.h>). The value for this
option is silently capped to 30.
attempts:n
sets the number of times the resolver will send a query to its
name servers before giving up and returning an error to the
calling application. The default is RES_DFLRETRY (currently 2,
see <resolv.h>). The value for this option is silently capped
to 5.
resolv.conf
提供可选参数,可以使用rotate随机访问NS,2个NS间隔最短可改为1s,尝试次数最少可改为1次
优化详细方式查看这里
options timeout:1 attempts:1 rotate
nameserver 10.0.0.1
nameserver 10.0.0.2
nameserver 10.0.0.3
但显然,优化后的resolv也并非最优方案,这时候可以选用dnsmasq
开启no-negcache,不缓存故障
he following directive controls whether negative caching should be enabled or not. Negative caching allows dnsmasq to remember “no such domain” answers from the parent nameservers, so it does not query for the same non-existent hostnames again and again. This is probably useful for spam filters or MTA services. By default, negative caching is enabled. To disable, un-comment the following directive.
一般情况下,进程会配置watchdog对进程状态进行监控,通过与crontab结合,定时发现进程不存在的情况并自动拉起进程。
但更深层次考虑的话,dnsmasq有可能一直都不能拉起,这时候就需要考虑降级操作,降级至本地/etc/resolv.conf作DNS解析
A1: 对于某些特殊的域名,想使用指定的Name Server,该如何配置
Q1: dnsmasq支持按域名指定NS,可通过以下方式实现
在dnsmasq.conf中添加如下配置:
server=/.google.com/8.8.8.8
server=/.google.com/4.4.4.4
或者将配置写入单独的文件,include至dnsmasq.conf
# 创建google专用的dnsmasq配置文件
echo -e "server=/.google.com/8.8.8.8\nserver=/.google.com/4.4.4.4" > /etc/dnsmasq.resolv_google.conf
# 在dnsmasq启用该配置
echo "conf-file=/etc/dnsmasq.resolv_google.conf" >> /etc/dnsmasq.conf
而且,使用本地resolv.conf是无法实现不同域名使用不同DNS解析,详看这里
A2: 针对A1的问题,假如我有多个域名需要“劫持”,有什么方式?
Q2: 首先考虑就是使用正则表达式匹配域名,然后指定NS;但官方dnsmasq是不支持正则表达式的方式(2.63版本好像曾经支持),所以如果想使用该功能,需要使用第三方支持正则表达式的dnsmasq
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。