簡易DNS教程 LINUX

 

操作系統版本centos 5.5需要安裝一些軟件,使用以下命令既可

#yum -y install bind*

#yum -y install caching-nameserver

這個是做備份文件,(連權限一起復制-p)

#cd   /var/named/chroot/etc

#cp -p named.caching-nameserver.conf  named.conf

下面開始進行配置,把所有代表本地的:127.0.0.1,localhost,都改成any,表示監聽所有主機的請求

#vi named.caching-nameserver.conf

示例:

-----------------------------------------------------------------------------------------------------------------------------------------------
//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver 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.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
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";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;

        allow-query     { any; };
        allow-query-cache { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
        match-clients      { any; };
        match-destinations { any; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};

//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver 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.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
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";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;

        allow-query     { any; };
        allow-query-cache { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
        match-clients      { any; };
        match-destinations { any; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};

-----------------------------------------------------------------------------------------------------------------------------------------------------

啓動服務

#/etc/init.d/named start

設置服務自動啓動

#chkconfig --level 35 named on

如果要開啓防火牆,請輸入以下指令

#iptables -A INPUT -p udp --dport 53 -j ACCEPT

#iptables -A INPUT -p tcp --dport 53 -j ACCEPT

這樣就可以用該主機做DNS服務器了。

       match-clients      { any; };
        match-destinations { any; };

說是這兩個可以不改,不過我沒試,以後再試吧

 ----------------------------------------------------------------------------------------------------------------------------------------------------

要設置本地的DNS解析

cd /var/named/chroot/etc

vi named.caching-nameserver.conf

在最後加上

 zone "test.com" IN {         //這裏就是你要的服務器名的域名,主機名在後面的一個文件裏設置
        type master;
        file "test.com.zone";
        allow-update { none; };
};

// 反向解釋,這個我沒做,非必需,以後試
zone "1.168.192.in-addr.arpa" IN {
    type master;
    file "1.168.192.in-addr.arpa.zone";
};

 

還有要做的是

/*view localhost_resolver {
        match-clients      { localhost; };
        match-destinations { localhost; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};*/
此處要將view字段註釋掉,否則在文件末尾添加zone字段後,啓動named服務時,會報如下錯誤:“/etc/named.conf:47: when using 'view' statements, all zones must be in views”,但view還是很有用的,網上查資料所得,它可以是的bind將一個域名對應幾個不同的IP地址。

# cd /var/named/chroot/var/named/
# cp –p localdomain.zone xxt401.com.zone(cp -p localhost.zone it.com.zone)
# cp –p named.local 1.168.192.in-addr.arpa.zone
# vi xxt401.com.zone(vi it.com.zone)

最後一行增加

bbs     IN      A       10.8.12.112

然後重起一下named ,然後bbs.it.com就可以被解析了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章