linux dns伺服器配置

來源:互聯網
上載者:User

常用命令,排錯利器:

查看進程

 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.