1、安装DNS服务
[root@dns-server ~]# yum install bind bind-utils -y
2、配置主配置文件
[root@dns-server ~]# cat /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { 127.0.0.1; any; }; //把 any 改为DNS服务器的IP也可以
// 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 { localhost; any; };
allow-transfer { 223.5.5.5;}; //允许转发
forward first ;
forwarders { 223.5.5.5;};
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion yes;
dnssec-enable no;
dnssec-validation no;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.root.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "";
};
//正向解析
zone "" IN {
type master;
file "forward.";
allow-update { none; };
};
//反向解析
zone "18.21.172in-addr.arpa" IN {
type master;
file "reverse.";
allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
#正向解析文件配置
[root@dns-server ~]# cat /var/named/forward.
$TTL 86400
@ IN SOA masterdns.. root.. (
2021060116 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS masterdns..
@ IN A 172.21.18.138
masterdns IN A 172.21.18.138
docs 600 IN A 172.21.18.149
wiki IN A 172.21.18.149
ftp 600 IN A 172.21.18.136
#反向解析文件配置
[root@dns-server ~]# cat /var/named/reverse.
$TTL 86400
@ IN SOA masterdns.. root.. (
2021060116 ;Serial //时间
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS masterdns..
@ IN PTR .
masterdns IN A 172.21.18.138
docs IN A 172.21.18.149
wiki IN A 172.21.18.149
ftp IN A 172.21.18.136
138 IN PTR masterdns..
149 IN PTR wiki..
149 IN PTR docs..
136 IN PTR ftp..
[root@dns-server ~]# systemctl restart named //重启生效
#测试
[root@dns-server ~]# dig wiki. @172.21.18.138
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.5 <<>> wiki. @172.21.18.138
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47677
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;wiki.. IN A
;; ANSWER SECTION:
wiki.. 86400 IN A 172.21.18.149
;; AUTHORITY SECTION:
. 86400 IN NS masterdns..
;; ADDITIONAL SECTION:
masterdns.. 86400 IN A 172.21.18.138
;; Query time: 0 msec
;; SERVER: 172.21.18.138#53(172.21.18.138)
;; WHEN: 三 6月 02 16:15:21 CST 2021
;; MSG SIZE rcvd: 106
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/slapping/2847248,作者:类似简单,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。