Debian的BIND9的配置
Debian的BIND9配置
安裝包:
apt install bind9
對bind9的一些操作命令:
systemctl status bind9 —查看bind9的狀態
systemctl restart bind9 —重啟bind9
粗略的日志:
/var/log/messages 它只記錄了一些服務啟動時的嚴重錯誤
配置目錄:
/etc/bind/named.conf----------------------主配置文件
/etc/bind/named.conf.default.zones----區域文件
/etc/bind/named.conf.options------------全局配置文件
**主配置文件:/etc/bind/named.conf
root@storageserver:/etc/bind# cat named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, BEFORE you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local
include “/etc/bind/named.conf.options”; ##它們是指定了
include “/etc/bind/named.conf.local”; #####一個其他的配配置文件
include “/etc/bind/named.conf.default-zones”;
**區域文件:/etc/bind/named.conf.default.zones
root@storageserver:/etc/bind# cat named.conf.default-zones
zone “.” {
type hint;
file “/etc/bind/db.root”;
};
zone “aa.com” { --------##主區域##--------------
type master;
file “/etc/bind/master.zone”;
allow-transfer {}; ##允許誰對這個zone進行轉發
};
zone “bb.aa.com” { --------##輔助區域##---------
type slave;
file “/etc/bind/slave”;
masters {192.168.10.1;}; ##主zone服務器的IP地址
};
zone “aa.com” IN { ----------##轉發區域##------------
type forward;
forward first|only;
forwarders {192.168.10.1;}; ##轉發的地址
};
關于子域的問題可以配合轉發區域使用,解決子域無法解析主域的問題
…**
泛解析:
在zone中加入一條A記錄,在想泛解析的地方加入* 這樣所有的以aa.com結尾的請求,都將會解析出192.168.10.1這個ip地址
*.aa.com. A 192.168.10.1
子域:
在主域中加入一條子域的NS記錄,在子域中加入轉發區域
主域:aa.com.
子域:bb.aa.com.
在主域zone file里加入:
@ ns dns.bb.aa.com.
dns.bb.aa.com. A ip-address
在子域中加入一個轉發zone file:
zone “aa.com” IN {
type forward;
forward only;
forwarders {主zone file的ip-address;};
};–##OK了##–
全局配置文件:/etc/bind/named.conf.options
root@storageserver:/etc/bind# cat named.conf.options
options {
directory “/var/cache/bind”; ##指定一個目錄為工作目錄,默認情況下所有zone存放在這個目錄下。
listen-on port 53 {any;}; ##設置在53號端口上監聽來自所有IP地址的請求。
recursion yes; ##服務器開啟遞歸查尋
----------一些權限控制----------
allow-query {192.168.10.0/24; !192.168.10.1;}; ##此選項允許192.168.10.0/24對本服務器進行區域解析不允許192.168.10.1進行區域解析;
allow-query-cache { any;}; ##此選項允許所有人對DNS服務器上面的緩存進行一個請求;
allow-recursion {ip-address}; ##這個允許誰對DNS進行遞歸查尋;
allow-transfer { ip-address;}; ##允許誰可以對zone進行傳送;
allow-update {any;}; ##允許那些客戶端對數據庫內容進行動態更新;主要用于DDNS;
blackhole {ip-address;}; ##黑名單,在其中的IP將會無法正常使用DNS SERVER提供的服務;
};
view視圖:
1. view是一個可基于條件,讓某一些IP訪問某個zone文件,讓某一個IP訪問另一個zone.
2. 這里要特別注意的是view是一個按順序匹配的,如果第一個view的match-clients{any;};這個條件是’any;‘的話就不會匹配下面的所有view.
3. 如果沒有被指定,match-clients和match-destinations默認匹配所有地址.
4. 一旦開啟view則所有zone都在view中
5. 在視圖語句中定義的域只對匹配視圖的用戶是可用的。
6. 通過在多個視圖中用相同名稱定義一個域,不同域數據可以傳給不同的用戶。
view “view-name” {
match-clients {ip-address;}; —##匹配源IP-可用來匹配內部IP
match-destinations{ip-address;}; —##匹配目的IP-一般設為any;
recursion yes|no; —##允許符合條件的進行遞歸查尋或否
zone “name” IN { —##設置一個區域
type master|save; —##設置文件類型
file “/var/named/123”; —##設置文件名字
};
include “/var/named/zone.file”; ##zone區域過多時,在view中可使用這個zone的文件
};
ACL訪問控制列表:
ACL可在named.conf or view中被使用,故名思有它與路由器中的access-list有異曲同工之妙,可針對IP地址進行訪問控制.
acl “abc” {
192.168.10.0/24;
!192.168.10.1;
!192.168.20.0/16;
any;
};
##如上所述abc這個訪問控制列表允許了192.168.10.0/24,any;拒絕了192.168.10.1,192.168.20.0/16;
很明顯any是所有的意思,而192.168.10.1則是個網段.
##除了any匹配所有外還有以下
1. none --##不匹配任何主機
2. any --##匹配任何主機
3. localhost --##匹配所有的本地IP與環回口也就是127.0.0.1
4. localnets --##匹配所有的本地網絡與環回接口,即服務器若有192.168.1.1/24這個IP,則匹配192.168.1.0-192.168.1.255/24加上127.0.0.1這個IP地址
BIND的日志:
在日志中主要有兩個概念:通道(channel)和類別(category)
channel:
一. 通道指定了應該向哪里發送日志數據:是發送給syslog,還是寫在一個文件里,或是發送給named的標準錯誤輸出,還是發送到位存儲桶(bit bucket)
. channel中的參數主要有:
logging{
channel aa {
file “/var/named/log_file” versions (number|unlimited) size —##versions定義了可以有多少日志文件##–
}}; —##size定義了大小##—
–消息的嚴重級別—
critical
error
warning
notice
info
debug [ level ]
dynamic
–消息的嚴重級別–
category:
一. 類別規定了哪些數據需要記錄
client —##處理客戶端請求。
config —##配置文件分析和處理。
database —##同BIND內部數據庫相關的消息,用來存儲區數據和緩存記錄。
default —##匹配所有未明確指定通道的類別。
dnssec —##處理 DNSSEC 簽名的響應。
general —##包括所有未明確分類的 BIND 消息。
lame-servers —##發現錯誤授權,即殘缺服務器。
network —##網絡操作。
notify —##區更新通知消息。
queries —##查詢日志
resolver —##名字解析,包括對來自解析器的遞歸查詢信息。
security —##批準/非批準的請求。
update —##動態更新事件。
xfer-in —##從遠程名字服務器到本地名字服務器的區傳送。
xfer-out —##從本地名字服務器到遠程名字服務器的區傳送。
在配置文件named.conf中使用logging語句來定制自己所需要的日志記錄,logging語句的語法為:
logging {
channel queries { --##設置通道名字##–
file “/var/named/queries_log” versions unlimited size 20m; --##設置日志文件為queries_log 不限制版本號 每個文件最多20M大小
severity info; --##警告級別為info##–
print-time yes; --##在前綴上加入時間##–
print-severity yes; --##在前綴上添加嚴重性##–
print-category yes; --##添加消息類別的前綴##–
};
category queries { queries}; --##將用戶查詢類別輸出到queries這個通道上,也就是/queries_log這個文件上.
};
----------------------下面是別人的,寫的很好就抄過來了-----------------------------
配置實例
logging {
channel “default_syslog” { —##指定服務器日志記錄的內容和日志信息來源##–
syslog daemon; —##發送給syslog 的daemon facility##–
severity info; --##只發送此優先級和更高優先級的信息 ##–
};
channel default_debug {
file “data/named.run”; /* 寫入工作目錄下的named.run 文件。注意:如果服務器用-f 參數啟動,則"named.run"會被stderr 所替換。/
severity dynamic; / 按照服務器當前的debug 級別記錄日志 */
};
channel xfer_in_log {
file “/var/log/named/xfer_in_log” versions 100 size 10m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel xfer_out_log {
file “/var/log/named/xfer_out_log” versions 100 size 10m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel notify_log {
file “/var/log/named/notify_log” versions 100 size 10m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel general_log {
file “/var/log/named/general_log” versions 400 size 100m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel default_log {
file “/var/log/named/default_log” versions 400 size 100m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel update_log {
file “/var/log/named/update_log” versions 100 size 10m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
channel query_log {
file “/var/log/query_log” versions 1024 size 1m;
severity info;
print-category no;
print-severity no;
print-time yes;
};
category queries { query_log; };
category default { default_log; };
category general { general_log; };
category xfer-in { xfer_in_log; };
category xfer-out { xfer_out_log; };
category notify { notify_log; };
category update { update_log; };
};
——————學藝不精,若有錯誤請指教!————————————
借鑒:
百度文庫
https://wenku.baidu.com/view/4324b12c2af90242a895e529.html
其他:
https://blog.csdn.net/zhang_danf/article/details/44775921
https://blog.csdn.net/yockie/article/details/8350229
https://www.jianshu.com/p/3fbbf7f457d7
http://blog.chinaunix.net/uid-10697776-id-3154778.html
https://www.cnblogs.com/zyqduron/archive/2009/01/05/1369594.html
https://blog.csdn.net/zhu_tianwei/article/details/45103455
726421625@qq.com 如果有什么指教可以發郵件!
---------------##發布日期:2019年10月24日 15:01:39##------------------
總結
以上是生活随笔為你收集整理的Debian的BIND9的配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IBM存储DS5020 配置
- 下一篇: Windows XP瘦身提速大法