工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆
浏览模式: 标准 | 列表2012年05月的文章

dnsmasq

yum install -y dnsmasq


echo 'addn-hosts=/etc/wdcdn.hosts' >> /etc/dnsmasq.conf

/etc/rc.d/init.d/dnsmasq start

 

 

 

 

 

 

一般说到dns,都会想到bind,bind虽然强大,但太复杂了,配置起来很头疼。用牛刀杀鸡倒不是鸡不死,而是怕那刀砍伤脚。dnsmasq这个小程序,使用上比dns始祖bind要简便得多,可以做正向dns代理,也可以直接做内部纯dns服务器用。

在debian/ubuntu下安装
apt-get install dnsmasq

配置
vi /etc/dnsmasq.conf
默认配置下,dnsmasq使用系统的/etc/resolv.conf并读取/etc/hosts,在配置里可以更改或者关闭,现在是修改了这两个,
其它的按默认:
resolv-file=/etc/dnsmasq.resolv.conf
addn-hosts=/etc/dnsmasq.hosts

(dnsmasq还支持dhcp服务,但一般不用搭理)

dnsmasq可以用hosts文件来设置域名:
例:test.sudone.com是不存在的域名,我在dnsmasq中指向到一个ip里:
echo "64.233.189.99 test.sudone.com" > /etc/dnsmasq.hosts
改完要重启
/etc/init.d/dnsmasq restart

做完之后,只要把本机dns指到dnsmasq的机器,就可以ping到test.sudone.com这个域名。

 

-----------------------

注意要记录查询的日志需要在配置文件里写

log-facility=/var/log/dnsmasq.log
log-queries

 

 


25
26
27
28
29
30
31
32
33
34
35
36
37
#
# Configuration file for dnsmasq acting as a caching nameserver.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
#
# Updated versions of this configuration file may be available at:
#
#   http://www.g-loaded.eu/2010/09/18/caching-nameserver-using-dnsmasq/
#
#
# Basic server configuration
#
listen-address=127.0.0.1
port=53
bind-interfaces
user=dnsmasq
group=dnsmasq
pid-file=/var/run/dnsmasq.pid
#
# Logging
#
#log-facility=/var/log/dnsmasq.log
#log-queries
#
# Name resolution options
#
domain-needed
bogus-priv
no-hosts
dns-forward-max=150
cache-size=1000
#no-negcache
neg-ttl=3600
resolv-file=/etc/resolv.dnsmasq
no-poll

 

 

squid的dns配置问题转

近期发现修改squid服务器的dns server配置后,无法生效,需要手工重启所有squid,今天查了一下,squid对dns的支持是这样一个原理:

1、如果dns server发送域名时带有ttl,则以此ttl为准,一般dns server都会带有对ttl的支持,现在我用的dnsmasq默认ttl是0。

2、如果dns server没发送ttl(ttl=0),squid就以自己的配置positive_dns_ttl为准,这个配置默认是6小时。

3、原先squid里配置的一个negative_dns_ttl,证实是配错了,这个配置指的是squid在取不到域名(出错)的情况下会多久再去重取。

我原先的情况是positive_dns_ttl和dns server的ttl都没有配置而配置了negative_dns_ttl,这时squid以默认的positive_dns_ttl为准,即6小时,这个时间对web服务器来说太长了。当前我解决的办法是修改dns server的ttl为60
秒,squid配置没有修改。因为直接修改squid的positive_dns_ttl配置项也是可以的。

有些朋友可能是用bind来做的dns,bind可能默认的ttl并不是0,所以用positive_dns_ttl配置不起效的话,修改ttl值就好。

附:检测dns服务器ttl值的方法

在一台linux机器上,修改/etc/resolv.conf将dns指向到要测试的dns,然后执行

dig test.com

如果该dns能解析test.com,就会返回一系列数据,其中有一列指明了ttl值,一试即知。

Records:18123