Linux系统工程师 3.6 -- 企业dns服务器搭建

目录

dns服务器部署

1.关于dns的名词解释

关于客户端

关于服务端

关于报错信息:

 2.dns服务的安装与启用

 3.高速缓存dns

 4.dns的正向解析

 5.dns的反向解析

 6.dns的双向解析

7.dns集群

8.ddns(dhcp+dns)


dns服务器部署

1.关于dns的名词解释

dns:        domain name service(域名解析服务)

关于客户端

/etc/resolv.conf    ##dns指向文件
nameserver 172.25.254.220

测试:
host www.baidu.com    ##地址解析命令
dig www.baidu.com    ##地址详细解析信息命令


A记录            ##ip地址叫做域名的Address 记录
SOA            ##授权起始主机
dns顶级. 一共有13个
   次级.com .net .edu .org .cn....

baidu.com;qq.com;qq.net

关于服务端

bind        ##安装包
named        ##服务名称
/etc/named.conf    ##主配置文件
/var/named    ##数据目录
端口        ##53

关于报错信息:

1.no servers could be reached    ##服务无法访问(服务开启?火墙?网络?端口?)
2.服务启动失败            ##配置文件写错 journalctl -xe查询错误
3.dig 查询状态
NOERROR                ##表示查询成功
REFUSED                ##服务拒绝访问,(dns服务器没开授权)
SERVFAIL            ##查询记录失败,(dns服务器无法到达上级,服务器端没东西)
NXDOMAIN            ##此域名Address记录在dns中不存在

 2.dns服务的安装与启用

#安装#
dnf install bind.x86_64 -y

#启用#
systemctl enable --now named
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
netstat -antlupe | grep named            查询端口

vim /etc/named.conf
11         listen-on port 53 { any; };        ##在本地所有网络接口上开启53端口
19         allow-query     { any; };        ##允许查询A记录的客户端列表
34         dnssec-validation no;        ##禁用dns检测使dns能够缓存外部信息到本机

systemctl restart named

#测试#

用另一台测试机设置dns为服务器的ip 172.25.254.235

 dig www.baidu.com        应当出现百度的网址等信息但因为服务器不能上网,所以报错

 3.高速缓存dns

20         forwarders { 114.114.114.114; };    #缓存 114.114.114.114 的信息到本机,当内部主机查询过某地址后,再次查询会直接访问缓存,速度相当快

 4.dns的正向解析

dnf install postfix mailx -y
systemctl enable --now postfix

20##       forwarders { 114.114.114.114; };        #注释掉缓存外部信息到本机
vim /etc/resolv.conf --> nameserver 172.25.254.220    #修改解析地址为服务本机

vim /etc/named.rfc1912.zone
zone "westos.org" IN {		##维护的域名
        type master;		##当前服务器位主dns
        file "westos.org.zone";	##域名A记录文件
        allow-update { none; };	##允许更新主机列表
};

cd /var/named/
cp -p named.localhost westos.org.zone		#按照源文件格式 新建一个域名A记录文件(此处需要注意copy组 -p)
$TTL 1D		#TIME-TO-LIVE(dns地址保存时间长度)
@       IN SOA  dns.westos.org. root.westos.org (		#SOA授权起始(Start of Authority)
                                        0       ; serial	#域名版本序列号
                                        1D      ; refresh	#刷新时间(辅助dns)
                                        1H      ; retry		#重试时间(辅助dns)
                                        1W      ; expire	#过期时间(辅助dns,查询失败过期停止对辅助域名的应答)
                                        3H )    ; minimum	#A记录最短有效期
                NS      dns.westos.org.
dns             A       172.25.254.220
www             CNAME   westos.a			##规范域名
westos.a        A       172.25.254.10			##正向解析记录
westos.a        A       172.25.254.20			
westos.org.     MX 1    172.25.254.220.			##邮件解析记录

systemctl restart named 

dig www.westos.org		#查询正向解析
dig -t mx westos.org		#邮件解析记录查询

 

 5.dns的反向解析

vim /etc/named.rfc1912.zones.in-addr.arpa" IN {
        type master;

zone "254.25.172.in-addr.arpa" IN {
	type master;
	file "172.25.254.ptr";
	allow-update { none; };
};

cd /var/named/
cp -p named.loopback 172.25.254.ptr

vim 172.25.254.ptr
$TTL 1D
@	IN SOA	dns.westos.org. root.westos.org. (
					0	; serial
					1D	; refresh
					1H	; retry
					1W	; expire
					3H )	; minimum
	NS	dns.westos.org.
dns	A	172.25.254.220
11	PTR	www.westos.com.
12	PTR	bbs.westos.com.
13	PTR	news.westos.org.

systemctl restart named 

测试:
dig -x 172.25.254.220

 6.dns的双向解析

实验环境:
客户端1台
1.1.1.254 网段 		##ifconfig ens3 1.1.1.120; netmask 255.255.255.0; DNS nameserver 1.1.1.220

服务端1台2个网段的ip
1.1.1.220
172.25.254.220		##ifconfig ens3 172.25.254.220; netmask 255.255.255.0; DNS nameserver 172.25.254.220


在 1.1.1.0 网段的客户主机中
vim /etc/resolv.conf
nameserver 1.1.1.220

服务端配置方式:
cd /var/named/
cp -p westos.org.zone westos.org.inter
vim westos.com.inter
$TTL 1D
@	IN SOA	dns.westos.org. root.westos.org (
					0	; serial
					1D	; refresh
					1H	; retry
					1W	; expire
					3H )	; minimum
		NS	dns.westos.org.
dns		A	1.1.1.220
www		CNAME	westos.a
westos.a	A	1.1.1.10
westos.a	A	1.1.1.20
westos.com.	MX 1	1.1.1.220.	#mail exchanger 

cp -p /etc/named.rfc1912.zones  /etc/named.rfc1912.inter
vim /etc/named.rfc1912.inter
zone "westos.org" IN {
	type master;
	file "westos.org.inter";
	allow-update { none; };
};

vim /etc/named.conf
/*zone "." IN {		注释掉
       type hint;
       file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
*/

view localnet {
        match-clients { 1.1.1.0/24; };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        include "/etc/named.rfc1912.zones";
        include "/etc/named.root.key";
};

view anyone {
        match-clients { any; };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        include "/etc/named.rfc1912.inter";
        include "/etc/named.root.key";
};
      
systemctl restart named 

测试:
分别在2个网段的主机中作同样域名的地址解析
得到的A记录不同 dig www.westos.org

7.dns集群

服务机
vim /etc/resolv.conf	nameserver 172.25.254.220
firewall-cmd --add-service=dns		或者直接关掉火墙,排除不必要的错误
主dns:
zone "westos.org" IN {
        type master;
        file "westos.org.zone";
        allow-update { none; };
        also-notify { 172.25.254.120; };		##主动通知的辅助dns主机
};

vim /var/named/westos.org.zone
$TTL 1D
@       IN SOA  dns.westos.org. root.westos.org (
                                        2021080601      ; serial	##每次修改A记录文件需要变更此参数的值
                                        1D      ; refresh		且此参数只能递增
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      dns.westos.org.
dns             A       172.25.254.220
www             CNAME   westos.a
westos.a        A       172.25.254.10
westos.a        A       172.25.254.20
westos.org.     MX 1    172.25.254.220.


测试机
vim /etc/resolv.conf	nameserver 172.25.254.120
slave dns:
dnf install bind -y
firewall-cmd --add-service=dns		或者直接关掉火墙,排除不必要的错误

vim /etc/named.conf
listen-on port 53 { any; };
allow-query     { any; };
dnssec-validation no;

vim /etc/named.rfc1912.zones
zone "westos.org" IN {
        type slave;			##dns状态位辅助dns
        masters { 172.25.254.220; };	##主dns
        file "slaves/westos.org.zone";	##同步数据文件
};

systemctl restart named 

8.ddns(dhcp+dns)

dns基于ip地址的更新:
服务器
vim /etc/resolv.conf
nameserver 172.25.254.220

dnf instsall dhcp-server -y	安装dhcp服务
vim /etc/dhcpd/dhcpd.conf	编辑配置文件
cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf	按照提示copy

cd /mnt/
dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST westoskey
cat Kwestoskey.+163+56170.private

cp /etc/rndc.key /etc/westos.key -p
key "westoskey" {
        algorithm hmac-sha256;
        secret "un3XXz/fpcsTjKcb1m/NJw==";
};

vim /etc/named.conf
include "/etc/westos.key";

vim /etc/named.rfc1912.zones
 29 zone "westos.org" IN {
 30         type master;
 31         file "westos.org.zone";
 32         allow-update { key westoskey; };
 33         also-notify { 172.25.254.120; };
 34 };

vim /etc/dhcpd/dhcpd.conf
option domain-name "westos.org";	设置域名 ip
option domain-name-servers 172.25.254.220;				
ddns-update-style interim;						
# No service will be given on this subnet, but declaring it helps the	
# DHCP server to understand the network topology.			
subnet 172.25.254.0 netmask 255.255.255.0 {				
 31   range 172.25.254.75 172.25.254.99;
 32   option routers 172.25.254.220;
 33 }
 34 
 35 
 36 key westoskey {
 37   algorithm hmac-sha256;
 38   secret un3XXz/fpcsTjKcb1m/NJw==; ##
 39 };
 40 
 41 zone westos.org. {
 42   primary 127.0.0.1;
 43   key westoskey;
 44 }
}

systemctl restart named
systemctl restart dhcpd

测试:

设定测试机网络工作方式为dhcp BOOTPROTO=dhcp
设定主机名称westosa.westos.org

重启网络使其自动获取IP信息和DNS

dig westosa.westos.org

可以得到正确解析

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值