Linux---DNS域名解析如何配置

我想喝橙汁兒~發表於2020-11-04

一:搭建DNS快取域名伺服器

  • DNS快取記憶體伺服器,通過向其它域名伺服器查詢獲得域名IP地址記錄,將域名查詢結果快取到本地,提高重複查詢時速度

1.1:關閉並禁用防火牆

systemctl stop firewalld
systemctl disable firewalld

1.2:關閉核心防護

vi /etc/selinux/config
	SELINUX=disabled

1.3:安裝與bind相關的軟體包

查詢是否安裝
rpm -qa | grep ''bind"

yum -y install bind bind-chroot bind-utils bind-libs

1.4:修改主配置檔案

vi /etc/named.conf
options {
	listen-on port 53 { 20.0.0.11; };
	forwarders { 8.8.8.8;114.114.114.114; };
	………………
	allow-query	{ 20.0.0.0/24; };


1.5:載入主配置檔案中對應的區域資料庫檔案

named-checkconf -z /etc/named.conf

systemctl start named

netstat -anutp | grep named

1.6:客戶機配置

vi /etc/resolv.conf
	nameserver 20.0.0.11

二:搭建DNS主從服務實驗

  • DNS主伺服器(20.0.0.11)

2.1:關閉防火牆

systemctl stop firewalld
systemctl disable firewalld

2.2:關閉核心防護

vi /etc/selinux/config
	SELINUX=disabled

2.3:安裝與bind相關的軟體包

查詢是否安裝
rpm -qa | grep ''bind"

yum -y install bind bind-chroot bind-utils bind-libs

2.4:修改主配置檔案(/etc/named.conf)

vi /etc/named.conf
options {
	listen-on port 53 { 20.0.0.11; };
	………………
	allow-query	{ any; };

2.5:新增正反配置檔案 (/etc/named.rfc1912.zones)

vi /etc/named.rfc1912.zones
zone "cenjeal.com" IN {
	type master;
	file "cenjeal.com.zone";
	allow-transfer { 20.0.0.12; };
	also-notify { 20.0.0.12; };
};

zone "0.0.20.in-addr.arpa" IN {
	type master;
	file "20.0.0.arpa";
	allow-transfer { 20.0.0.12; };
	also-notify { 20.0.0.12; };
};

2.6:dns正向解析檔案(/var/named/cenjeal.com.zone)

vi /var/named/cenjeal.com.zone
$TTL 1D
@	IN SOA cenjeal.com. admin.cenjeal.com. (
				0	; serial
				1D	; refresh
				1H	; retry
				1W	; expire
				3H )	; minimum
	NS        @
	A           192.168.11.119
www IN	A           192.168.11.119
ftp    IN	A           192.168.11.118
mail IN	CNAME	www

  • 修改屬主
chown named:named /var/named/bdqn.com.zone

2.7:dns反向解析檔案(/var/named/20.0.0.arpa)

$TTL 1D
@	IN SOA cenjeal.com. admin.cenjeal.com. (
				0	; serial
				1D	; refresh
				1H	; retry
				1W	; expire
				3H )	; minimum
	NS        @
	A           192.168.11.119
119 IN	PTR          www.bdqn.com.
120 IN	PTR          ftp.bdqn.com.
121 IN	PTR	bbs.bdqn.com.

  • 修改屬主
    chown named:named /var/named/bdqn.com.zone

2.8:重啟服務

systemctl restart named

三:DNS從伺服器(20.0.0.12)配置

關閉防火牆
systemctl stop firewalld
systemctl disable firewalld
關閉核心防護
vi /etc/selinux/config
	SELINUX=disabled

yum -y install bind install bind-chroot bind-utils bind-libs
vi /etc/named.conf
options {
	listen-on port 53 { 20.0.0.12; };
	………………
	allow-query	{ any; };

新增正反配置檔案
vi /etc/named.rfc1912.zones
zone "cenjeal.com" IN {
	type slave;
	masters { 20.0.0.11; };
	allow-notify { 20.0.0.11; };
	file "slaves/cenjeal.com.zone";
};

zone "0.0.20.in-addr.arpa" IN {
	type slave;
	masters { 20.0.0.11; };
	allow-notify { 20.0.0.11; };
	file "slaves/20.0.0.arpa";
}; 
:wq

systemctl start named

四:客戶機(20.0.0.13)配置

vi /etc/resolv.conf

#主DNS伺服器
nameserver 20.0.0.11
#從DNS伺服器
#nameserver 20.0.0.12

五:測試

yum -y install bind-utils

nslookup www.cenjeal.com

nslookup 20.0.0.119


相關文章