Centos Bind配置完整版

來源:互聯網
上載者:User

標籤:style   blog   http   使用   os   io   strong   檔案   

首先要成功安裝Centos作業系統,最新版本是Centos 6.4版本,迷你安裝。

[root@localhost named]# ifconfig -a

eth1      Link encap:Ethernet  HWaddr 00:15:5D:01:69:2C  
          inet addr:192.168.1.251  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: f180::225:5cff:fe01:691c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10252 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5782 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9993401 (9.5 MiB)  TX bytes:471402 (460.3 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:21 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1944 (1.8 KiB)  TX bytes:1944 (1.8 KiB)

可以看到本地網卡是eth1和lookback,編輯eth1網卡。

[root@localhost named]# vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1     #網卡裝置名稱
BOOTPROTO=static     #靜態IP
IPADDR=192.168.1.251     #靜態ip地址
NETMASK=255.255.255.0     #子網路遮罩
GATEWAY=192.168.1.1     #網關

如果配置正確的情況是,現在是可以上網的,ping 一個ip地址測試下。但是無法進行網域名稱解析,因此需要設定原生dns。
[root@localhost named]# vi /etc/resolv.conf

加入內容:

nameserver 8.8.8.8     #DNS伺服器
nameserver 8.8.4.4     #備用DNS伺服器

此時,網路已經配置完畢,讓我們開啟bind配置之旅吧!

[root@localhost ~]# yum install bind
Downloading Packages:
(1/4): bind-9.8.2-0.17.rc1.el6_4.5.i686.rpm | 4.0 MB 00:03
(2/4): bind-chroot-9.8.2-0.17.rc1.el6_4.5.i686.rpm | 71 kB 00:00
(3/4): bind-libs-9.8.2-0.17.rc1.el6_4.5.i686.rpm | 890 kB 00:04
(4/4): bind-utils-9.8.2-0.17.rc1.el6_4.5.i686.rpm | 181 kB 00:00
[root@localhost ~]# service named restart
停止 named [確定]
Generating /etc/rndc.key:
新開視窗輸入:
[[email protected] ~]# rndc-confgen -r /dev/urandom -a
wrote key file "/etc/rndc.key"
[[email protected] ~]# service named restart
停止 named [確定]
啟動 named [確定]
[[email protected] ~]#
在安裝bind-chroot的情況下,配置檔案儲存在/var/named/chroot/etc/目錄下
[[email protected] ~]# cd /var/named/chroot/etc/
[[email protected] etc]# vi named.conf
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 { any; };
        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     { any; };     #可查詢主機
        allow-query-cache { any; };      #緩衝
        recursion yes;     #是否允許遞迴查詢
        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

//logging {
//        channel default_debug {
//                file "data/named.run";
//                severity dynamic;
//        };
//};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
        channel gsquery {
                file "data/query.log"   versions 3 size 20m;
                severity info;
                print-time yes;
                print-category yes;
                print-severity yes;
        };
        category queries { gsquery; };
};

zone "." IN {
        type hint;
        file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

到此基本上DNS伺服器可以跑起來了。哦,不要忘記去把/etc/resolv.conf修改為自己這台伺服器的IP哦!~下面開始建立域以及域檔案。

可以直接修改named.conf,也可以在named.rfc1912.zones下面建立,我喜歡在named.rfc1912.zones下面建立。

[[email protected] etc]# vi /var/named/chroot/etc/named.rfc1912.zones
OR
[[email protected] etc]# vi /etc/named.rfc1912.zones

均可修改,我們建立一個a.com的域

zone "a.com" IN {
        type master;
        file "a.com.zone";
        allow-update { none; };
};

然後在
[[email protected] etc]# cd /var/named/chroot/var/named/
OR
[[email protected] etc]# cd /var/named/
建立一個檔案名稱為a.com.zone的正向地區檔案。
[[email protected] named]# vi /var/named/a.com.zone
a.com.zone的內容如下

$TTL 1D
$TTL 600
@       IN       SOA    ns.a.com      admin.a.com. (
                        0       ; serial
                        1D      ; refresh
                        1H      ; retry
                        1W      ; expire
                        3H )    ; minimum
        IN      NS      ns
        IN      A       192.168.1.250
        IN      AAAA    ::1
www     IN      A       192.168.1.191
ns      IN      A       192.168.1.250
qwer    IN      A       4.3.2.1

注意第二行哦!!@ IN SOA a.com admin.a.com.是非常重要的哦!~
然後我們再來建立一個反向地區檔案。
首先在named.rfc1912.zones建立一個反向地區

zone "a.com" IN {     #這個是正向
        type master;
        file "a.com.zone";
        allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {     #這個是反向
        type master;
        file "192.168.1.zone";
        allow-update { none; };
};

然後再來建立一個名字為192.168.1.zone的檔案。
[[email protected] named]# vi /var/named/192.168.1.zone

$TTL 1D
@       IN SOA  a.com admin.a.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
250     IN      PTR     ns.a.com.
1.2.3.4 IN      PTR     qwer.a.com.

基本建立完成,經過測試正向、反向都正確。參考了很多網路文章,不一一列舉,本地配置成功。

哦,對了。不要忘記開啟防火牆的TCP、UDP 53連接埠哦!!
[[email protected] ~]# vi /etc/sysconfig/iptables
添加如下內容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT

參考文章如下:
http://www.linuxidc.com/ 這個網站下面相關bind的文章全部看過

http://blog.sina.com.cn/s/blog_bd846d6e0101dw5q.html

http://yuanbin.blog.51cto.com/363003/108578/

http://docs.oracle.com/cd/E24847_01/html/E22302/dnsref-13.html

http://www.chinaz.com/web/2011/0513/179982.shtml

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.