linux dns服务器配置

常用命令,排错利器:

查看进程

 ps  aux |grep named

启动

service named start (centos)

/usr/local/bind/sbin/named -4  (redhat)

杀死

killall named

查看端口

netstat -ano| grep 53

检测

nslookup

dig

dig -x

改dns

vi /etc/resolv.conf

改网卡

vi /etc/sysconfig/network-scripts/ifcfg-eth0


centos系统(那你就幸福了,可以用yum装,redhat的直接往下拉):

一、安装
# rpm -qa | grep bind
#rpm -qa | grep caching

# yum install caching-nameserver

ok,centos这样就装好了。

检查一下:

#service named start

[root@localhost named]# ps  aux |grep named
named    14011  4.0  0.2  38852  3380 ?        Ssl  07:48   0:00 /usr/sbin/named -u named- c /etc/named.caching-nameserver.conf- t /var/named/chroot
root     14021  0.0  0.0   4784   704 pts/1    R+   07:48   0:00 grep named

注意了,红蓝字部分

说明,我们named服务配置文件为: /etc/named.caching-nameserver.conf

zone文件应该放在: /var/named/chroot/var/named/

二、配置

先说明一下,不然看着这些配置文件你或许会晕:

192.168.10.62 将是我们的dns服务器
192.168.10.188 将是我们的slave服务器

abc.zone.db 正解文件

named.192.168.10 反解文件

服务配置文件:

[root@localhost named]# vi /etc/named.caching-nameserver.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { 192.168.10.0/24; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { 192.168.10.0/24; };
        allow-query-cache { 192.168.10.0/24; };
        recursion yes;

};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {

        type hint;
        file "/var/named/named.ca";
};


zone "mx1985.com." IN {

        type master;

        file "/var/named/mx1985.zone.db";
        allow-transfer { 192.168.10.188; };
};

zone "abc.com." IN {

       type master;

       file "/var/named/abc.zone.db";
        allow-transfer { 192.168.10.188; };
};

zone "10.168.192.in-addr.arpa" IN {
        type master;
        file "/var/named/named.192.168.10";
        allow-transfer { 192.168.10.188; };
};

正解文件:

[root@localhost named]# vi /var/named/chroot/var/named/abc.zone.db

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                IN  NS  abc.com.
                IN  NS  slave.abc.com.
abc.com.        IN  A 192.168.10.62
slave.abc.com.  IN  A 192.168.10.188

www     IN A    192.168.10.188
aaa     IN A    192.168.10.188
bbb     IN A    192.168.10.62


反解文件:

[root@localhost named]# vi /var/named/chroot/var/named/named.192.168.10

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN  NS  abc.com.
        IN  NS  slave.abc.com.
62      IN  PTR abc.com.
188     IN  PTR slave.abc.com.

188     IN PTR   www.abc.com.
188     IN PTR  aaa.abc.com.
62      IN PTR  bbb.abc.com.
~
~


redhat 系统作为slave 服务的配置(redhat作为master服务器的配置请再往下拉):

在上面我们用的192.168.10.188作为slave服务器,现在我们来配置它。

因为我采用的是redhat,所以,这里就把其安装说明一下:

我分享一下 安装包

http://pan.baidu.com/share/link?shareid=90714652&uk=3222060313

#tar -zxvf bind-9.9.2.tar.gz

#cd bind-9.9.2

#./configure --prefix=/usr/local/bind --enable-threads --with-dlz-mysql

#make

#make install

生成基本配置文件

# /usr/local/bind/sbin/rndc-confgen >/usr/local/bind/etc/rndc.conf

#tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf

启动

#/usr/local/bind/sbin/named -4

好了,进入slavedns的配置,特别要注意这个系统的路径

建一个slaves目录,用于存放zone文件,

#mkdir /usr/local/bind/etc/slaves

#chmod 777 -R slaves/

#chown -R named.named slaves/

# ll -d slaves
drwxrwxrwx 2 named named 4096 Jul 25 13:42 slaves(这样就对了)

[root@localhost etc]# vi named.conf

key "rndc-key" {
        algorithm hmac-md5;
        secret "XfiakRq8MCb3uC6XwKDLQQ==";
};

controls {
        inet 127.0.0.1 port 953
                allow { 127.0.0.1; } keys { "rndc-key"; };
};
zone "." IN {

        type hint;
        file "/usr/local/bind/etc/named.ca";

};

zone "abc.com." IN {

       type slave;

       file "slaves/abc.zone.db";

        masters { 192.168.10.62; };

};

zone "10.168.192.in-addr.arpa" IN {
        type slave;
        file "slaves/named.192.168.10";

        masters { 192.168.10.62; };
};

重启,master共享的zone文件就过来了
# /usr/local/bind/sbin/named -4

[root@localhost etc]# ll slaves/
total 8
-rw-r--r-- 1 root root 349 Jul 25 14:18 abc.zone.db
-rw-r--r-- 1 root root 446 Jul 25 14:38 named.192.168.10

现在我们配置一个redhat下的master DNS服务器,不包括slave服务

named.conf

[root@rhes6 ~]# vi /usr/local/bind/etc/named.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { 192.168.10.0/24; };
        listen-on-v6 port 53 { ::1; };
        directory       "/usr/local/bind/etc/";
        pid-file "/usr/local/bind/var/run/named/named.pid";
        allow-query     { 192.168.10.0/24; };
        allow-query-cache { 192.168.10.0/24; };
        recursion yes;
        allow-transfer { none; };
};

include "/usr/local/bind/etc/rndc.key";
zone "." IN {

        type hint;
        file "/usr/local/bind/etc/named.ca";

};


zone "mx1985.com." IN {

       type master;

       file "mx1985.zone.db";

};

zone "abc.com." IN {

       type master;

       file "abc.zone.db";

};

zone "10.168.192.in-addr.arpa" IN {
        type master;
        file "named.192.168.10";
};


正解文件


[root@rhes6 ~]# vi /usr/local/bind/etc/abc.zone.db

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN  NS  abc.com.
        A 192.168.10.185

www     IN A    192.168.10.188
aaa     IN A    192.168.10.188
bbb     IN A    192.168.10.188


反解文件:

~
[root@rhes6 ~]# vi /usr/local/bind/etc/named.192.168.10

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN  NS  abc.com.
        PTR 192.168.10.185

188     IN PTR   www.abc.com.
188     IN PTR  aaa.abc.com.

188      IN PTR bbb.abc.com.

现在将所有机器的dns都改成这两台服务器吧

# vi /etc/resolv.conf

mastername 192.168.10.62

mastername 192.168.10.188

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值