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