您好,登錄后才能下訂單哦!
5.1、DNS簡(jiǎn)介
DNS服務(wù)可以為用戶提供域名和IP之間的自動(dòng)轉(zhuǎn)換。通過DNS,用戶只需輸入機(jī)器的域名即可訪問相關(guān)的服務(wù),而無需使用那些難以記憶的IP地址。DNS幫助用戶在互聯(lián)網(wǎng)上尋找路徑,在互聯(lián)網(wǎng)上的每一個(gè)計(jì)算機(jī)都擁有一個(gè)唯一的地址,稱作'IP地址'。由于IP地址是一串?dāng)?shù)字,難以記憶,而DNS允許用戶使用一串有意義的字符串'即域名'取代,由域名轉(zhuǎn)換成相應(yīng)IP地址的這個(gè)過程稱為域名解析。
DNS域名又稱為DNS命名空間,它是以層次樹狀結(jié)構(gòu)進(jìn)行管理的,其最頂層是根域。根域在整個(gè)DNS命名空間是唯一的,而根域下可以分為多個(gè)子域,每個(gè)子域又可以分為多個(gè)子域。例如,Internet命名空間具有多個(gè)頂級(jí)域名(top-level domain names,TLD),如org,net,com等。而cn頂級(jí)域名又可以有多個(gè)子域,如edu、net、org和com等。
一個(gè)完整的域名由頂級(jí)域以及各子域的名稱所組成,各部分之間用圓點(diǎn)'.'分隔開來。其中最后一個(gè) '.'稱為根域,可省略,其左邊部分稱為頂級(jí)域名;第二個(gè)點(diǎn)'.'的左邊部分稱為二級(jí)域名(SLD);二級(jí)域左邊部分稱為三級(jí)域名;以此類推。例如www.sina.com.cn.中cn是一級(jí)域名,com是二級(jí)域名,sina是三級(jí)域名。全球一共有13個(gè)根域,其IP地址分別是:
[root@mylinux ~]# dig ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.3 <<>> ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11096 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 15 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 66583 IN NS e.root-servers.net. . 66583 IN NS f.root-servers.net. . 66583 IN NS b.root-servers.net. . 66583 IN NS a.root-servers.net. . 66583 IN NS m.root-servers.net. . 66583 IN NS i.root-servers.net. . 66583 IN NS k.root-servers.net. . 66583 IN NS j.root-servers.net. . 66583 IN NS d.root-servers.net. . 66583 IN NS c.root-servers.net. . 66583 IN NS l.root-servers.net. . 66583 IN NS g.root-servers.net. . 66583 IN NS h.root-servers.net. ;; ADDITIONAL SECTION: a.root-servers.net. 3580244 IN A 198.41.0.4 b.root-servers.net. 3576238 IN A 192.228.79.201 c.root-servers.net. 3580290 IN A 192.33.4.12 d.root-servers.net. 3575852 IN A 199.7.91.13 e.root-servers.net. 3523146 IN A 192.203.230.10 f.root-servers.net. 3590994 IN A 192.5.5.241 g.root-servers.net. 3549348 IN A 192.112.36.4 h.root-servers.net. 3586059 IN A 198.97.190.53 i.root-servers.net. 3534085 IN A 192.36.148.17 j.root-servers.net. 3562264 IN A 192.58.128.30 k.root-servers.net. 3562350 IN A 193.0.14.129 l.root-servers.net. 3534062 IN A 199.7.83.42 m.root-servers.net. 3561115 IN A 202.12.27.33 a.root-servers.net. 3574439 IN AAAA 2001:503:ba3e::2:30 b.root-servers.net. 3565057 IN AAAA 2001:500:84::b ;; Query time: 7 msec ;; SERVER: 10.225.30.181#53(10.225.30.181) ;; WHEN: Tue May 23 20:33:36 2017 ;; MSG SIZE rcvd: 492
Internet域名空間的頂級(jí)域是由ICANN(英特網(wǎng)名稱與數(shù)字地址分配機(jī)構(gòu))負(fù)責(zé)管理,這是一個(gè)近年來成立的負(fù)責(zé)管理Internet域名即地址系統(tǒng)的非營(yíng)利機(jī)構(gòu)。頂級(jí)域分為通用和國(guó)家兩大類。
通用頂級(jí)域名 | 說明 | 通用頂級(jí)域名 | 說明 |
com | 商業(yè)機(jī)構(gòu) | biz | 商業(yè)機(jī)構(gòu) |
net | 網(wǎng)絡(luò)服務(wù)組織 | name | 個(gè)人 |
org | 非營(yíng)利性組織 | pro | 專用人士 |
edu | 教育機(jī)構(gòu) | coop | 商業(yè)合作社 |
gov | 政府機(jī)構(gòu) | aero | 航空運(yùn)輸業(yè) |
mil | 軍事機(jī)構(gòu) | museum | 博物館行業(yè) |
int | 國(guó)際組織 | travel | 旅游行業(yè) |
info | 信息行業(yè) | job | 招聘和求職市場(chǎng) |
除美國(guó)以外的國(guó)家或地區(qū)需要使用國(guó)家域名,國(guó)家域名使用雙字母來進(jìn)行標(biāo)識(shí)。常見國(guó)家頂級(jí)域名有
國(guó)家頂級(jí)域名 | 說明 | 國(guó)家頂級(jí)域名 | 說明 |
cn | 中國(guó) | jp | 日本 |
hk | 中國(guó)香港 | uk | 英國(guó) |
tw | 中國(guó)臺(tái)灣 | kr | 韓國(guó) |
mo | 中國(guó)澳門 | de | 德國(guó) |
sg | 新加坡 | fr | 法國(guó) |
us | 美國(guó) | ru | 俄羅斯 |
5.2、DNS工作原理
在DNS出現(xiàn)之前,通常是通過計(jì)算機(jī)上維護(hù)一個(gè)hosts文件(/etc/hosts)的方式來實(shí)現(xiàn)主機(jī)名和IP地址之間的解析。管理員在hosts文件中記錄所有需要訪問的主機(jī)的主機(jī)名與IP地址,當(dāng)需要進(jìn)行解析的時(shí)候系統(tǒng)會(huì)自動(dòng)查詢hosts文件,并找出匹配的解析關(guān)系。采用這種方式,每臺(tái)主機(jī)上都必須維護(hù)一個(gè)hosts文件。網(wǎng)絡(luò)中每增加一臺(tái)計(jì)算機(jī)就必須手工修改hosts文件,添加新的計(jì)算機(jī)主機(jī)名和IP地址對(duì)應(yīng)的記錄。
隨著計(jì)算機(jī)網(wǎng)絡(luò)的快速發(fā)展,網(wǎng)絡(luò)中計(jì)算機(jī)數(shù)量隨之快速增長(zhǎng),這種依賴hosts文件來實(shí)現(xiàn)主機(jī)名和IP地址之間解析的方式無法滿足網(wǎng)絡(luò)發(fā)展的需求。DNS提供了完整解決方案。
DNS服務(wù)器采用C/S方式進(jìn)行工作。其具體工作流程為:
1、當(dāng)需要進(jìn)行DNS解析時(shí),系統(tǒng)會(huì)向本地DNS服務(wù)器發(fā)出解析請(qǐng)求,由本地DNS服務(wù)器進(jìn)行域名和IP地址的解析工作。 2、本地DNS服務(wù)器收到用戶請(qǐng)求后,則會(huì)將自身的DNS數(shù)據(jù)庫進(jìn)行查找匹配的域名和IP記錄。如果找到則把結(jié)果返回給客戶端并完成解析工作;如果沒有找到則把請(qǐng)求轉(zhuǎn)發(fā)給根服務(wù)器。 3、根域DNS服務(wù)器查到所對(duì)應(yīng)頂級(jí)域,將結(jié)果返回本地DNS服務(wù)器;本地DNS服務(wù)器根據(jù)頂級(jí)域地址向頂級(jí)域發(fā)起請(qǐng)求,頂級(jí)域DNS服務(wù)器查到二級(jí)域?qū)?yīng)地址返回給本地DNS服務(wù)器;本地DNS服務(wù)器根據(jù)二級(jí)域地址向二級(jí)域DNS服務(wù)器發(fā)送請(qǐng)求,二級(jí)域DNS服務(wù)器查到三級(jí)域?qū)?yīng)地址返回給本地DNS服務(wù)器;以此類推,直到本地DNS服務(wù)器找到最終要解析的域名所對(duì)應(yīng)的IP地址 4、最終本地DNS服務(wù)器把結(jié)果返回給客戶端 5、如果經(jīng)過查找后依然無法找到所需要的解析記錄,則有本地DNS服務(wù)器向客戶端返回?zé)o法解析的錯(cuò)誤信息。 |
上面的工作流程為正向解析,即FQDN-->IP,反向解析為IP-->FQND正反向解析是兩個(gè)不同的名稱空間,是兩棵不同的解析樹;不應(yīng)該存放同一個(gè)數(shù)據(jù)庫。FQDN(Full Qualified Domain Name, 完全限定域名)。
5.3、DNS服務(wù)器的安裝
bind是一款代碼的DNS服務(wù)器軟件,它是由伯克利大學(xué)編寫,全名(Berkeley Internet Name Domain)伯克利英特網(wǎng)域名,是目前世界上使用最為廣泛的DNS服務(wù)器軟件。
Centos6.5中自帶了bind軟件。但是為了使用最新版的bind軟件,可以從官方網(wǎng)站http://www.isc.org/上下載該軟件軟代碼進(jìn)行安裝,也可以直接使用yum安裝。
[root@mylinux home]# yum install bind -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * epel-debuginfo: mirrors.tuna.tsinghua.edu.cn * epel-source: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.hust.edu.cn Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.62.rc1.el6_9.2 will be installed --> Processing Dependency: portreserve for package: 32:bind-9.8.2-0.62.rc1.el6_9.2.x86_64 --> Running transaction check ---> Package portreserve.x86_64 0:0.0.4-11.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================= Installing: bind x86_64 32:9.8.2-0.62.rc1.el6_9.2 updates 4.0 M Installing for dependencies: portreserve x86_64 0.0.4-11.el6 base 23 k Transaction Summary ========================================================================================= Install 2 Package(s) Total download size: 4.0 M Installed size: 7.3 M Downloading Packages: (1/2): bind-9.8.2-0.62.rc1.el6_9.2.x86_64.rpm | 4.0 MB 00:42 (2/2): portreserve-0.0.4-11.el6.x86_64.rpm | 23 kB 00:00 ----------------------------------------------------------------------------------------- Total 87 kB/s | 4.0 MB 00:47 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : portreserve-0.0.4-11.el6.x86_64 1/2 Installing : 32:bind-9.8.2-0.62.rc1.el6_9.2.x86_64 2/2 Verifying : portreserve-0.0.4-11.el6.x86_64 1/2 Verifying : 32:bind-9.8.2-0.62.rc1.el6_9.2.x86_64 2/2 Installed: bind.x86_64 32:9.8.2-0.62.rc1.el6_9.2 Dependency Installed: portreserve.x86_64 0:0.0.4-11.el6 Complete!
啟動(dòng)和關(guān)閉bind
安裝完成后可以開啟bind服務(wù),bind通過named命令進(jìn)行啟動(dòng),一般讓其后臺(tái)運(yùn)行。
[root@mylinux named]# service named start Generating /etc/rndc.key:[ OK ] Starting named: [ OK ] [root@mylinux named]# ss -tunlp | grep :53 #查看DNS監(jiān)聽的端口,默認(rèn)只監(jiān)聽本機(jī) udp UNCONN 0 0 127.0.0.1:53 *:* users:(("named",1538,512)) udp UNCONN 0 0 ::1:53 :::* users:(("named",1538,513)) tcp LISTEN 0 3 ::1:53 :::* users:(("named",1538,21)) tcp LISTEN 0 3 127.0.0.1:53 *:* users:(("named",1538,20))
5.4、bind服務(wù)器配置
bind的主要配置文件包括named.conf和相應(yīng)的區(qū)域文件,bind中各種配置的更改都是通過這個(gè)文件完成,修改完成后需要重新啟動(dòng)bind服務(wù)使配置生效。其主要配置文件有:
服務(wù)腳本:/etc/rc.d/init.d/named 主配置文件:/etc/named.conf, /etc/named.rfc1912.zones(請(qǐng)求注解文檔) 區(qū)域解析庫文件:/var/named/zone_name.zone(至少包含根、本地、回環(huán)這三個(gè)區(qū)域文件) named.ca named.localhost named.loopback |
named.conf配置文件
named.conf是bind的主要配置文件,里面存儲(chǔ)了大量的bind自身的設(shè)置信息。bind安裝完成后并不會(huì)自動(dòng)創(chuàng)建該配置文件,用戶需要通過命令手工生成。 默認(rèn)顯示內(nèi)容為
[root@mylinux etc]# cat name.conf key "rndc-key" { algorithm hmac-md5; secret "9WzbeVyRhvPUak0Irw6pLA=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; [root@mylinux etc]#
named.conf配置文件由配置語句和注釋語句組成。每條配置語句以分號(hào)';'結(jié)尾,多條配置語句組成語句塊;注釋語句使用兩個(gè)左斜杠'//'作為注釋符。named.conf配置文件所支持的配置語句有:
語句 | 說明 |
acl | 定義一個(gè)主機(jī)匹配列表,用于訪問控制或其它用途 |
controls | 定義rndc工具與bind服務(wù)進(jìn)程的通信 |
include | 把其他文件中的內(nèi)容包含進(jìn)來 |
key | 定義加密秘鑰 |
logging | 定義系統(tǒng)日志信息 |
lwres | 把named配置為輕量級(jí)解釋器 |
masters | 定義主域名列表 |
options | 設(shè)置全局選項(xiàng) |
statistics-channels | 定義bind的統(tǒng)計(jì)信息的通信通道 |
server | 定義服務(wù)器的屬性 |
trusted-keys | 定義信任的DNSSEC密鑰 |
view | 定義視圖 |
zone | 定義區(qū)域 |
acl語句,用于定義地址匹配列表,其格式為:
acl string { address_match_element; ... };
bind默認(rèn)定義了一些地址匹配列表
地址匹配列表 | 說明 |
any | 匹配任何主機(jī) |
none | 不匹配任何主機(jī) |
localhost | 匹配系統(tǒng)上所有網(wǎng)卡的IPv4和IPv6的地址 |
localnets | 匹配任何與系統(tǒng)有接口的主機(jī)的IPv4和IPv6的地址 |
controls語句,用于定義rndc工具與bind服務(wù)進(jìn)程的通信,系統(tǒng)管理員可以通過rndc向bind進(jìn)行發(fā)出命令,并接受由bind返回的結(jié)果。其格式為:
controls { inet ( ipv4_address | ipv6_address | * ) [ port ( integer | * ) ] allow { address_match_element; ... } [ keys { string; ... } ]; unix unsupported; // not implemented };
include語句,用于把語句中所制定的文件的內(nèi)容添加進(jìn)named.conf配置文件中,該語句格式為:
include filename
key語句,用于定義TSIG或命令通道所使用的加密秘鑰,其格式為:
key domain_name { algorithm string; secret string; };
option語句,用于設(shè)置影響整個(gè)DNS服務(wù)器的全局選項(xiàng),該語句在named.conf配置文件中只能出現(xiàn)一次。如果沒有設(shè)置該語句,bind將使用默認(rèn)的option值。該語句支持選項(xiàng)非常多,常用選項(xiàng)有:
options { directory quoted_string; forward ( first | only ); forwarders [ port integer ] { ( ipv4_address | ipv6_address ) [ port integer ]; ... }; query-source ( ( ipv4_address | * ) | [ address ( ipv4_address | * ) ] ) [ port ( integer | * ) ]; query-source-v6 ( ( ipv6_address | * ) | [ address ( ipv6_address | * ) ] ) [ port ( integer | * ) ]; statistics-interval integer;
directory選項(xiàng)用于定義服務(wù)器的工作目錄,在配置文件中所指定的所有相對(duì)路徑都是相對(duì)于該路徑來定義的。該目錄也是服務(wù)器中大部分輸出文件(如name.run)的存儲(chǔ)位置。系統(tǒng)默認(rèn)使用'.'(即bind啟動(dòng)的目錄)作為工作目錄,一般把bind的工作目錄設(shè)置為/var/named,如
directory '/var/named';
forwarders選項(xiàng)用于指定DNS請(qǐng)求的轉(zhuǎn)發(fā)到其他的DNS服務(wù)器上,該選項(xiàng)默認(rèn)為空,也就是不進(jìn)行轉(zhuǎn)發(fā) 。選項(xiàng)值可以是一個(gè)IP地址或主機(jī)名,也可以是多臺(tái)主機(jī)的列表,如
forwarders {192.168.191.2;192.168.191.100;192.168.191.105;}
forward選項(xiàng)僅在forwarders選項(xiàng)不為空時(shí)生效,該選項(xiàng)用于控制DNS服務(wù)器的請(qǐng)求轉(zhuǎn)發(fā)操作。如果選項(xiàng)為first,則DNS服務(wù)器會(huì)先把請(qǐng)求轉(zhuǎn)發(fā)給forwarders選項(xiàng)中所指定的遠(yuǎn)端DNS服務(wù)器。如果遠(yuǎn)端DNS服務(wù)器無法響應(yīng)請(qǐng)求,則bind將嘗試自行解析該請(qǐng)求;如果選項(xiàng)值為only,則bind至轉(zhuǎn)發(fā)請(qǐng)求,并不進(jìn)行處理。
query-source和query-source-v6選項(xiàng)分別用于設(shè)置DNS服務(wù)器所使用的IPv4和IPv6的IP地址和端口號(hào)。默認(rèn)端口號(hào)為53,如果指定其他端口,將無法與全局的DNS服務(wù)器通信。
statistics-interval選項(xiàng)用于指定DNS服務(wù)器記錄統(tǒng)計(jì)信息的時(shí)間間隔,單位為分鐘,默認(rèn)為60,最大值為40320,如果選項(xiàng)為0,則服務(wù)器不記錄統(tǒng)計(jì)信息。
server語句,bind有可能與其他的DNS服務(wù)器進(jìn)行通信,但是并非所有的DNS服務(wù)器都運(yùn)行同一個(gè)版本的bind。server語句可以設(shè)置遠(yuǎn)程服務(wù)器的特征信息,以使雙方能夠正常通信。該語句的格式為:
server ( ipv4_address[/prefixlen] | ipv6_address[/prefixlen] ) { bogus boolean; edns boolean; edns-udp-size integer; max-udp-size integer; provide-ixfr boolean; request-ixfr boolean; keys server_key; transfers integer; transfer-format ( many-answers | one-answer ); transfer-source ( ipv4_address | * ) [ port ( integer | * ) ]; transfer-source-v6 ( ipv6_address | * ) [ port ( integer | * ) ]; support-ixfr boolean; // obsolete };
view語句,該語句可以使bind根據(jù)客戶端地址來決定需要返回的域名解析結(jié)果,也就是說,不同的主機(jī)通過同一臺(tái)DNS服務(wù)器對(duì)同一個(gè)域名解析,會(huì)得到不同的解析結(jié)果。其格式為:
view string optional_class{ match-clients { address_match_element; ... }; match-destinations { address_match_element; ... }; match-recursive-only boolean; key string { algorithm string; secret string; }; zone string optional_class { ... }; }
每一條view語句定義了一個(gè)客戶端集合所能看到的視圖,如果客戶端匹配試圖中的match-clients選項(xiàng)所定義的客戶端列表,那么bind將根據(jù)該視圖返回解析結(jié)果。例如,希望對(duì)內(nèi)網(wǎng)用戶和外網(wǎng)用戶進(jìn)行區(qū)分,使他們?cè)L問同一個(gè)域名時(shí)會(huì)得到不同的結(jié)果。可以使用view語句定義不同的視圖,在兩個(gè)視圖中分別定義不同的屬性,以達(dá)到效果。
view 'internal'{ match-clients { 172.0.0.0/8; }; recursion yes; zone 'example.com'{ type master: file 'example-internal.zone'; }; }; view 'external'{ match-clients { any; }; recursion no; zone 'example.com'{ type master: file 'example-external.zone'; }; };
zone語句,該語句是named.conf文件的核心部分。每一條zone語句定義一個(gè)區(qū)域,用戶可以在區(qū)域中設(shè)置該區(qū)域相關(guān)的選項(xiàng)。在bind中可以設(shè)置多種類型的區(qū)域,如表所示。不同類型的區(qū)域,其zone語句的d定義有所不同。
區(qū)域類型 | 說明 |
master | 主DNS區(qū)域 |
slave | 從DNS區(qū)域,由主DNS區(qū)域控制 |
forward | 將解析請(qǐng)求轉(zhuǎn)發(fā)給其他服務(wù)器 |
hint | 根DNS服務(wù)器集 |
stub | 與從區(qū)域類似,但只保存DNS服務(wù)器的名字 |
zone 'domain_name' IN{ type master; file 'path'; }; zone '.' IN{ type hint; file 'path'; };
其中,根域的名稱為'.',type選項(xiàng)定義區(qū)域的類型,根域所對(duì)應(yīng)的類型代碼為hint。file選項(xiàng)定義了該區(qū)域所使用的區(qū)域文件,在該文件中可以定義與該區(qū)域文件相關(guān)的各種屬性。主DNS區(qū)域是bind中最基本的區(qū)域類型,它又可以分為正向解析區(qū)域和反向解析區(qū)域兩種。如下面定義了一個(gè)域名為test.com的正向解析區(qū)域,使用區(qū)域文件為test.zone。
zone 'test.com' IN { type master; file 'test.zone'; allow-update {none;}; };
反向解析主區(qū)域的例子為:
zone '1.168.192.in-addr.arpa' IN { type master; file 'test.local'; allow-update {none;}; };
檢查該配置文件語法錯(cuò)誤的命令有:
Service named-checkconfig #檢查配置錯(cuò)誤 service name-checkzone #檢查區(qū)域錯(cuò)誤
根區(qū)域文件named.ca
named.ca是一個(gè)特殊的區(qū)域文件,該文件中記錄了Internet上的根DNS服務(wù)器的名稱和IP地址。DNS服務(wù)器接收到客戶端發(fā)來的解析請(qǐng)求后,如果在本地找不到匹配的DNS記錄,則把請(qǐng)求發(fā)送到該文件中所定義的根DNS服務(wù)器上進(jìn)行逐級(jí)查找。在該文件中總共定義13個(gè)根DNS服務(wù)器。
[root@mylinux var]# cat named.ca ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t NS . @a.root-servers.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1193 ;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 518400 IN NS e.root-servers.net. . 518400 IN NS h.root-servers.net. . 518400 IN NS l.root-servers.net. . 518400 IN NS i.root-servers.net. . 518400 IN NS a.root-servers.net. . 518400 IN NS d.root-servers.net. . 518400 IN NS c.root-servers.net. . 518400 IN NS b.root-servers.net. . 518400 IN NS j.root-servers.net. . 518400 IN NS k.root-servers.net. . 518400 IN NS g.root-servers.net. . 518400 IN NS m.root-servers.net. . 518400 IN NS f.root-servers.net. ;; ADDITIONAL SECTION: e.root-servers.net. 518400 IN A 192.203.230.10 e.root-servers.net. 518400 IN AAAA 2001:500:a8::e h.root-servers.net. 518400 IN A 198.97.190.53 h.root-servers.net. 518400 IN AAAA 2001:500:1::53 l.root-servers.net. 518400 IN A 199.7.83.42 l.root-servers.net. 518400 IN AAAA 2001:500:9f::42 i.root-servers.net. 518400 IN A 192.36.148.17 i.root-servers.net. 518400 IN AAAA 2001:7fe::53 a.root-servers.net. 518400 IN A 198.41.0.4 a.root-servers.net. 518400 IN AAAA 2001:503:ba3e::2:30 d.root-servers.net. 518400 IN A 199.7.91.13 d.root-servers.net. 518400 IN AAAA 2001:500:2d::d c.root-servers.net. 518400 IN A 192.33.4.12 ;; Query time: 68 msec ;; SERVER: 198.41.0.4#53(198.41.0.4) ;; WHEN: Thu May 25 03:26:39 2017 ;; MSG SIZE rcvd: 508
正向解析區(qū)域文件
正向解析區(qū)域文件用于映射域名和IP地址,文件中包含該文件區(qū)域的所有參數(shù),包括域名,IP地址、刷新時(shí)間、重試時(shí)間、和超時(shí)等。
資源記錄(Resource Record, RR)格式:
NAME(類型) [TTL](緩存時(shí)長(zhǎng)) IN RRT(DNS資源記錄類型) VALUE(數(shù)據(jù))
1、SOA(Start Of Authority): 起始授權(quán)記錄,只能有一個(gè)
name: 區(qū)域名稱, 通??梢院?jiǎn)寫為@,例如:magedu.com.
value: 主DNS服務(wù)器的FQDN
注意:SOA必須是區(qū)域數(shù)據(jù)庫文件第一條記錄
@ 600 IN SOA ns.magedu.com. dnsadmin.magedu.com.( serial number; 序列號(hào),十進(jìn)制數(shù)字,不超過10位,通常使用日期,如2014031001 refresh time ; 刷新時(shí)間,即每隔多久到主服務(wù)器檢查一次 retry time ; 重試時(shí)間,應(yīng)該小于refresh time expire time ; 過期時(shí)間 negative answer ttl ;否定答案的ttl )
2、NS(Name Server): ZONE NAME --> FQDN 名稱服務(wù)器,可以有多個(gè)
name: 區(qū)域名稱,通??梢院?jiǎn)寫為@
value: DNS服務(wù)器的FQDN(可以使用相對(duì)名稱)
@ 600 IN NS ns
3、MX(Mail eXchanger): ZONE NAME --> FQDN 郵件交換器
name: 區(qū)域名稱,用于標(biāo)識(shí)smtp服務(wù)器
value: 包含優(yōu)先級(jí)和FQDN,優(yōu)先級(jí):0-99, 數(shù)字越小,級(jí)別越高;
@ 600 IN MX 10 mail
4、A(address):FQDN-->IPv4 5、AAAA:FQDN-->IPv6
name: FQDN(可以使用相對(duì)名稱)
value: IP
www 600 IN A 192.168.1.2
6、PTR(pointer):IP-->FQDN只能定義在反向區(qū)域數(shù)據(jù)文件中
name: IP, 逆向的主機(jī)地址,例如172.16.100.7的name為7.100,
完全格式為7.100.16.172.in-addr.arpa.
value: FQDN
7.100 600 IN PTR www.maged.com.
7、CNAME(Canonical NAME): FQDN-->FQDN別名記錄
name: FQDN
value: FQDN
ftp IN CNAME www
一個(gè)完整的正向解析區(qū)域文件:
$TTL 1D @ IN SOA test.com. root.test.com.( 0 1D 1H 1W 3H ) IN NS dns.test.com. IN MX 10 mail1.test.com. IN MX 10 mail2.test.com. www IN A 192.168.1.101 mail1 IN A 192.168.1.102 mail2 IN A 192.168.1.103 dns IN A 192.168.1.104
反向解析區(qū)域文件
用于定義IP地址到域名的解析,它采用與正向解析文件類似的選項(xiàng)和格式。但由于是進(jìn)行反向解析,所以該文件是使用PTR指針記錄,而不是主機(jī)記錄。下面是一個(gè)反向解析的例子
$TTL 86400 @ IN SOA test.com. root.test.com.( 20031001 7200 3600 43200 86400 ) IN NS dns.test.com. 101 IN PTR www.test.com. 102 IN PTR mail1.test.com. 103 IN PTR mail2.test.com. 104 IN PTR dns.test.com.
DNS服務(wù)器類型
主DNS服務(wù)器:維護(hù)所負(fù)責(zé)解析的域內(nèi)解析庫服務(wù)器;解析庫由管理維護(hù); 從DNS服務(wù)器:從主DNS服務(wù)器或其它的從DNS服務(wù)器那里“復(fù)制”(區(qū)域傳遞)一份解析庫; 序列號(hào):解析庫的版本號(hào);前提:主服務(wù)器解析庫內(nèi)容發(fā)生變化,其序列遞增; 刷新時(shí)間間隔:從服務(wù)器從主服務(wù)器請(qǐng)求同步解析庫的時(shí)間間隔; 重試時(shí)間間隔:從服務(wù)器從主服務(wù)器請(qǐng)求同步解析庫失敗時(shí),再次嘗試的時(shí)間間隔; 過期時(shí)長(zhǎng):從服務(wù)器始終聯(lián)系不到主服務(wù)器時(shí),從服務(wù)器角度,停止提供服務(wù)。 緩存名稱服務(wù)器:非權(quán)威答案。 |
主從服務(wù)器同步的方式:
域:Domain(邏輯概念)區(qū)域:Zone(物理概念)
區(qū)域傳送:
全量區(qū)域傳送:傳送整個(gè)解析庫。AXFR
增量區(qū)域傳送:傳遞解析庫變化的那部分內(nèi)容。IXFR
rndc命令
rndc: Remote Name Domain Controller遠(yuǎn)程管理BIND的工具,默認(rèn)與bind安裝在一起,且只能通過127.0.0.1來連接named進(jìn)程;提供輔助性的管理功能。監(jiān)聽端口(953/tcp)。
rndc與bind通過密鑰進(jìn)行連接互信。
rndc: 持有一半密鑰,保存于rndc的配置文件中
BIND:持有一半密鑰,保存于主配置文件中
rndc的配置文件/etc/rndc.conf
在CentOS或RHEL系統(tǒng)中配置文件為: 密鑰文件/etc/rndc.key
命令格式:rndc COMMAND
reload: 重載主配置文件和區(qū)域解析庫文件 reload zone: 重載區(qū)域解析庫文件 retransfer zone: 手動(dòng)啟動(dòng)區(qū)域傳送過程,而不管序列號(hào)是否增加; notify zone: 重新對(duì)區(qū)域傳送發(fā)通知; reconfig: 重載主配置文件 querylog: 開啟或關(guān)閉查詢?nèi)罩荆?/p> trace: 遞增debug級(jí)別; trace LEVEL: 指定使用的級(jí)別 flush: 清空服務(wù)器的緩存 flushname name: 清空指定名稱相關(guān)的緩存 |
5.5、各種DNS服務(wù)器的配置方法
緩存名稱服務(wù)器
緩存名稱服務(wù)器配置十分簡(jiǎn)單,只需要通過yum安裝后,對(duì)主配置文件進(jìn)行一些修改即可。
[root@mylinux named]# vim /etc/named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { // listen-on port 53 { 127.0.0.1; }; 開放監(jiān)聽端口,或者添加外網(wǎng)地址 // listen-on port 53 { 0.0.0.0; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; 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 { localhost; }; 關(guān)閉僅允許主機(jī)遞歸 recursion yes; // dnssec-enable yes; 關(guān)閉dnssec // dnssec-validation yes; /* Path to ISC DLV key */ // bindkeys-file "/etc/named.iscdlv.key"; // managed-keys-directory "/var/named/dynamic"; }; .... [root@mylinux named]# service named restart #重啟服務(wù) Stopping named: [ OK ] Starting named: [ OK ] [root@mylinux named]# dig -t A www.baidu.com @192.168.191.128 #測(cè)試解析結(jié)果 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t A www.baidu.com @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55532 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 5, ADDITIONAL: 5 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 1200 IN CNAME www.a.shifen.com. www.a.shifen.com. 300 IN A 111.13.100.91 www.a.shifen.com. 300 IN A 111.13.100.92 ;; AUTHORITY SECTION: a.shifen.com. 1200 IN NS ns4.a.shifen.com. a.shifen.com. 1200 IN NS ns3.a.shifen.com. a.shifen.com. 1200 IN NS ns5.a.shifen.com. a.shifen.com. 1200 IN NS ns2.a.shifen.com. a.shifen.com. 1200 IN NS ns1.a.shifen.com. ;; ADDITIONAL SECTION: ns5.a.shifen.com. 1200 IN A 119.75.222.17 ns3.a.shifen.com. 1200 IN A 61.135.162.215 ns2.a.shifen.com. 1200 IN A 180.149.133.241 ns4.a.shifen.com. 1200 IN A 115.239.210.176 ns1.a.shifen.com. 1200 IN A 61.135.165.224 ;; Query time: 1102 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 21:12:03 2017 ;; MSG SIZE rcvd: 260
主DNS服務(wù)器
配置主DNS服務(wù)器時(shí),需要在主配置文件中定義區(qū)域,以及配置解析數(shù)據(jù)庫文件。
[root@mylinux named]# vim /etc/named.rfc1912.zones allow-update { none; }; }; zone "localhost" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "0.in-addr.arpa" IN { type master; file "named.empty"; allow-update { none; }; }; zone "mylinux.com" IN { ;添加的區(qū)域mylinux.com type master; file "mylinux.com.zone"; allow-update { none; }; }; "/etc/named.rfc1912.zones" 46L, 1022C written [root@mylinux named]# named-checkconf /etc/named.rfc1912.zones #檢查配置文件是否錯(cuò)誤 [root@mylinux named]# vim /var/named/mylinux.com.zone #解析數(shù)據(jù)庫文件 $TTL 1D @ IN SOA test.com. root.test.com.( 0 1D 1H 1W 3H ) @ IN NS dns @ IN MX 10 mail1 @ IN MX 10 mail2 dns IN A 192.168.1.104 www IN A 192.168.1.101 mail1 IN A 192.168.1.102 mail2 IN A 192.168.1.103 "mylinux.com.zone" 15L, 269C written [root@mylinux named]# named-checkzone @ /var/named/mylinux.com.zone #檢查數(shù)據(jù)解析是否錯(cuò)誤 zone ./IN: loaded serial 0 OK [root@mylinux named]# service named restart #重啟服務(wù) Stopping named: [ OK ] Starting named: [ OK ] [root@mylinux named]# dig -t A www.mylinux.com @192.168.191.128 #測(cè)試解析結(jié)果 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t A www.mylinux.com @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12794 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.mylinux.com. IN A ;; ANSWER SECTION: www.mylinux.com. 86400 IN A 192.168.1.101 ;; AUTHORITY SECTION: mylinux.com. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 1 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 21:39:52 2017 ;; MSG SIZE rcvd: 83 [root@mylinux named]# dig -t A mail1.mylinux.com @192.168.191.128 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t A mail1.mylinux.com @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37024 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;mail1.mylinux.com. IN A ;; ANSWER SECTION: mail1.mylinux.com. 86400 IN A 192.168.1.102 ;; AUTHORITY SECTION: mylinux.com. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 0 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 21:40:37 2017 ;; MSG SIZE rcvd: 85 [root@mylinux named]# dig -t A mail2.mylinux.com @192.168.191.128 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t A mail2.mylinux.com @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41030 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;mail2.mylinux.com. IN A ;; ANSWER SECTION: mail2.mylinux.com. 86400 IN A 192.168.1.103 ;; AUTHORITY SECTION: mylinux.com. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 0 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 21:40:48 2017 ;; MSG SIZE rcvd: 85 [root@mylinux named]#
反向解析
反向解析區(qū)域名稱一般以in-addr.arpa結(jié)尾,例如172.16.100.-->100.16.172.in-addr.arpa.
[root@mylinux named]# vim /etc/named. named.conf named.iscdlv.key named.root.key named.confbak named.rfc1912.zones [root@mylinux named]# vim /etc/named.rfc1912.zones file "named.localhost"; allow-update { none; }; }; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "0.in-addr.arpa" IN { type master; file "named.empty"; allow-update { none; }; }; zone "mylinux.com" IN { type master; file "mylinux.com.zone"; allow-update { none; }; }; zone "100.168.192.in-addr.arpa" IN { #定義反向區(qū)域 type master; file "100.168.192.arpa"; "/etc/named.rfc1912.zones" 51L, 1127C [root@mylinux named]# named-checkconf #檢查配置文件 [root@mylinux named]# vim 100.168.192.arpa #定義反向區(qū)域數(shù)據(jù)文件 $TTL 1D @ IN SOA mylinux.com. root.mylinux.com.( 0 1D 1H 1W 3H ) @ IN NS dns.mylinux.com. 1 IN PTR www.mylinux.com. 3 IN PTR mail1.mylinux.com. 4 IN PTR mail2.mylinux.com. 2 IN PTR dns.mylinux.com. "100.168.192.arpa" 13L, 259C written [root@mylinux named]# named-checkzone "100.168.192.in-addr.arpa" 100.168.192.arpa zone 100.168.192.in-addr.arpa/IN: loaded serial 0 #檢查數(shù)據(jù)區(qū)域文件語法錯(cuò)誤 OK [root@mylinux named]# service named reload #重載服務(wù) Reloading named: [ OK ] [root@mylinux named]# dig -x 192.168.100.1 @192.168.191.128 #測(cè)試解析結(jié)果 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -x 192.168.100.1 @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35918 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;1.100.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 1.100.168.192.in-addr.arpa. 86400 IN PTR www.mylinux.com. ;; AUTHORITY SECTION: 100.168.192.in-addr.arpa. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 0 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 22:33:34 2017 ;; MSG SIZE rcvd: 107 [root@mylinux named]# dig -x 192.168.100.2 @192.168.191.128 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -x 192.168.100.2 @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42216 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;2.100.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 2.100.168.192.in-addr.arpa. 86400 IN PTR dns.mylinux.com. ;; AUTHORITY SECTION: 100.168.192.in-addr.arpa. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 0 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 22:33:42 2017 ;; MSG SIZE rcvd: 103 [root@mylinux named]# dig -x 192.168.100.3 @192.168.191.128 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -x 192.168.100.3 @192.168.191.128 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27136 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;3.100.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 3.100.168.192.in-addr.arpa. 86400 IN PTR mail1.mylinux.com. ;; AUTHORITY SECTION: 100.168.192.in-addr.arpa. 86400 IN NS dns.mylinux.com. ;; ADDITIONAL SECTION: dns.mylinux.com. 86400 IN A 192.168.1.104 ;; Query time: 0 msec ;; SERVER: 192.168.191.128#53(192.168.191.128) ;; WHEN: Thu May 25 22:33:46 2017 ;; MSG SIZE rcvd: 109
主從DNS服務(wù)器的配置
1、從服務(wù)器應(yīng)該為一臺(tái)獨(dú)立的名稱服務(wù)器 2、主服務(wù)器的區(qū)域解析庫中必須有一條NS記錄指向從服務(wù)器 3、從服務(wù)器主需要定義區(qū)域,而無需提供解析庫文件,庫文件放在/var/named/slaves/目錄中 4、主服務(wù)器需要允許從服務(wù)器做區(qū)域傳送 |
從服務(wù)器的配置
[root@localhost ~]# vim /etc/named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { listen-on port 53 { 192.168.191.128; 127.0.0.1; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { // listen-on port 53 { 127.0.0.1; }; #取消僅監(jiān)聽本機(jī) listen-on-v6 port 53 { ::1; }; directory "/var/named"; 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; }; #允許查詢 recursion yes; // dnssec-enable yes; // dnssec-validation yes; /* Path to ISC DLV key */ // bindkeys-file "/etc/named.iscdlv.key"; // managed-keys-directory "/var/named/dynamic"; }; logging { "/etc/named.conf" 43L, 1005C written [root@localhost ~]# service named restart #啟動(dòng)服務(wù) Stopping named: [ OK ] Starting named: [ OK ] [root@localhost ~]# ss -tunlp | grep :53 #查看監(jiān)聽端口 udp UNCONN 0 0 192.168.191.129:53 *:* users:(("named",1432,513)) udp UNCONN 0 0 127.0.0.1:53 *:* users:(("named",1432,512)) udp UNCONN 0 0 ::1:53 :::* users:(("named",1432,514)) tcp LISTEN 0 3 ::1:53 :::* users:(("named",1432,22)) tcp LISTEN 0 3 192.168.191.129:53 *:* users:(("named",1432,21)) tcp LISTEN 0 3 127.0.0.1:53 *:* users:(("named",1432,20)) [root@localhost ~]# vim /etc/named.rfc1912.zones #定義從服務(wù)器配置文件 // named.rfc1912.zones: // // Provided by Red Hat caching-nameserver package // // ISC BIND named zone configuration for zones recommended by // RFC 1912 section 4.1 : localhost TLDs and address zones // and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt // (c)2007 R W Franks // // See /usr/share/doc/bind*/sample/ for example named configuration files. // zone "localhost.localdomain" IN { type master; file "named.localhost"; }; allow-update { none; }; }; zone "localhost" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "0.in-addr.arpa" IN { type master; file "named.empty"; allow-update { none; }; }; zone "mylinux.com" IN { #從服務(wù)器域文件 type slave; masters { 192.168.191.128;}; file "slaves/mylinux.com.zone"; "/etc/named.rfc1912.zones" 48L, 1080C written [root@localhost ~]# service named start Starting named: named: already running[ OK ]
在主DNS服務(wù)器中必須要有從服務(wù)器的NS記錄,才會(huì)通知從服務(wù)器讀取數(shù)據(jù),否則不會(huì)通知。
[root@mylinux named]# service named reload #重載DNS主服務(wù)器 Reloading named: [ OK ] [root@mylinux named]# tail /var/log/messages #查看日志信息 May 25 23:15:25 mylinux named[2037]: received control channel command 'reload' May 25 23:15:25 mylinux named[2037]: loading configuration from '/etc/named.conf' May 25 23:15:25 mylinux named[2037]: using default UDP/IPv4 port range: [1024, 65535] May 25 23:15:25 mylinux named[2037]: using default UDP/IPv6 port range: [1024, 65535] May 25 23:15:25 mylinux named[2037]: sizing zone task pool based on 8 zones May 25 23:15:25 mylinux named[2037]: Warning: 'empty-zones-enable/disable-empty-zone' not set: disabling RFC 1918 empty zones May 25 23:15:25 mylinux named[2037]: reloading configuration succeeded May 25 23:15:25 mylinux named[2037]: reloading zones succeeded May 25 23:15:25 mylinux named[2037]: zone mylinux.com/IN: loaded serial 3 May 25 23:15:25 mylinux named[2037]: zone mylinux.com/IN: sending notifies (serial 3)
查看從服務(wù)器是否讀取到數(shù)據(jù)
[root@localhost slaves]# cat /var/named/slaves/mylinux.com.zone $ORIGIN . $TTL 86400 ; 1 day mylinux.com IN SOA mylinux.com. root.mylinux.com. ( 3 ; serial 86400 ; refresh (1 day) 3600 ; retry (1 hour) 604800 ; expire (1 week) 10800 ; minimum (3 hours) ) NS dns.mylinux.com. NS dns2.mylinux.com. MX 10 mail1.mylinux.com. MX 10 mail2.mylinux.com. $ORIGIN mylinux.com. dns A 192.168.1.104 dns2 A 192.168.191.129 mail1 A 192.168.1.102 mail2 A 192.168.1.103 www A 192.168.1.101
子域授權(quán)
在父域的資源記錄文件中添加如下項(xiàng):授權(quán)的子區(qū)域名稱;子區(qū)域的名稱服務(wù)器;子區(qū)域的名稱服務(wù)器的IP地址:
mylinux.com. IN NS ns.mylinux.com. (授權(quán)的子域服務(wù)器名稱) mylinux.com. IN NS ns2.mylinux.com. ns.mylinux.com. IN A 192.168.100.1 (子域服務(wù)器的IP地址) ns2.mylinux.com. IN A 192.168.100.2
轉(zhuǎn)發(fā)服務(wù)器
被轉(zhuǎn)發(fā)的服務(wù)器需要能夠?yàn)檎?qǐng)求者做遞歸,否則,轉(zhuǎn)發(fā)請(qǐng)求不予進(jìn)行。
全部轉(zhuǎn)發(fā),凡是對(duì)非本機(jī)所負(fù)責(zé)的區(qū)域請(qǐng)求,都進(jìn)行轉(zhuǎn)發(fā)給指定服務(wù)器
配置文件中添加配置: options { forward only|first; forwarders { IP; }; }
區(qū)域轉(zhuǎn)發(fā),僅轉(zhuǎn)發(fā)對(duì)特定的區(qū)域的請(qǐng)求至服務(wù)器
配置文件中添加區(qū)域配置: zone "特定區(qū)域" IN { type forward; forwarders { IP; } forward only|first; }
視圖
內(nèi)網(wǎng): server1.company.com 172.20.1.1 server2.company.com 172.20.1.2 server3.company.com 172.20.1.3 server4.company.com 172.20.1.4 外網(wǎng): ftp.company.com 61.124.100.1 www.company.com 61.124.100.2 mail.company.com 61.124.100.3 |
配置如圖所示的網(wǎng)絡(luò)DNS網(wǎng)絡(luò)拓?fù)浣Y(jié)構(gòu),內(nèi)網(wǎng)用戶可以使用正向解析所有內(nèi)網(wǎng)計(jì)算機(jī)以及外網(wǎng)的服務(wù)器,反向解析內(nèi)網(wǎng)服務(wù)器,允許遞歸查詢;外用用戶只能正向解析外網(wǎng)服務(wù)器,不能解析內(nèi)網(wǎng)服務(wù)器,不允許使用遞歸查詢。使用視圖時(shí),就必須所有的zone都?xì)w類到view中。
配置區(qū)域文件
[root@mylinux ~]# vim /etc/named.rfc1912.zones view "internal" { match-clients {172.20.1.0/24; }; recursion yes ; zone "localhost" IN { type master; file "localhost-internal.zone"; allow-update {none;}; }; zone "0.0.127.in-addr.arpa" IN { type master; file "localhost-internal.arpa"; allow-update { none;} ; }; zone "company.com" IN { type master; file "company-internal.zone"; allow-update {none;}; }; zone "1.20.127.in-addr.arpa" IN { type master; file "company-internal.arpa"; allow-update { none;} ; }; }; view "external" { match-clients { any; }; recursion no ; zone "." IN { type hint; file "root.ca"; }; zone "company.com" IN { type master; file "company-external.zone"; allow-update { none; }; }; }; [root@mylinux ~]# named-checkconf
localhost-internal.zone數(shù)據(jù)解析文件
[root@mylinux named]# vim localhost-internal.zone $TTL 86400 @ IN SOA localhost. root.localhost( 42 3H 15M 1W 1D ) @ 1D IN NS dns.localhost. dns 1D IN A 127.0.0.1 [root@mylinux named]# named-checkzone 'localhost' /var/named/localhost-internal.zone zone localhost-internal/IN: loaded serial 42 OK
localhost-inter.arpa反向解析文件
[root@mylinux named]# vim localhost-internal.arpa $TTL 86400 @ IN SOA localhost. root.localhost( 42 3H 15M 1W 1D ) @ 1D IN NS localhost. 1 1D IN PTR localhost. [root@mylinux named]# named-checkzone '0.0.127.in-addr.arpa' /var/named/localhost-internal.arpa zone 0.0.127.in-addr.arpa/IN: loaded serial 42 OK
company-internal.zone解析文件
[root@mylinux named]# vim company-internal.zone $TTL 1D @ IN SOA company.com. root.company.com. ( 1054654658 3H 5M 1W 1D) IN NS dns.company.com. IN MX 5 mail.com.com. ftp IN A 61.124.100.1 www IN A 61.124.100.2 mail IN A 61.124.100.3 dns IN A 172.20.1.11 servel1 IN A 172.20.1.1 servel2 IN A 172.20.1.2 servel3 IN A 172.20.1.3 servel4 IN A 172.20.1.4 "company-internal.zone" [New] 17L, 403C written [root@mylinux named]# named-checkzone 'company.com' /var/named/company-internal.zone zone company-internal/IN: loaded serial 1054654658 OK [root@mylinux named]#
company-internal.arpa反向解析文件
[root@mylinux named]# vim company-internal.arpa IN MX 5 mail.com.com. ftp IN A 61.124.100.1 www IN A 61.124.100.2 mail IN A 61.124.100.3 dns IN A 172.20.1.11 servel1 IN A 172.20.1.1 servel2 IN A 172.20.1.2 servel3 IN A 172.20.1.3 1 IN PTR server1.company.com. $TTL 1D @ IN SOA company.com. root.company.com. ( 1054654658 3H 5M 1W 1D) @ IN NS dns.company.com. 1 IN PTR server1.company.com. 2 IN PTR server2.company.com. 3 IN PTR server3.company.com. 4 IN PTR server4.company.com. 11 IN PTR dns.company.com. "company-internal.arpa" 13L, 256C written [root@mylinux named]# named-checkzone '1.20.127.in-addr.arpa' /var/named/company-internal.arpa zone 1.20.127.in-addr.arpa/IN: loaded serial 1054654658 OK
company-external.zone解析文件
[root@mylinux named]# vim company-external.zone $TTL 1D @ IN SOA company.com. root.company.com. ( 1054654658 3H 5M 1W 1D) IN NS dns.company.com. IN MX 5 mail.com.com. ftp IN A 61.124.100.1 www IN A 61.124.100.2 mail IN A 61.124.100.3 dns IN A 172.20.1.11 "company-external.zone" 13L, 263C written [root@mylinux named]# named-checkzone 'company-external' /var/named/company-external.zone zone company-external/IN: loaded serial 1054654658 OK
重啟即可測(cè)試:
[root@mylinux named]# service named restart Stopping named: [ OK ] Starting named: [ OK ]
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。