linux--DNS解析
yum install bind -y
systemctl start named
systemctl enable named
systemctl stop firewlld systemctl disable firewalld
圖示:安裝bind
圖示:開啟服務關閉火墻
主配置文件: /etc/named.conf
子配置文件: /etc/name.rfc1912.zones
數據目錄: /var/named
二、高速緩存dns
vim /etc/named.conf
11 listen-on port 53 { any; }; #讓所有用戶IP可以訪問
17 allow-query { any; }; #客戶群體
18 forwarders {172.25.254.250; }; #訪問中介
圖示:修改配置文件
cat /etc/services | grep domain
圖示:查看
systemctl restart named
測試:
在客戶主機
vim /etc/resolv.conf
nameserver 172.25.254.121
dig www.baidu.com
圖示:測試結果
三、權威DNS的正向解析
vim /etc/named.rfc.1912.zone
26 type master;
27 file "westos.com.zone";
28 allow-update { none; };
29 };
cd /var/named/
cp -p named.localhost westos.com.zone
vim westos.com.zone
1 $TTL 1D
2 @ IN SOA dns.westos.com. root.westos.com. (
3 0 ; serial
5 1H ; retry
6 1W ; expire
7 3H ) ; minimum
8 NS dns.westos.com
9 dns A 172.25.254.121
10 www A 172.25.254.111
systemctl restart named
圖示:修改配置文件
測試:
dig www.westos.com
cat /etc/resolv.conf
# Generated by NetworkManager
search ilt.example.com example.com
nameserver 172.25.254.121
圖示:測試結果
四、反向解析
vim /etc/named.rfc.1912.zone
48 zone "254.25.172.in-addr.arpa" IN {
49 type master;
50 file "westos.com.ptr";
51 allow-update { none; };
52 };
ls
cp -p named.loopback westos.com.ptr
vim westos.com.ptr
1 $TTL 1D
2 @ IN SOA dns.westos.com. root.westos.com. (
3 0 ; serial
4 1D ; refresh
5 1H ; retry
6 1W ; expire
7 3H ) ; minimum
8 NS dns.westos.com.
9 dns A 172.25.254.100
10 100 PTR www.westos.com.
systemctl restart named
圖示:配置文件及操作
測試:
dig -x 172.25.254.121
圖示:測試結果
五、dns雙向解析
vim /etc/named.conf
50 view localnet {
51 match-clients { 172.25.254.221; };
52 zone "." IN {
53 type hint;
54 file "named.ca";
55 };
56
57 include "/etc/named.rfc1912.zones";
58 include "/etc/named.root.key";
59 };
60
61 view any {
62 match-clients { any; };
63 zone "." IN {
64 type hint;
65 file "named.ca";
66 };
67
68 include "/etc/named.rfc1912.zones";
69 include "/etc/named.root.key";
70 };
cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.inter -p
vim /etc/named.rfc1912.zones.inter
25 zone "westos.com" IN {
26 type master;
27 file "westos.com.inter";
28 allow-update { none; };
29 };
cp -p westos.com.zone westos.com.inter
vim westos.com.inter
1 $TTL 1D
2 @ IN SOA dns.westos.com. root.westos.com. (
3 0 ; serial
4 1D ; refresh
5 1H ; retry
6 1W ; expire
7 3H ) ; minimum
8 NS dns.westos.com.
9 dns A 1.1.1.121
10 www A 1.1.1.111
%s/172.25.254/1.1.1/g
systemctl restart named
圖示:修改配置內容
測試:在221主機上 dig www.westos.com.inter
圖示:測試結果
六、輔助dns
主dns的設定
vim /etc/named.rfc1912.zones
25 zone "westos.com" IN {
26 type master;
27 file "westos.com.zone";
28 allow-update { none; };
29 also-notify { 172.25.254.221; };
systemctl restart named
註意:每次更改A記錄文件後必須更改輔助serial的值,最高為10位。
vim /var/named/westos.com.inter
4 0 ; serial
輔助dns主機中的設定
yum install bind -y
systemctl restart named
systemctl stop firewalld
vim /etc/sysconfig/selinux
disabled
vim /etc/named.conf
# listen-on port 53 { 127.0.0.1; };
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; };
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
type slave;
masters {172.25.254.121; };
file "slaves/westos.com.inter";
allow-update { none; };
};
systemctl restart named
測試:
vim /etc/resolv.conf
nameserver 172.25.254.221
dig www.westos.com
圖示:修改配置文件
圖示:測試結果
七、dns的遠程更新
(實驗前需先備份)
基於ip
vim /etc/name.rfc1912.zone.inter
25 zone "westos.com" IN {
26 type master;
27 file "westos.com.inter";
28 allow-update { 172.25.254.244; };
29 also-notify {172.25.254.244; };
30 };
systemctl restart named
圖示:修改配置文件
測試
在221主機上
[root@localhost ~]# nsupdate
> server 172.25.254.121
> update add bbs.westos.com 86400 A 1.1.1.2 #添加
> send
> server 172.25.254.121
> update delete bbs.westos.com #刪除
> send
[root@dns-server named]# ls
data named.empty slaves westos.com.ptr
dynamic named.localhost westos.com.inter westos.com.zone
named.ca named.loopback westos.com.inter.jnl <-----更新在121主機上生成
圖示:記錄生成過程
dig bbs.westos.com
;; ANSWER SECTION:
bbs.westos.com. 86400 IN A 1.1.1.2
圖示:測試結果
###
還原
[root@dns-server named]# rm -fr westos.com.inter westos.com.inter.jnl[root@dns-server named]# ls
data named.ca named.localhost slaves westos.com.zone
dynamic named.empty named.loopback westos.com.ptr
[root@dns-server named]# cp -p /mnt/westos.com.inter .
###
*基於key的
cd /mnt
cp -p /etc/rndc.key /etc/westos.key ##‘-p’復制所有
dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos
vim /etc/westos.key
1 key "westos" {
2 algorithm hmac-md5;
3 secret "ujuIHzR74r3ikunB3OblMQ==";
4 };
圖示:更改文件內容
vim /etc/named.conf
41 include "/etc/westos.key";
42 logging {
43 channel default_debug {
44 file "data/named.run";
圖示:修改配置文件
vim /etc/named.rfc1912.zones.inter
25 zone "westos.com" IN {
26 type master;
27 file "westos.com.inter";
28 allow-update { key westos; };
29 also-notify {172.25.254.221; };
30 };
systemctl restart named
圖示:修改配置文件
測試
測試:
發送鑰匙給測試主機
scp Kwestos.+157+60830.* [email protected]:/mnt
圖示:發送鑰匙
在有key 的主機中執行
[root@localhost mnt]# nsupdate -kKwestos.+157+60830.private
> update add bbs.westos.com 8000 A 1.1.1.0
> send
[root@localhost mnt]# nsupdate
> server 172.25.254.121
> update add ss.westos.com 8000 A 1.1.1.1
> send
update failed: REFUSED
圖示:沒鑰匙更新失敗
ddns
八、DDNS的配置
1.輔助設備
[root@dns-slave mnt]# hostnamectl set-hostname www.westos.com ##修改主機名
[root@dns-slave mnt]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
圖示:編輯配置使得更改為動態獲取ip
[root@dns-slave mnt]# systemctl restart network
2.設置dns主機
vim /etc/named.rfc1912.zones
25 zone "westos.com" IN {
26 type master;
27 file "westos.com.zone";
28 allow-update { none; };
29 also-notify { key westos; };
圖示:修改配置文件
安裝dhcp服務
[root@dns-server ~]# yum install dhcp -y ##安裝dhcp服務
[root@dns-server ~]# systemctl stop firewalld ##關閉防火墻
[root@dns-server ~]# systemctl disable firewalld ##設置開機不啟動
[root@dns-server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@dns-server mnt]# cd /etc/dhcp/
[root@dns-server dhcp]# ls
dhclient.d dhcpd6.conf dhcpd.conf
圖示:復制以及修改配置文件
[root@dns-server named]# vim westos.com.zone
圖示 :修改配置文件
[root@dns-server named]# systemctl restart named
監控測試
watch -n 1 dig www.westos.com.inter
圖示:測試結果
##end##
linux--DNS解析