Centos5.2下安裝bind9.6-P1vim
安裝bind前先安裝gcc,配置好yum源,yum -y install gcc,若是有run.pid報錯,直接rm -rf /var/run/yum.pid (解決yum-updatesd服務正運行的狀況)
下載 bind9.6到/root/Desktop,先進至目錄裏,而後wget ftp://ftp.isc.org/isc/bind9/9.6.0-P1/bind-9.6.0-P1.tar.gz
解壓bind-9.6.0-P1.tar.gz
# tar zxvf bind-9.6.0-P1.tar.gz
進入 bind-9.6.0-P1.gz文件夾
# cd bind-9.6.0-P1
建立安裝目錄,我是安裝在 /opt/bind
# mkdir /opt/bind
編譯,指定安裝目錄,開啓多線程支持
#./configure --prefix=/opt/bind --enable-threads --disable-openssl-version-check --disable-ipv6
#Make 大約須要幾分鐘,只要不報錯就繼續下去。
# make
#Make install 安裝
# make install
沒有報錯,就表示安裝成功了。
開始配置bind,接下來的過程是讓rndc來管理bind9.6
建立 rndc.conf文件,用bind自帶程序生成
進入/opt/bind/etc,將rndc.conf及named.conf生成
# cd /opt/bind/etc
# /opt/bind/sbin/rndc-confgen > /opt/bind/etc/rndc.conf
把rndc.conf 中的key信息輸出到 named.conf 中
# tail -10 rndc.conf | head -9 | sed -e s/#\ //g > named.conf
這裏強調一下,rndc.conf與named.conf的key值必須徹底同樣,並且並不須要生成rndc.key,這個問題糾纏了我大約3個小時
# vim named.conf
key "rndc-key" {
algorithm hmac-md5;
secret "WeHHAt0lui+9WihUW6HdsQ==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
options {
directory "/opt/bind/var/named";
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "fuying.com" IN {
type master;
file "fuying.zone";
};
zone "xiaofang.com" IN {
type master;
file "xiaofang.zone";
};
建立named文件夾:
# mkdir /opt/bind/var/named
進入named文件夾
# cd /opt/bind/var/named/
寫入如下內容
# vi localhost.zone
寫入如下內容:
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS @
1D IN A 127.0.0.1
將跟服務器的信息導入到/opt/bind/var/named/named.ca文件中
# dig -t NS . >/opt/bind/var/named/named.ca
建立文件named.local
#vi named.local
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
建立fuying.zone
# vi fuying.zone
$TTL 86400
@ IN SOA fuying.com. root.fuying.com. (
57 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns.fuying.com.
IN MX 5 mail
dns IN A 121.101.211.72
dns1 IN A 121.101.211.72
dns2 IN A 121.101.211.74
www IN A 121.101.211.76
建立xiaofang.zone
#vi xiaofang.zone
$TTL 86400
@ IN SOA xiaofang.com. root.xiaofang.com. (
57 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns.xiaofang.com.
IN MX 5 mail
dns IN A 121.101.211.72
dns1 IN A 121.101.211.72
dns2 IN A 121.101.211.74
www IN A 192.168.1.179
特別注意:bind的配置文檔是區分大小寫的。
下面就能夠啓動bind來測試安裝是否成功了
# /opt/bind/sbin/named –gc /opt/bind/etc/named.conf &
加 –gc 參數,能夠顯示出啓動日誌,以便出錯排查。
若是運行結果最後一行顯示
Running
代表安裝並啓動成功。
測試rndc命令 /opt/bind/sbin/rndc status,正確的話應該有狀態提示,我通常是直接編輯vim /root/.bashrc加進一個alias rndc9='/opt/bind/sbin/rndc'
把named 添加到啓動項,隨操做系統一塊兒啓動。
# cd /etc/rc.d
# vim rc.local
在最後添加如下內容
/opt/bind/sbin/named /opt/bind/etc/named.conf &
退出保存。
能夠嘗試重啓服務器,而後用命令nslookup及dig測試,或用pa axu | grep named,結束此服務用命令killall named
附加從DNS配置文件:
key "rndc-key" {
algorithm hmac-md5;
secret "c97aVpbK9mWdlbefliG7qg==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
options {
directory "/opt/bind/var/named";
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "fuying.com" IN {
type slave;
file "slaves/fuying.salve";
masters{192.168.1.179;};
};
zone "xiaofang.com" IN {
type slave;
file "slaves/xiaofang.salve";
masters{192.168.1.179;};
附加防火牆策略
[root@fuying opt]# vi vivabj069.sh
#! /bin/bash
#start iptables services
service iptables restart
#Flush all the policy
iptables -F
# setting the default policy
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#allow access 22,80 from LAN by tcp
iptables -A INPUT -p tcp -m tcp -s 0/0 --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 20020:20030 -j ACCEPT
iptables -A INPUT -p tcp --dport 20020:20030 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --dport 953 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --sport 953 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --sport 953 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --dport 953 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --dport 953 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --sport 953 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --sport 953 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --dport 953 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --dport 53 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --sport 53 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --dport 53 -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --sport 53 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --dport 53 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p tcp -m tcp --sport 53 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --sport 53 -j ACCEPT
iptables -A OUTPUT -s 0.0.0.0/0 -d 0.0.0.0/0 -p udp -m udp --dport 53 -j ACCEPT
執行防火牆:
附CNAME 解析記錄
# sh vivabj069.sh
# vi fuying.zone
$TTL 86400
@ IN SOA fuying.com. root.fuying.com. (
57 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns.fuying.com.
IN MX 5 mail
dns IN A 121.101.211.72
dns1 IN A 121.101.211.72
dns2 IN A 121.101.211.74
www IN A 121.101.211.76
wwww
IN
CNAME
www.fuying.com.
注意域名後面必須跟「.」;