構建一個DNS服務器node
fade.com 網段爲192.168.139.0/24vim
NS服務器爲 ns1.fade.com 192.168.139.11緩存
www.fade.com 爲 192.168.139.12 和 192.168.139.13安全
mail.fade.com 爲 192.168.139.14 服務器
ftp.fade.com 別名爲www.fade.comtcp
[root@node1 ~]# yum install bind bind-libs bind-utilside
[root@node1 ~]# rpm -ql bind工具
/etc/named.conf bind的配置文件,能夠定義bind進程的工做屬性區域定義文件oop
/etc/rc.d/init.d/named 服務腳本啓動文件
測試
/etc/rndc.conf 遠程名稱服務控制工具的配置文件
/etc/rndc.key 密鑰文件
/etc/sysconfig/named 服務腳本配置文件
/usr/lib64/bind 庫文件
root@node1 ~]# cd /var/named/
[root@node1 named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
named.localhost 將127.0.0.1解析爲localhost
named.loopback 將localhost解析爲127.0.0.1
[root@node1 named]# cat named.ca
a.root-server.net -- m.root-server.net全球13臺根服務器的A記錄
. 3600000 NS A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET. 3600000 A 198.41.0.4
A.ROOT-SERVERS.NET. 3600000 AAAA 2001:503:ba3e::2:30
;
; FORMERLY NS1.ISI.EDU
;
. 3600000 NS B.ROOT-SERVERS.NET.
B.ROOT-SERVERS.NET. 3600000 A 192.228.79.201
B.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:84::b
;
; FORMERLY C.PSI.NET
.......
......
......
. 3600000 NS M.ROOT-SERVERS.NET.
M.ROOT-SERVERS.NET. 3600000 A 202.12.27.33
M.ROOT-SERVERS.NET. 3600000 AAAA 2001:dc3::35
; End of file
[root@node1 bind]# dig -t NS .
若是聯網的話能夠用dig命令直接查找出DNS的全部根服務器
[root@node1 bind]# service named start
Generating /etc/rndc.key: [ OK ]
Starting named: [ OK ]
注:DNS服務的服務名爲named
DNS協議監聽的協議/端口 : 53/udp 和 53/tcp(從服務器與主服務器之間進行區域傳送爲了安全爲TCP) 953/tcp(rndc遠程DNS服務控制工具監聽的端口)
[root@node1 bind]# vim /etc/named.conf
options {
listen-on port 53 { 127.0.0.1; }; 監聽在本機的53好端口,這樣只能給本機提供服務不能爲遠程客戶端提供服務
listen-on-v6 port 53 { ::1; }; 監聽調度ipv6端口
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; }; 只容許本地進行查詢
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 {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
[root@node1 bind]# vim /etc/named.conf
options { 全局段
directory "/var/named";
};
zone "." IN { 根區域段
type hint;提示區域
file "named.ca"; 區域文件爲/var/named/name.ca
};
zone "localhost" IN { 正向區域段
type master; 主區域
file "named.localhost"; 系統自帶的正向解析文件,也可 以自建一個
};
zone "0.0.127.in-addr.arpa" IN { 反向區域段
type master;
file "named.loopback";
};
[root@node1 bind]# chown root:named /etc/named.conf
[root@node1 bind]# chmod 640 /etc/named.conf 修改權限
[root@node1 bind]# named-checkconf 檢查主配置文件語法
[root@node1 bind]# named-checkzone "." /var/named/named.ca 檢查根區域語法
zone ./IN: has 0 SOA records
zone ./IN: not loaded due to errors. 提示有錯誤沒有加載(沒關係)
[root@node1 bind]# named-checkzone "localhost" /var/named/named.localhost
zone localhost/IN: loaded serial 0 加載成功
OK
[root@node1 bind]# named-checkzone "0.0.127.in-addr.arpa" /var/named/named.loopback
zone 0.0.127.in-addr.arpa/IN: loaded serial 0
OK
[root@node1 bind]# service named start
Starting named: [ OK ]
[root@node1 bind]# netstat -tunlp
udp 0 0 192.168.139.2:53 0.0.0.0:* 2804/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 804/named
tcp 0 0 192.168.139.2:53 0.0.0.0:* 2804/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* 2804/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* 2804/named
[root@node1 bind]# vim /etc/resolv.conf
search node1.com
nameserver 192.168.139.2 #本機的IP
測試一下這臺主機能不能直接鏈接互聯網進行DNS解析
[root@node1 bind]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=54 time=25.9 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=54 time=24.1 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=54 time=22.1 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=54 time=22.9 ms
64 bytes from 61.135.169.121: icmp_seq=5 ttl=54 time=22.2 ms
能夠看到可以進行解析(本機會去請求根,再一次次的迭代找到www.baidu.com的IP),這樣一個DNS緩存服務器就構成了
讓本機也能進行DNS解析
[root@node1 bind]# chkconfig named on
[root@node1 bind]# vim /etc/named.conf
新加一個區域
zone "fade.com" IN { type master;
file "fade.com.zone";
};
[root@node1 bind]# vim /var/named/fade.com.zone
$TTL 600
fade.com. IN SOA ns1.fade.com admin.fade.com. (
2017022101
1H
5M
1D
6H)
fade.com. IN NS ns1.fade.com.
IN MX 10 mail
ns1 IN A 192.168.139.11
mail IN A 192.168.139.14
www IN A 192.168.139.12
www IN A 192.168.139.13
ftp IN CNAME www
[root@node1 bind]# chmod 640 /var/named/fade.com.zone
[root@node1 bind]# chown root.named /var/named/fade.com.zone
[root@node1 bind]# service named restart
[root@node1 bind]# dig -t A www.fade.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.4 <<>> -t A www.fade.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13925
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION: 你的問題
;www.fade.com.INA
;; ANSWER SECTION: 給你的答案
www.fade.com.600INA192.168.139.12
www.fade.com.600INA192.168.139.13
;; AUTHORITY SECTION: 提供權威答案的服務器是ns1.fade.com
fade.com.600INNSns1.fade.com.
;; ADDITIONAL SECTION: ns1的A記錄
ns1.fade.com.600INA192.168.139.11
;; Query time: 1 msec
;; SERVER: 192.168.139.2#53(192.168.139.2)
;; WHEN: Tue Feb 21 12:57:26 2017
;; MSG SIZE rcvd: 96
[root@node1 bind]#dig -x 192.168.139.12(進行反向查詢,但我還沒配置反向查詢段)
host命令的用法
[root@node1 bind]# host -t A www.fade.com
www.fade.com has address 192.168.139.12
www.fade.com has address 192.168.139.13
[root@node1 bind]# host -t NS fade.com
fade.com name server ns1.fade.com.
讓能進行發向DNS解析
[root@node1 bind]# vim /etc/named.conf
加入正向解析段
zone "139.168.192.in-addr.arpa" IN {
type master;
file "192.168.139.zone";
};
[root@node1 bind]# vim /var/named/192.168.139.zone
$TTL 600
@ IN SOA ns1.fade.com admin.fade.com.(
2017022101
1H
5M
1D
6H)
IN NS ns1.fade.com.
11 IN PTR ns1.fade.com.
12 IN PTR www.fade.com.
13 IN PTR www.fade.com.
14 IN PTR mail.fade.com.
[root@node1 bind]# named-checkzone "139.168.192.in-addr.arpa" /var/named/192.168.139.zone
zone 139.168.192.in-addr.arpa/IN: loaded serial 2017022101
OK
[root@node1 bind]# service named restart
用Windows進行測試
泛域名解析(當用戶訪問了一個不從在的頁面時,能夠用URL重定向到一個默認的錯誤頁面,提醒用戶出錯了)
在正向解析文件/var/named/fade.com.zone中加入
*.fade IN A 192.168.139.12
則用戶訪問*.fade 時就會自動轉換到192.168.139.12這臺服務器
到此咱們的這臺主機既能夠進行正向解析,也可以進行反向解析,還可以做爲DNS緩存服務器使用
想要創建網站,能夠在godaddy.com(在這個網站進行註冊不用在中國政府進行備案)上註冊一個域名,再買一個虛擬機,就能夠創建本身的網站了