DNS(Domain Name System,域名系統)
因特網上做爲域名和IP地址相互映射的一個分佈式數據庫,可以使用戶方便的訪問互聯網,而不用去記住可以被機器讀取的IP數串。
經過主機名,最終獲得該主機名對應的IP地址的過程叫作域名解析(或主機名解析),DNS協議運行在UDP協議之上,使用端口號53
DNS的分佈式數據庫是以域名爲索引的,每一個域名實際上就是一顆很大的逆向數中路徑,這棵逆向樹成爲域名空間(domain name space)
樹的最大深度不超過127層,樹種每一個節點都有一個能夠長達63個字符的文本符號。node
簡單地說就是一個IP地址和域名之間的轉換系統,方便用戶經過域名訪問正確的服務地址,而不用記住不易區分的具體IP。DNS協議運行在UDP協議之上,使用端口53。linux
DNS的分類
主DNS服務器:就是一臺存儲着原始資料的DNS服務器
從DNS服務器:使用自動更新方式從主DNS服務器同步數據的DNS服務器,也稱輔助DNS服務器
緩存服務器:不負責本地解析,採用遞歸方式轉發客戶機查詢請求,並返回結果給客戶機的DNS服務器,同時緩存查詢回來的結果,也叫遞歸服務器。
轉發器:這臺DNS發現非本機負責的請求後,再也不向根發起請求,而是直接轉發給指定的一臺或多臺服務器,自身並不保存查詢結果數據庫
10.0.1.161 m01 主DNS(Master DNS)
10.0.1.162 m02 從DNS(Slave DNS)vim
系統版本號後端
[root@linux-node1 ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@linux-node1 ~]# uname -rm 2.6.32-504.el6.x86_64 x86_64 [root@linux-node1 ~]# [root@linux-node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.0.1.161 linux-node1.example.com linux-node1 10.0.1.162 linux-node2.example.com linux-node2 [root@linux-node1 ~]#
[root@linux-node1 ~]# host baidu.com baidu.com has address 180.149.132.47 baidu.com has address 220.181.57.217 baidu.com has address 111.13.101.208 baidu.com has address 123.125.114.144 baidu.com mail is handled by 20 jpmx.baidu.com. baidu.com mail is handled by 20 mx50.baidu.com. baidu.com mail is handled by 10 mx.n.shifen.com. baidu.com mail is handled by 20 mx1.baidu.com. [root@linux-node1 ~]#
nslookup顯示的更多,會把nameserver也顯示出來瀏覽器
[root@linux-node1 ~]# nslookup baidu.com Server: 10.0.2.15 Address: 10.0.2.15#53 Non-authoritative answer: Name: baidu.com Address: 111.13.101.208 Name: baidu.com Address: 123.125.114.144 Name: baidu.com Address: 180.149.132.47 Name: baidu.com Address: 220.181.57.217 [root@linux-node1 ~]#
dig命令緩存
[root@linux-node1 ~]# dig baidu.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22215 ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;baidu.com. IN A ;; ANSWER SECTION: baidu.com. 59 IN A 123.125.114.144 baidu.com. 59 IN A 180.149.132.47 baidu.com. 59 IN A 220.181.57.217 baidu.com. 59 IN A 111.13.101.208 ;; Query time: 1 msec ;; SERVER: 10.0.2.15#53(10.0.2.15) ;; WHEN: Sat May 13 21:41:26 2017 ;; MSG SIZE rcvd: 91 [root@linux-node1 ~]#
主dns上安裝bindbash
[root@linux-node1 yum.repos.d]# yum install -y bind-utils bind bind-devel bind-chroot Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.163.com * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.163.com * updates: mirrors.aliyun.com Package 32:bind-utils-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-devel-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-chroot-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Nothing to do [root@linux-node1 yum.repos.d]#
[root@linux-node1 yum.repos.d]# rpm -qa | grep "^bind" bind-chroot-9.8.2-0.62.rc1.el6_9.2.x86_64 bind-9.8.2-0.62.rc1.el6_9.2.x86_64 bind-libs-9.8.2-0.62.rc1.el6_9.2.x86_64 bind-devel-9.8.2-0.62.rc1.el6_9.2.x86_64 bind-utils-9.8.2-0.62.rc1.el6_9.2.x86_64 [root@linux-node1 yum.repos.d]#
編輯dns主配置文件,清空原先的內容。新的內容寫以下服務器
[root@linux-node1 ~]# vim /etc/named.conf [root@linux-node1 ~]# cat /etc/named.conf options { version "1.1.1"; listen-on port 53 {any;}; directory "/var/named/chroot/etc/"; pid-file "/var/named/chroot/var/run/named/named.pid"; allow-query { any; }; Dump-file "/var/named/chroot/var/log/binddump.db"; Statistics-file "/var/named/chroot/var/log/named_stats"; zone-statistics yes; memstatistics-file "log/mem_stats"; empty-zones-enable no; forwarders {202.106.196.115;8.8.8.8; }; }; key "rndc-key" { algorithm hmac-md5; secret "Eqw4hClGExUWeDkKBX/pBg=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; logging { channel warning { file "/var/named/chroot/var/log/dns_warning" versions 10 size 10m; severity warning; print-category yes; print-severity yes; print-time yes; }; channel general_dns { file "/var/named/chroot/var/log/dns_log" versions 10 size 100m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { warning; }; category queries { general_dns; }; }; include "/var/named/chroot/etc/view.conf"; [root@linux-node1 ~]#
上面主配置文件詳解網絡
options { version "1.1.1"; listen-on port 53 {any;}; #監控端口 directory "/var/named/chroot/etc/"; #A記錄等配置文件所在的目錄 pid-file "/var/named/chroot/var/run/named/named.pid"; 服務器來的進程號 allow-query { any; }; #容許誰訪問{}能夠寫IP Dump-file "/var/named/chroot/var/log/binddump.db"; Statistics-file "/var/named/chroot/var/log/named_stats"; #能夠看到DNS解析記錄的數量,成功率有多少域(能夠作監控)DNS狀態等 zone-statistics yes; #配成yes以後上面纔會寫入 memstatistics-file "log/mem_stats"; #內存狀態 empty-zones-enable no; forwarders {202.106.196.115;8.8.8.8; }; 轉發(若是我這沒有域名就轉發) }; key "rndc-key" { 認證的密鑰 algorithm hmac-md5; secret "Eqw4hClGExUWeDkKBX/pBg=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; logging { 日誌 警告路徑 (日誌分2種) channel warning { 日誌的相關信息 file "/var/named/chroot/var/log/dns_warning" versions 10 size 10m; severity warning; print-category yes; print-severity yes; print-time yes; }; channel general_dns { 訪問日誌相關信息 file "/var/named/chroot/var/log/dns_log" versions 10 size 100m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { #默認日誌警告級別 warning; }; category queries { #訪問日誌級別 general_dns; }; }; include "/var/named/chroot/etc/view.conf"; 其餘域的配置文件目錄(view.conf能夠實現簡單的只能DNS的功能,爲之後的只能DNS作準備)
除了這個文件的配置,dns的一些其餘的配置,好比zone的配置。你可使用rndc reload生效,這個就是rndc的做用
channel warning { file "/var/named/chroot/var/log/dns_warning" versions 10 size 10m; severity warning; print-category yes; print-severity yes; print-time yes; }; channel general_dns { file "/var/named/chroot/var/log/dns_log" versions 10 size 10m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { warning; }; category queries { general_dns; };
Statistics-file "/var/named/chroot/var/log/named_stats";
建立rndc.key和rndc.conf文件
[root@linux-node1 ~]# cat /etc/rndc.key key "rndc-key" { algorithm hmac-md5; secret "Eqw4hClGExUWeDkKBX/pBg=="; }; [root@linux-node1 ~]# [root@linux-node1 ~]# cat /etc/rndc.conf key "rndc-key" { algorithm hmac-md5; secret "Eqw4hClGExUWeDkKBX/pBg=="; }; options { default-key "rndc-key"; default-server 127.0.0.1; default-port 953; }; [root@linux-node1 ~]#
編輯view.conf文件
下面的allow-transfer表示容許下面主機來取數據,注意不是請求dns解析,而是用於從dns請求配置文件裏的數據
also-notify表示文件更新時,執行rndc reload時通知哪一個從dns來取數據。這樣就達到了主從同步的效果
[root@linux-node1 ~]# cat /var/named/chroot/etc/view.conf view "View" { zone "lnh.com" { type master; file "lnh.com.zone"; allow-transfer { 10.0.1.162; }; notify yes; also-notify { 10.0.1.162; }; }; }; [root@linux-node1 ~]#
[root@linux-node1 ~]# vim /var/named/chroot/etc/lnh.com.zone [root@linux-node1 ~]# cat /var/named/chroot/etc/lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2003 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. shanks A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.101 [root@linux-node1 ~]#
上面關於zone文件解釋說明
一、Serial:只是一個序號,但這個序號可被用來做爲slave與master更新的依據。舉例來講。
master序號100 但salve序號爲90時,那麼這個zonefile的資料就會被傳送到slave來更新了
因爲序號表明新舊資料,一般咱們建議能夠利用日期來設定!舉例來講,在2006/10/20
所更新文件,能夠用2006102001做爲序號表明!(yyyymmddnn,nn表明這一天第幾回修改)
二、Refresh:除了根據Serial來判斷新舊以外,咱們能夠利用這個refresh(更新)命令,slave多久進行一次主動更新。
三、Retry:若是到了Refresh的時間,可是slave卻沒法鏈接到master時,那麼在多久以後,slave會再次的主動嘗試與主機連線
四、Expire:若是slave一直沒法與master鏈接上,那麼通過多久的時間以後,則命令slave不要再鏈接master了!也就是說,此時咱們假設master DNS
可能遇到重大問題而沒法上線,則等待系統管理員處理完畢後,再從新來到slave DNS從新啓動bind吧
五、Minimun:這個就有點像是TTL!
區域解析庫文件的簡要說明: 常見的正解文件 RR 相關信息 [domain] IN [[RR type] [RR data]] 主機名. IN A IPv4 的 IP 地址 主機名. IN AAAA IPv6 的 IP 地址 區域名. IN NS 管理這個領域名的服務器主機名字. 區域名. IN SOA 管理這個領域名的七個重要參數(如上說明) 區域名. IN MX 順序數字 接收郵件的服務器主機名字 主機別名. IN CNAME 實際表明這個主機別名的主機名字. 單位:W=周、D=日、H=小時、M=分鐘。 $TTL 86400 宏定義全局TTL時間 @ IN SOA ns.chinasoft.com. root ( # ns.chinasoft.com. 是DNS服務器的名稱 0 ; serial (d. adams) 僅做爲序列號而已 1D ;refresh 服務器的更新時間 15M ; retry 從新更新時間間隔 1W ; expiry 多久以後宣佈失敗 1H ) ;minimum 至關於緩存記憶時間 @ IN NS ns.chinasoft.com. @ IN MX 5 mail.chinasoft.com.(5爲優先級別) ns IN A 1.2.3.4 www IN A 1.2.3.4 www IN A 1.2.3.4 mail IN A 1.2.3.4
[root@linux-node1 var]# cd /var && chown -R named.named named/ [root@linux-node1 var]# /etc/init.d/named start Starting named: [ OK ] [root@linux-node1 var]# chkconfig named on [root@linux-node1 var]#
檢查端口
[root@linux-node1 var]# netstat -lntup | grep 53 tcp 0 0 10.0.1.161:53 0.0.0.0:* LISTEN 7060/named tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 7060/named tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 7060/named udp 0 0 10.0.1.161:53 0.0.0.0:* 7060/named udp 0 0 127.0.0.1:53 0.0.0.0:* 7060/named [root@linux-node1 var]#
若是對zone文件更改,可使用rndc reload讓其生效
[root@linux-node1 var]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 var]#
使用dig命令測試
[root@linux-node1 var]# dig @127.0.0.1 a.lnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> @127.0.0.1 a.lnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57403 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;a.lnh.com. IN A ;; ANSWER SECTION: a.lnh.com. 3600 IN A 192.168.122.101 a.lnh.com. 3600 IN A 1.2.3.4 ;; AUTHORITY SECTION: lnh.com. 3600 IN NS op.lnh.com. ;; ADDITIONAL SECTION: op.lnh.com. 3600 IN A 1.2.3.4 ;; Query time: 1 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Mon May 15 22:20:39 2017 ;; MSG SIZE rcvd: 92 [root@linux-node1 var]#
[root@linux-node2 yum.repos.d]# yum install bind-utils bind bind-devel bind-chroot -y Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.ustc.edu.cn * extras: mirrors.zju.edu.cn * updates: mirrors.aliyun.com Package 32:bind-utils-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-devel-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Package 32:bind-chroot-9.8.2-0.62.rc1.el6_9.2.x86_64 already installed and latest version Nothing to do [root@linux-node2 yum.repos.d]#
[root@linux-node1 var]# scp /etc/named.conf 10.0.1.162:/etc/ root@10.0.1.162's password: named.conf 100% 1121 1.1KB/s 00:00 [root@linux-node1 var]# scp /etc/rndc.key 10.0.1.162:/etc/ root@10.0.1.162's password: rndc.key 100% 91 0.1KB/s 00:00 [root@linux-node1 var]# scp /etc/rndc.conf 10.0.1.162:/etc/ root@10.0.1.162's password: rndc.conf 100% 181 0.2KB/s 00:00 [root@linux-node1 var]#
[root@linux-node2 ~]# vim /var/named/chroot/etc/view.conf [root@linux-node2 ~]# cat /var/named/chroot/etc/view.conf view "SlaveView" { zone "lnh.com" { type slave; masters {10.0.1.161;}; file "slave.lnh.com.zone"; }; }; [root@linux-node2 ~]#
[root@linux-node2 ~]# cd /var && chown -R named.named named/ [root@linux-node2 var]# /etc/init.d/named start Starting named: [ OK ] [root@linux-node2 var]# [root@linux-node2 var]# chkconfig named on [root@linux-node2 var]#
它自動生成從的zone文件
[root@linux-node2 var]# ll /var/named/chroot/etc/ total 676 -rw-r--r-- 1 root root 388 Sep 17 2014 localtime drwxr-x--- 2 root named 4096 May 9 21:43 named -rw-r----- 1 root named 1891 May 14 19:05 named.conf -rw-r--r-- 1 root named 2389 May 9 21:43 named.iscdlv.key -rw-r----- 1 root named 931 Jun 21 2007 named.rfc1912.zones -rw-r--r-- 1 root named 487 Jul 19 2010 named.root.key drwxr-x--- 3 named named 4096 May 14 19:03 pki -rw-r--r--. 1 root root 6455 Jan 12 2010 protocols -rw-r--r-- 1 root root 90 May 14 19:06 rndc.conf -rw-r--r--. 1 root root 641020 Oct 2 2013 services -rw-r--r-- 1 named named 326 May 14 20:00 slave.lnh.com.zone -rw-r--r-- 1 named named 129 May 14 20:00 view.conf
[root@linux-node2 var]# cat /var/named/chroot/etc/slave.lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2000 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. a A 1.2.3.4 op A 1.2.3.4 shanks A 1.2.3.4 [root@linux-node2 var]#
測試主從
主dns服務器把zone文件序號改爲2004
[root@linux-node1 var]# cd /var/named/chroot/etc/ [root@linux-node1 etc]# vim lnh.com.zone [root@linux-node1 etc]# cat lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. shanks A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.101 [root@linux-node1 etc]#
[root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node2 etc]# cat slave.lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. a A 1.2.3.4 A 192.168.122.101 op A 1.2.3.4 shanks A 1.2.3.4 [root@linux-node2 etc]#
[root@linux-node1 etc]# vim lnh.com.zone [root@linux-node1 etc]# cat lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. shanks A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.101 [root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
主dns上執行rndc reload
[root@linux-node2 etc]# cat slave.lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. a A 1.2.3.4 A 192.168.122.101 op A 1.2.3.4 shanks A 1.2.3.4 [root@linux-node2 etc]#
[root@linux-node1 etc]# cat lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2005 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. shanks A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.101 cname CNAME a.lnh.com. [root@linux-node1 etc]# [root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node2 etc]# cat slave.lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2005 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. a A 1.2.3.4 A 192.168.122.101 cname CNAME a op A 1.2.3.4 shanks A 1.2.3.4 [root@linux-node2 etc]#
[root@linux-node1 etc]# dig @10.0.1.161 cname.lnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> @10.0.1.161 cname.lnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53265 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;cname.lnh.com. IN A ;; ANSWER SECTION: cname.lnh.com. 3600 IN CNAME a.lnh.com. a.lnh.com. 3600 IN A 192.168.122.101 a.lnh.com. 3600 IN A 1.2.3.4 ;; AUTHORITY SECTION: lnh.com. 3600 IN NS op.lnh.com. ;; ADDITIONAL SECTION: op.lnh.com. 3600 IN A 1.2.3.4 ;; Query time: 1 msec ;; SERVER: 10.0.1.161#53(10.0.1.161) ;; WHEN: Mon May 15 23:09:22 2017 ;; MSG SIZE rcvd: 112 [root@linux-node1 etc]#
[root@linux-node1 etc]# dig @10.0.1.162 cname.lnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> @10.0.1.162 cname.lnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6767 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;cname.lnh.com. IN A ;; ANSWER SECTION: cname.lnh.com. 3600 IN CNAME a.lnh.com. a.lnh.com. 3600 IN A 192.168.122.101 a.lnh.com. 3600 IN A 1.2.3.4 ;; AUTHORITY SECTION: lnh.com. 3600 IN NS op.lnh.com. ;; ADDITIONAL SECTION: op.lnh.com. 3600 IN A 1.2.3.4 ;; Query time: 2 msec ;; SERVER: 10.0.1.162#53(10.0.1.162) ;; WHEN: Mon May 15 23:10:43 2017 ;; MSG SIZE rcvd: 112 [root@linux-node1 etc]#
MX記錄學習
MX記錄和A記錄差很少,MX是關於郵件服務的解析的
[root@linux-node1 etc]# vim lnh.com.zone [root@linux-node1 etc]# cat lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2006 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. shanks A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.101 cname CNAME a.lnh.com. mx MX 5 192.168.122.101 [root@linux-node1 etc]#
記得序列號更新下,能夠+1
[root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node2 etc]# cat slave.lnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour lnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2006 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN lnh.com. a A 1.2.3.4 A 192.168.122.101 cname CNAME a mx MX 5 192.168.122.101 op A 1.2.3.4 shanks A 1.2.3.4 [root@linux-node2 etc]#
[root@linux-node1 etc]# dig @10.0.1.162 mx.lnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> @10.0.1.162 mx.lnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31263 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;mx.lnh.com. IN A ;; AUTHORITY SECTION: lnh.com. 3600 IN SOA op.lnh.com. dns.lnh.com. 2006 900 600 86400 3600 ;; Query time: 1 msec ;; SERVER: 10.0.1.162#53(10.0.1.162) ;; WHEN: Mon May 15 23:17:57 2017 ;; MSG SIZE rcvd: 71 [root@linux-node1 etc]#
[root@linux-node1 etc]# host mx.lnh.com 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: mx.lnh.com mail is handled by 5 192.168.122.101.lnh.com. [root@linux-node1 etc]# [root@linux-node1 etc]# host mx.lnh.com 10.0.1.162 Using domain server: Name: 10.0.1.162 Address: 10.0.1.162#53 Aliases: mx.lnh.com mail is handled by 5 192.168.122.101.lnh.com. [root@linux-node1 etc]#
添加RTP記錄(反向解析)
做用:可讓人根據IP獲取到主機名,從而判斷主機用途
編輯maste節點/var/named/chroot/etc/view.conf,加入ptr的zone配置
in-addr.arpa已經成爲業界共識了,做爲ptr用的
168.192是IP地址反過來
主dns服務器上以下編輯view文件,添加新的zone
[root@linux-node1 ~]# vim /var/named/chroot/etc/view.conf [root@linux-node1 ~]# cat /var/named/chroot/etc/view.conf view "View" { zone "lnh.com" { type master; file "lnh.com.zone"; allow-transfer { 10.0.1.162; }; notify yes; also-notify { 10.0.1.162; }; }; zone "168.192.in-addr.arpa" { type master; file "168.192.zone"; allow-transfer { 10.0.1.162; }; notify yes; also-notify { 10.0.1.162; }; }; }; [root@linux-node1 ~]#
[root@linux-node1 ~]# vim /var/named/chroot/etc/168.192.zone [root@linux-node1 ~]# cat /var/named/chroot/etc/168.192.zone $TTL 3600 ; 1 hour @ IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. 102.122 IN PTR a.lnh.com. [root@linux-node1 ~]#
@ 表示繼承 zone "168.192.in-addr.arpa"
沒有@的話,前面就得用
$ORIGIN .
了
文件受權,並從新加載
[root@linux-node1 ~]# cd /var/named/chroot/etc/ [root@linux-node1 etc]# ll total 684 -rw-r--r-- 1 root root 503 May 15 23:43 168.192.zone -rw-r--r-- 1 named named 536 May 15 23:14 lnh.com.zone -rw-r--r-- 1 root root 388 Sep 17 2014 localtime drwxr-x--- 2 named named 4096 May 9 21:43 named -rw-r--r-- 1 named named 1121 May 14 21:16 named.conf -rw-r--r-- 1 named named 2389 May 9 21:43 named.iscdlv.key -rw-r----- 1 named named 931 Jun 21 2007 named.rfc1912.zones -rw-r--r-- 1 named named 487 Jul 19 2010 named.root.key drwxr-x--- 3 named named 4096 May 13 21:53 pki -rw-r--r--. 1 named named 6455 Jan 12 2010 protocols -rw-r--r-- 1 named named 181 May 14 20:45 rndc.conf -rw-r--r-- 1 named named 91 May 14 20:53 rndc.key -rw-r--r--. 1 named named 641020 Oct 2 2013 services -rw-r--r-- 1 named named 434 May 15 23:39 view.conf [root@linux-node1 etc]# chown named:named 168.192.zone [root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node2 etc]# vim /var/named/chroot/etc/view.conf [root@linux-node2 etc]# cat /var/named/chroot/etc/view.conf view "SlaveView" { zone "lnh.com" { type slave; masters {10.0.1.161;}; file "slave.lnh.com.zone"; }; zone "168.192.in-addr.arpa" { type slave; masters {10.0.1.161; }; file "slave.168.192.zone"; }; }; [root@linux-node2 etc]#
從上更改權限並從新加載配置
[root@linux-node2 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node2 etc]# [root@linux-node2 etc]# cd /var/named/chroot/etc/ [root@linux-node2 etc]# ll total 684 -rw-r--r-- 1 root root 388 Sep 17 2014 localtime drwxr-x--- 2 root named 4096 May 9 21:43 named -rw-r----- 1 root named 1121 May 15 22:36 named.conf -rw-r--r-- 1 root named 2389 May 9 21:43 named.iscdlv.key -rw-r----- 1 root named 931 Jun 21 2007 named.rfc1912.zones -rw-r--r-- 1 root named 487 Jul 19 2010 named.root.key drwxr-x--- 3 named named 4096 May 14 19:03 pki -rw-r--r--. 1 root root 6455 Jan 12 2010 protocols -rw-r--r-- 1 root root 181 May 15 22:37 rndc.conf -rw-r--r-- 1 root root 91 May 15 22:37 rndc.key -rw-r--r--. 1 root root 641020 Oct 2 2013 services -rw-r--r-- 1 named named 327 May 15 23:58 slave.168.192.zone -rw-r--r-- 1 named named 389 May 15 23:54 slave.lnh.com.zone -rw-r--r-- 1 named named 251 May 15 23:50 view.conf [root@linux-node2 etc]#
[root@linux-node2 etc]# cat slave.168.192.zone $ORIGIN . $TTL 3600 ; 1 hour 168.192.in-addr.arpa IN SOA op.lnh.com. dns.lnh.com. ( 2004 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN 168.192.in-addr.arpa. 102.122 PTR a.lnh.com. [root@linux-node2 etc]#
[root@linux-node1 etc]# host 192.168.122.102 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: 102.122.168.192.in-addr.arpa domain name pointer a.lnh.com. [root@linux-node1 etc]# host 192.168.122.102 10.0.1.162 Using domain server: Name: 10.0.1.162 Address: 10.0.1.162#53 Aliases: 102.122.168.192.in-addr.arpa domain name pointer a.lnh.com. [root@linux-node1 etc]#
測試dns解析的輪詢功能
衝新加載服務
[root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node1 etc]# nslookup a.lnh.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.lnh.com Address: 192.168.122.101 Name: a.lnh.com Address: 192.168.122.102 Name: a.lnh.com Address: 1.2.3.4 [root@linux-node1 etc]# nslookup a.lnh.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.lnh.com Address: 192.168.122.102 Name: a.lnh.com Address: 1.2.3.4 Name: a.lnh.com Address: 192.168.122.101 [root@linux-node1 etc]# nslookup a.lnh.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.lnh.com Address: 1.2.3.4 Name: a.lnh.com Address: 192.168.122.101 Name: a.lnh.com Address: 192.168.122.102 [root@linux-node1 etc]#
測試智能dns,根據源IP不一樣解析到對應的IP
[root@linux-node1 etc]# vim /var/named/chroot/etc/view.conf [root@linux-node1 etc]# cat /var/named/chroot/etc/view.conf view "GROUP1" { match-clients { group1; }; zone "viewlnh.com" { type master; file "group1.viewlnh.com.zone"; }; }; view "GROUP2" { match-clients { group2; }; zone "viewlnh.com" { type master; file "group2.viewlnh.com.zone"; }; }; [root@linux-node1 etc]#
[root@linux-node1 etc]# vim group1.viewlnh.com.zone [root@linux-node1 etc]# cat /var/named/chroot/etc/group1.viewlnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour viewlnh.com IN SOA op.viewlnh.com. dns.viewlnh.com. ( 2009 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.viewlnh.com. $ORIGIN viewlnh.com. op A 192.168.122.1 view A 192.168.122.1 [root@linux-node1 etc]#
[root@linux-node1 etc]# vim /var/named/chroot/etc/group2.viewlnh.com.zone [root@linux-node1 etc]# cat /var/named/chroot/etc/group2.viewlnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour viewlnh.com IN SOA op.viewlnh.com. dns.viewlnh.com. ( 2009 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.viewlnh.com. $ORIGIN viewlnh.com. op A 192.168.122.2 view A 192.168.122.2 [root@linux-node1 etc]# [root@linux-node1 etc]# chown named.named group* [root@linux-node1 etc]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful [root@linux-node1 etc]#
[root@linux-node1 etc]# host view.viewlnh.com 10.0.1.161 Using domain server: Name: 10.0.1.161 Address: 10.0.1.161#53 Aliases: view.viewlnh.com has address 192.168.122.1 [root@linux-node1 etc]#
[root@linux-node2 etc]# host view.viewlnh.com 10.0.1.161 Using domain server: Name: 10.0.1.161 Address: 10.0.1.161#53 Aliases: view.viewlnh.com has address 192.168.122.2 [root@linux-node2 etc]#
[root@linux-node1 etc]# vim /etc/named.conf [root@linux-node1 etc]# cat /etc/named.conf options { version "1.1.1"; listen-on port 53 {any;}; directory "/var/named/chroot/etc/"; pid-file "/var/named/chroot/var/run/named/named.pid"; allow-query { any; }; Dump-file "/var/named/chroot/var/log/binddump.db"; Statistics-file "/var/named/chroot/var/log/named_stats"; zone-statistics yes; memstatistics-file "log/mem_stats"; empty-zones-enable no; forwarders {202.106.196.115;8.8.8.8; }; }; key "rndc-key" { algorithm hmac-md5; secret "Eqw4hClGExUWeDkKBX/pBg=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; logging { channel warning { file "/var/named/chroot/var/log/dns_warning" versions 10 size 10m; severity warning; print-category yes; print-severity yes; print-time yes; }; channel general_dns { file "/var/named/chroot/var/log/dns_log" versions 10 size 100m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { warning; }; category queries { general_dns; }; }; acl group1 { 10.0.1.161; }; acl group2 { 10.0.1.162; }; acl groupall { *; }; include "/var/named/chroot/etc/view.conf"; [root@linux-node1 etc]#