系统:centos6.5
公司内部需求一台dns server,解析内部域名(该域名不需要在公网上解析)
安装了"bind bind-utils"包,配置里设置转发到外部电信dns,dhcp服务设置分发dns服务为该服务器。然后解析内部很通畅,但是到外部(如百度,163,新浪)等网站很慢。
不知道是不是配置有问题,找不出。
所以就使用dnsmasq试试。
下面是安装操作步骤
===================
1,yum 安装
yum install dnsmasq -y
或者源码安装
cd /tmp && wget http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.71.tar.gz tar -zxvf dnsmasq-2.71.tar.gz && cd dnsmasq-2.71 make install
cp dnsmasq.conf.example /etc/dnsmasq.conf mkdir -p /etc/dnsmasq.d #这个目录备用
2,dnsmasq配置
#主要有三个文件: #/etc/dnsmasq.conf #/etc/dnsmasq.d/resolv.dnsmasq.conf #/etc/dnsmasq.d/dnsmasq.hosts #第一个是系统默认必须的,后面两个可以自行建立,放置的路径也可以根据自己需要定义。
vi /etc/dnsmasq.conf #ITGeeker每次开启都提示错误,目的是让dnsmasq读取目录内所有配置文件 #conf-dir=/etc/dnsmasq.d #让dnsmasq读取你设定的resolv-file #no-resolv resolv-file=/etc/dnsmasq.d/resolv.dnsmasq.conf no-poll strict-order #不读取系统hosts,读取你设定的 no-hosts addn-hosts=/etc/dnsmasq.d/dnsmasq.hosts #dnsmasq日志设置 log-queries log-facility=/var/log/dnsmasq.log #dnsmasq缓存设置 cache-size=1024 #单设置127只为本机使用,加入本机IP为内部全网使用 listen-address=127.0.0.1,10.19.21.249
#在/etc/dnsmasq.d目录下新建2个文件
vi /etc/dnsmasq.d/resolv.dnsmasq.conf #nameserver 127.0.0.1 不应该添加 nameserver 202.96.209.5 nameserver 202.96.209.133 nameserver 223.5.5.5 nameserver 223.6.6.6 nameserver 114.114.114.114 nameserver 8.8.4.4 #nameserver 8.8.8.8
vi /etc/dnsmasq.d/dnsmasq.hosts 10.19.21.249 aop.baim.com
3,启动服务
/etc/init.d/dnsmasq start chkconfig dnsmasq on #如果是源码编译安装的 启动: /usr/local/sbin/dnsmasq 验证:netstat -tunlp|grep 53 关闭:killall -KILL dnsmasq 重启: pkill -9 dnsmasp && /usr/local/sbin/dnsmasq -h
#服务启动脚本 vi /etc/init.d/dnsmasq #!/bin/sh # # Startup script for the <span class='wp_keywordlink_affiliate'><a href="http://itgeeker.net/tag/dns/" title="View all posts in DNS" target="_blank">DNS</a></span> caching server # # chkconfig: - 49 50 # description: This script starts your DNS caching server # processname: dnsmasq # pidfile: /var/run/dnsmasq # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 dnsmasq=/usr/local/sbin/dnsmasq [ -f $dnsmasq ] || exit 0 RETVAL=0 # See how we were called. case "$1" in start) if [ $UID -ne 0 ] ; then echo "User has insufficient privilege." exit 4 fi echo -n "Starting dnsmasq: " daemon $dnsmasq $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dnsmasq ;; stop) if test "x`pidof dnsmasq`" != x; then echo -n "Shutting down dnsmasq: " killproc dnsmasq fi RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dnsmasq /var/run/dnsmasq.pid ;; status) status dnsmasq RETVAL=$? ;; reload) echo -n "Reloading dnsmasq: " killproc dnsmasq -HUP RETVAL=$? echo ;; force-reload) # new configuration takes effect only after restart $0 stop $0 start RETVAL=$? ;; restart) $0 stop $0 start RETVAL=$? ;; condrestart) if test "x`/sbin/pidof dnsmasq`" != x; then $0 stop $0 start RETVAL=$? fi ;; *) echo "Usage: $0 {start|stop|restart|reload|condrestart|status}" exit 2 esac exit $RETVAL
#如果你是本地编辑上传的,提示找不到文件记得 set ff=unix #再赋予执行的权限 chmod +x /etc/init.d/dnsmasq /etc/init.d/dnsmasq start chkconfig dnsmasq on
注:完成后需要在DHCP服务端设置DNS服务器地址,然后客户端会自动获取到该DNS地址。需要重客户端本地网络。
查看本地dns,是否能够获取地址。
然后访问域名,是否能够解析。
转载于:https://blog.51cto.com/charlie928/1671914