1. 程式人生 > >Linux 搭建DNS

Linux 搭建DNS

容易出錯 imu 上層 server for 配置 auto statistic accep

Linux 搭建DNS

使用yum源安裝

yum -y install bind*

修改主配置文件

[[email protected] ~]# cp /etc/named.conf /etc/named.conf.bak  # 修改之前先備份一遍

[[email protected] ~]# vi /etc/named.conf  

修改為以下:

options {
 
        listen-on port 53 { any; }; // 監聽在主機的53端口上。any代表監聽所有的主機
        directory       "/var/named"; // 如果此檔案底下有規範到正反解的zone file 檔名時,該檔名預設應該放置在哪個目錄底下
 
         // 下面三項是服務的相關統計信息
 
        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; }; // 誰可以對我的DNS服務器提出查詢請求。any代表任何人
        recursion yes;
        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;
        forwarders { // 指定上層DNS服務器
           114.114.114.114;
        };
        bindkeys-file "/etc/named.iscdlv.key";
        managed-keys-directory "/var/named/dynamic";
};
 
logging {
 
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
 
};
zone "." IN {
        type hint;
        file "named.ca";
};
 
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

自定義域名解析配置

[[email protected] ~]#  vi /etc/named.rfc1912.zones  # 比如我們要添加example.com這個域的解析可以添加下面這一段
 
zone "example123.com" IN {    // 定義要解析主域名
        type master;
        file "example123.com.zone";  // 具體相關解析的配置文件保存在 /var/named/example123.com.zone 文件中
 
};

自定義example123.com.zone文件

[[email protected] named]# vi /var/named/example123.com.zone 
 
全文如下:
$TTL 86400
@       IN SOA          ns.example123.com. root (
                                        1       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        0 )     ; minimum  
 
@       IN      NS      ns. example123.com.
ns      IN      A       192.168.1.219
www     IN      A       192.168.1.45
bbs     IN      A       192.168.1.46
ttt     IN      A       192.168.1.68

www IN A 192.168.1.45 代表 www.example123.com 解析到 192.168.1.45服務器上。其他的類似

修改權限

[[email protected] named]# chown root:named  example123.com.zone  # 這一步一定要做

重啟服務

[[email protected]_server named]# service named restart

新增域名解析

如果我們要追加一個域的解析。比如google.com 則:

vi /etc/named.rfc1912.zones 
 
// 添加下面這段
zone "google.com" IN {
        type master;
        file "google.com.zone";
};
 
[[email protected] named]# cp -a example123.com.zone google.com.zone
[[email protected] named]# vi google.com.zone 
 
$TTL 86400
@       IN SOA          ns.google.com. root (
                                        1       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        0 )     ; minimum
@       IN      NS      ns.google.com.
ns      IN      A       192.168.1.219
www     IN      A       192.168.1.11
bbs     IN      A       192.168.1.46
ttt     IN      A       192.168.1.68

檢查bind文件配置過程中容易出錯

以下命令用以檢查bind配置文件及zone文件語法

named-checkconf /etc/named.conf

沒有報錯即可

named-checkzone example123.cn /var/named/example123.cn.zone

配置完成之後重啟服務

[[email protected]_server named]# service named restart

添加防火墻規則

[[email protected] web]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT

[[email protected] web]# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT

[[email protected] web]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 953 -j ACCEPT

[[email protected] web]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

Linux 搭建DNS