前言:shell
重點步驟:找主配置文件,找啓動腳本vim
ip解析域名,多用於測試緩存
www.sina.com.cn. 最後一個點是根,總體就是徹底合格域名安全
www是主機名稱,sina二級域名,com.cn是頂級域名 .是根服務器
在服務安裝完畢時,就是緩存服務器數據結構
[root@localhost ~]# vim /etc/named.conf options { '選項' listen-on port 53 { any; }; '監聽地址全部' listen-on-v6 port 53 { ::1; }; directory "/var/named"; '目錄在/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"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { 192.168.10.0/24; }; '容許此網段前來解析'
#正向解析 zone "localhost" IN { '主機名,例kgc.com' type master; 'master類型,主服務器' file "named.localhost"; '區域數據文件名,A記錄,能夠解析主機頭,' allow-update { none; }; '容許更新' allow-transfer { 173.16.16.2 } '從服務器的IP地址' }; #反向解析 zone "16.16.173.in-addr.arpa" IN { 'ip地址反寫' type master; '主服務器' file "named.loopback"; '區域配置文件名' allow-update { none; }; '容許更新' };
16.16.173.in-addr.arpa 是ip地址的反寫 正寫是'173.16.16.?',?做爲一個選項負載均衡
$TTL 1D '有效解析記錄的生命週期' @ IN SOA @ rname.invalid. ( 'SOA標記、@域名、管理者郵箱' 0 ; serial '更新序列號,能夠是10位之內的整數,當前0' 1D ; refresh '刷新時間,從新下載地址數據的間隔,1天' 1H ; retry '重試延時,下載失敗後的重試間隔,1小時' 1W ; expire '失效時間,超過改時間仍沒法下載則放棄,1周' 3H ) ; minimum '無效解析記錄的生存週期 3小時' NS @ '@指本身' A 127.0.0.1 '迴環地址,此行的首位沒寫,默認是本身的主機名,即輸入本身的主機名就是在ping本身' AAAA ::1 ~
如果找不到主服務器,就會每1小時找一次,持續1w即一週dom
$TTL 1D '有效解析記錄的生命週期' @ IN SOA @ rname.invalid. ( 'SOA標記、@域名、管理者郵箱' 0 ; serial '更新序列號,能夠是10位之內的整數,當前0' 1D ; refresh '刷新時間,從新下載地址數據的間隔,1天' 1H ; retry '重試延時,下載失敗後的重試間隔,1小時' 1W ; expire '失效時間,超過改時間仍沒法下載則放棄,1周' 3H ) ; minimum '無效解析記錄的生存週期 3小時' NS @ A 127.0.0.1 AAAA ::1 @ IN NS ns1.bdqn.com. '本身的域名叫作ns1.bdqn.com.' IN MX 10 mail.bdqn.com. '本身的郵件交換系統優先級別10的叫作mail.bdqn.com.' ns1 IN A 58.119.74.203 '主機名即主機頭爲ns1時,對應的ip地址58.119.74.203' www IN A 173.16.16.1 '主機名爲www時,對應的ip地址爲爲173.16.16.1' mail IN A 173.16.16.4 ftp IN CNAME www 'cname,別名,即輸入ftp至關於輸入www' ~
[root@dns named]# rpm -qc bind '查看已安裝bind軟件的配置文件' /etc/logrotate.d/named /etc/named.conf /etc/named.iscdlv.key /etc/named.rfc1912.zones /etc/named.root.key /etc/rndc.conf /etc/rndc.key /etc/sysconfig/named /var/named/named.ca /var/named/named.empty /var/named/named.localhost /var/named/named.loopback [root@dns named]#
[root@dns named]# vim /etc/named.conf '配置主配置文件' options { listen-on port 53 { any; }; '監聽地址修改成全部' 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"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; '容許全部主機前來解析' /*
[root@dns named]# vim /etc/named.conf '配置主配置文件' zone "." IN { '根域,不要去動它' type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; '區域配置文件,接下來要配置它' include "/etc/named.root.key";
[root@dns named]# cd /var/named '去看一眼默認文件存放路徑' [root@dns named]# ls chroot data dyndb-ldap kgc.com.zone named.empty named.loopback chroot_sdb dynamic kgc.com.local named.ca named.localhost slaves [root@dns named]# vim /etc/named.rfc1912.zones '配置區域配置文件'
以ipv6反向解析zone爲界限,上面的是正向解析zone,下面是反向解析zonetcp
zone "kgc.com" IN { '建立一個kgc.com正向解析區域' type master; file "kgc.com.zone"; '存放文件在默認目錄/var/named下,名爲kgc.com.zone文件,如果沒有須要本身建立' 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 "0.0.10.in-addr.arpa" IN { type master; file "kgc.com.local"; allow-update { none; }; };
[root@dns named]# cp -p named.localhost kgc.com.zone '保留權限複製模板,重命名爲kgc.com.zone' [root@dns named]# vim kgc.com.zone ''修改區域數據, $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS kgc.com. A 127.0.0.1 IN MX 5 mail.kgc.com. mail IN A 10.10.10.10 www IN A 9.9.9.9 ftp IN CNAME www * IN A 8.8.8.8
@ 表明變量,在這裏指域名分佈式
此時DNS的正向解析已經配置完畢
[root@dns named]# systemctl start named '啓動服務' [root@dns named]# netstat -natp |grep named '查看端口狀態-n 數字 -a 全部 -t tcp -p protocol 協議' tcp 0 0 192.168.139.132:53 0.0.0.0:* LISTEN 40771/named tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 40771/named tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 40771/named tcp6 0 0 ::1:53 :::* LISTEN 40771/named tcp6 0 0 ::1:953 :::* LISTEN 40771/named [root@dns named]# netstat -naup |grep named '-u udp' udp 0 0 192.168.139.132:53 0.0.0.0:* 40771/named udp 0 0 127.0.0.1:53 0.0.0.0:* 40771/named udp 0 0 192.168.122.1:53 0.0.0.0:* 40771/named udp6 0 0 ::1:53 :::* 40771/named
[root@dns named]# systemctl stop firewalld '關閉防火牆' [root@dns named]# setenforce 0 '關閉安全加強服務'
驗證一下
新建一臺虛擬機,網卡模式也設置爲nat模式,而後指定dns
C:\Users\GSY>nslookup mail.kgc.com 服務器: UnKnown Address: 192.168.139.132 名稱: mail.kgc.com Address: 10.10.10.10 C:\Users\GSY>nslookup qqq.kgc.com 服務器: UnKnown Address: 192.168.139.132 DNS request timed out. timeout was 2 seconds. 名稱: qqq.kgc.com Address: 123.123.123.123
'也能夠在本機的/etc/resolv.conf內輸入dns服務器名,告訴主機dns的位置,進行本地驗證 ' [root@dns named]# echo "nameserver 192.168.139.132" > /etc/resolv.conf [root@dns named]# nslookup www.kgc.com Server: 192.168.139.132 Address: 192.168.139.132#53 Name: www.kgc.com Address: 10.0.0.10
14 IN PTR www.kgc.com. 13 IN PTR ftp.kgc.com.
反向解析的區域數據文件配置
[root@dns named]# cp -p named.loopback kgc.com.local '建立的文件名與區域反向解析配置的文件名一致' [root@dns named]# vim kgc.com.local $TTL 1D @ IN SOA kgc.com. admin.kgc.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS kgc.com. A 14.0.0.14 14 IN PTR www.kgc.com. 13 IN PTR ftp.kgc.com. 2 IN PTR WWW.GSYDSG.com. ~
測試 nslookup 或者host均可以
[root@dns named]# systemctl restart named [root@dns named]# nslookup 14.0.0.2 '由於在配置文件中是大寫的WWW,因此不是域名=' 2.0.0.14.in-addr.arpa name = WWW.GSYDSG.com. [root@dns named]# host 14.0.0.14 14.0.0.14.in-addr.arpa domain name pointer www.kgc.com. [root@dns named]# host 14.0.0.13 13.0.0.14.in-addr.arpa domain name pointer ftp.kgc.com. [root@dns named]#
www IN A 9.9.9.9 www IN A 7.7.7.7 www IN A 6.6.6.6 * IN A 8.8.8.8
驗證同一域名對應到多個IP地址
C:\Users\GSY>nslookup www.kgc.com 服務器: UnKnown Address: 192.168.139.132 DNS request timed out. timeout was 2 seconds. 名稱: www.kgc.com Addresses: 6.6.6.6 7.7.7.7 9.9.9.9
[root@dns named]# named-checkconf /etc/named.conf [root@dns named]# named-checkconf /etc/named.rfc1912.zones
沒啥反應,由於是正常運轉的,我把裏面的數據改錯驗證一下
zoe "kgc.com" IN { '去掉個字母' type master; file "kgc.com.zone"; allow-update { none; }; };
[root@dns named]# named-checkconf /etc/named.rfc1912.zones /etc/named.rfc1912.zones:13: unknown option 'zoe'
錯誤改回來
[root@dns named]# named-checkconf -z /etc/named.rfc1912.zones zone kgc.com/IN: loaded serial 0 zone localhost/IN: loaded serial 0 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: loaded serial 0 zone 0.0.14.in-addr.arpa/IN: loaded serial 0 zone 0.in-addr.arpa/IN: loaded serial 0
-z 選項,還會查看其中的zone項是否有誤
不帶-z選項,只查看總體的語法
[root@dns named]# named-checkzone kgc.com /var/named/kgc.com.zone zone kgc.com/IN: loaded serial 0 OK
slave 從服務器
先管關掉防火牆再說
主配置文件/etc/bind/named.conf
數據文件 /var/named
程序 /usr/sbin/named
options { '衆多選項' listen-on port 53 { 127.0.0.1; }; '監聽此地址' listen-on-v6 port 53 { ::1; }; directory "/var/named"; '默認目錄在/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"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { localhost; }; '容許此主機名前來解析'
#正向解析 zone "localhost" IN { 「主機名」 type master; 'master類型,主服務器' file "named.localhost"; '區域數據文件名,A記錄,能夠解析主機頭' allow-update { none; }; '容許更新' allow-transfer { 173.16.16.2 }; '從服務器的IP地址' }; zone "localhost" IN { 「主機名」 type slave; 'slave類型,從服務器' file 「slaves/bdqn.com.zone」; allow-update { none; }; '容許更新' masters { 192.168.10.10; }; '主服務器的IP地址' }; #反向解析 zone "16.16.173.in-addr.arpa" IN { 'ip地址反寫' type master; '主服務器' file "named.loopback"; '區域配置文件名' allow-update { none; }; '容許更新' };
以其中的named.localhost爲模板帶權限複製,名字改成區域配置文件中file參數的名字
$TTL 1D '有效解析記錄的生命週期' @ IN SOA @ rname.invalid. ( 'SOA標記、@域名、管理者郵箱' 0 ; serial '更新序列號,能夠是10位之內的整數,當前0' 1D ; refresh '刷新時間,從新下載地址數據的間隔,1天' 1H ; retry '重試延時,下載失敗後的重試間隔,1小時' 1W ; expire '失效時間,超過改時間仍沒法下載則放棄,1周' 3H ) ; minimum '無效解析記錄的生存週期 3小時' NS @ A 127.0.0.1 AAAA ::1 @ IN NS ns1.bdqn.com. IN MX 10 mail.bdqn.com. mail IN A 173.16.16.4 ns1 IN A 58.119.74.203 ftp IN CNAME www www IN A 173.16.16.1
nslookup能夠去檢驗
能夠在/etc/hosts 和/etc/resolv.conf文件中輸入dns服務器主機名
並確認,用以快速訪問dns地址