bind 配置簡單自用 DNS 伺服器,binddns
目標:自訂一個網域名稱 www.test.com,可以解析到指定機器
安裝(版本:9.7.3):
yum install bind
配置:
初始化配置:
#產生rndc.conf檔案
cd /etc
rndc-confgen > rndc.conf
#產生named.conf檔案
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
#這之後 named.conf 內容看起來是這樣子:
key "rndc-key" {
algorithm hmac-md5;
secret "Bvqc7XRIJlz3s6p0JQ4Gwg==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
追加下面內容到 /etc/named.conf
options {
directory "/var/named";
forwarders { 192.168.1.1; }; # 無法解析的網域名稱轉到這裡
allow-query { any; };
# allow-transfer { none; };
};
# 下面那個處理 localhost
zone "localhost" {
type master;
file "named.localhost";
};
# localhost 反向解析
zone "0.0.127.in-addr.arpa" {
type master;
file "named.loopback";
};
# 我們自己的網域名稱
zone "test.com" IN {
type master;
file "test.zone";
allow-update { none; };
};
目錄 /var/named 下添加一個設定檔 test.zone,內容如下:
$ttl 1D
@ IN SOA test.com. root.test.com. (
1053891162
3H
15M
1W
1D )
IN NS ns1
ns1 IN A 192.168.0.1
www IN A 192.168.0.3
配置完成,啟動服務:service named start
測試:
host www.test.com
擴充一下,配置bind主從,很簡單
拷貝主DNS的 /etc/named.conf 到從dns伺服器,相應的網域名稱配置中
zone "test.com" IN {
type master;
file "test.zone";
allow-update { none; };
};
改為(紅字部分)
zone "test.com" IN {
type slave;
file "test.zone";
allow-update { none; };
masters {主dns地址;};
};
更新主dns後,重啟輔 dns 就會自動更新,不需要同步 test.zone 檔案