1. 程式人生 > 實用技巧 >Linux(RHEL 5)中Bind服務的安裝與配置全過程-續

Linux(RHEL 5)中Bind服務的安裝與配置全過程-續

最近做了一個DNS雙機,記錄下來,備忘只用!

安裝及簡單配置在下面的連結有

Linux(RHEL 5)中Bind服務的安裝與配置全過程

與RHEL 4的對比請看Linux(RHEL 4)系列 之 DNS配置

一、修改主機名

hosts檔案

先修改主機名

[[email protected] ~]# hostnamewww.bokai.com //這樣修改只是臨時,重啟後恢復

[[email protected] ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

#127.0.0.1 localhost.localdomain localhost

127.0.0.1www.bokai.com www

::1 localhost6.localdomain6 localhost6

[[email protected] ~]#

network檔案

[[email protected] ~]# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no //關閉ipv6可以加快DNS的解析速度

HOSTNAME= www.bokai.com

[[email protected] ~]#

二、RNDC的配置和使用:

rndc的作用只在伺服器本地,並且伺服器系統防火牆必須開放953埠。rndc主要用來重新載入named.conf檔案,一般更改主配置檔案或者正逆向檔案後需要重啟named服務,現在可以使用rndc reload命令來重新載入配置檔案,而無需再重啟named服務。

[[email protected] ~]#rm –rf /etc/rndc.* //刪除之前的檔案

[[email protected] ~]#rm –rf /var/named/chroot/etc/rndc.*

[[email protected] ~]#

[[email protected]

~]# /usr/sbin/rndc-confgen > /var/named/chroot/etc/rndc.conf

[[email protected] ~]#cd /var/named/chroot/etc/

[[email protected] etc]#cp –p rndc.conf rndc.key //–p 引數可以吧檔案的屬性複製

[[email protected] etc]#chown named.named rndc.* //必須吧rndc.*所有許可權賦予給named使用者

[[email protected] etc]# ls -l

總計 32

-rw-r--r-- 1 root root 405 07-04 04:13 localtime

-rw-r----- 1 root named 1076 07-04 05:23 named.caching-nameserver.conf

-rw-r----- 1 root root 1100 07-04 05:22 named.caching-nameserver.conf.bak

-rw-r----- 1 root named 955 2007-07-19 named.rfc1912.zones

-rw-r----- 1 root root 955 07-04 05:22 named.rfc1912.zones.bak

-rw-r--r-- 1 named named 113 07-04 04:06 rndc.conf

-rw-r--r-- 1 named named 113 07-04 04:06 rndc.key

[[email protected] etc]# cat rndc.conf

# Start of rndc.conf

key "rndckey" {

algorithm hmac-md5;

secret "YywlCn+BNEfb6BHyj0hn3Q==";

};

options {

default-key "rndckey";

default-server 127.0.0.1;

default-port 953;

};

# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:

# key "rndckey" {

# algorithm hmac-md5;

# secret "YywlCn+BNEfb6BHyj0hn3Q==";

# };

#

# controls {

# inet 127.0.0.1 port 953

# allow { 127.0.0.1; } keys { "rndckey"; };

# };

# End of named.conf

[[email protected] etc]# cat rndc.key

# Start of rndc.conf

#key "rndckey" {

# algorithm hmac-md5;

# secret "YywlCn+BNEfb6BHyj0hn3Q==";

#};

#

#options {

# default-key "rndckey";

# default-server 127.0.0.1;

# default-port 953;

#};

#

# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:

key "rndckey" {

algorithm hmac-md5;

secret "YywlCn+BNEfb6BHyj0hn3Q==";

};

# controls {

# inet 127.0.0.1 port 953

# allow { 127.0.0.1; } keys { "rndckey"; };

# };

# End of named.conf

//rndc.key只要把rndc.conf註釋的部分改為執行,control方法下面的依舊保持註釋。把control方法全部複製到/var/named/chroot/etc/named.caching-nameserver.conf最後面。在/var/named/chroot/etc/named.rfc1912.zones檔案裡面新增一行 :

include "/etc/rndc.key";

三、SSH配置

[[email protected] ~]# cd /etc/ssh/

[[email protected] ssh]#cp –b sshd_config sshd_config.bak

[[email protected] ssh]# ls -l

總計 204

-rw------- 1 root root 132839 2007-07-13 moduli

-rw-r--r-- 1 root root 1827 2007-07-13 ssh_config

-rw------- 1 root root 3319 07-05 16:27 sshd_config

-rw------- 1 root root 3301 07-05 16:26 sshd_config.bak

-rw------- 1 root root 668 06-10 15:51 ssh_host_dsa_key

-rw-r--r-- 1 root root 590 06-10 15:51 ssh_host_dsa_key.pub

-rw------- 1 root root 963 06-10 15:51 ssh_host_key

-rw-r--r-- 1 root root 627 06-10 15:51 ssh_host_key.pub

-rw------- 1 root root 1675 06-10 15:51 ssh_host_rsa_key

-rw-r--r-- 1 root root 382 06-10 15:51 ssh_host_rsa_key.pub

[[email protected] ssh]#vi sshd_config

LoginGraceTime 10m //如果10秒內沒有輸入密碼,伺服器將斷開連線

PermitRootLogin no

AllowUsers dnsadmin

[[email protected] ssh]# vi ssh_config

ServerAliveInterval 300 //如果5分鐘內沒有操作就自動斷開連線

一般配置全部使用SSH遠端連線配置

建議使用putty,設定如下:這樣配置是避免出現亂碼。

使用putyy登入舉例:

login as: dns

[email protected]'s password:************************

Last login: Sat Jul 9 14:35:15 2011 from 192.168.10.10

[[email protected] ~]$ su root

口令:**************************

[[email protected] dns]#

四、DNS配置檔案編輯

(1)主DNS配置檔案修改

named.caching-nameserver.conf

[[email protected] etc]# cat named.caching-nameserver.conf

options {

listen-on port 53 { any; };

allow-query { any; };

allow-transfer { 192.168.10.2;}; //執行傳輸的從伺服器地址

};

view localhost_resolver {

match-clients { any; };

match-destinations { any; };

};

controls {

inet 127.0.0.1 port 953

allow { 127.0.0.1; } keys { "rndckey"; };

}; //這幾行是使用rndc管理named時必須新增的,關於rndc上面講了

named.rfc1912.zones

這個檔案基本不變,只在檔案最後新增一句 include "/etc/rndc.key";

(2)從伺服器配置

從伺服器配置比較簡單,修改IP,修改主機名,安裝bind,配置ssh,配置檔案備份都和上面一樣。需要修改的配置檔案是named.rfc1912.zones,修改舉例如下:

zone "bokai.com" in {

type slave; //設定型別為slave

file "bokai.com"; //檔名沒必要和主檔案一樣

master "192.168.10.1"; //指定主伺服器地址

};

五、啟動DNS服務,測試主伺服器是否正常工作

啟動DNS的方法如下:

[[email protected] ~]# /sbin/service named start //因為是遠端,所以命令指定絕對路徑.本地執行無需新增/sbin/

使用 #/sbin/chkconfig --level 35 named on命令新增named開機啟動

[[email protected] ~]# /etc/init.d/named start

測試:在客戶端,DNS伺服器地址設定成唯一的192.168.10.1

六、測試主從伺服器同步情況

首先吧主DNS伺服器的某個資料庫檔案修改版本號(序列號),比如如下

serial改成2011070801,重新整理時間修改成90或者其他,儲存,rndc reload。在從伺服器同樣修改這個檔案,版本號加1,重新整理時間修改90或者其他,超時改為10rndc reload或者重啟named服務。過段時間就能更新到。

希望看此文的人,能在實際中間體會點點東西。並擴充套件到,如何做雙主機,一主多備,異地容災,DNSSEC。甚至異地DNS伺服器虛擬化,真正實現數臺DNS伺服器建成的雲。

轉載於:https://blog.51cto.com/kennywong/607229