安装相关包
[root@localhost ~]# dnf install bind bind-utils -y
[root@localhost ~]# rpm -ql bind
进入主配置文件
[root@localhost ~]# vim /etc/named.conf
options {
#所以地址都可监听
listen-on port 53 { 192.168.248.128; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
允许任何主机查询
allow-query { any; };
zone "baidu.com" IN {
type master;
file "named.baidu.com";
};
写入区域服务器配置文件
root@localhost ~]# vim /var/named/named.baidu.com
$TTL 1D
@ IN SOA @ admin.baidu.com. ( 0 1D 1H 1W 3H )
IN NS ns.baidu.com.
IN MX 10 mail.baidu.com.
ns IN A 192.168.248.128
mail IN A 192.168.245.12
www IN A 192.168.245.13
ftp IN CNAME www
[root@localhost ~]# systemctl restart named
客户机测试
[root@localhost ~]# host ns.baidu.com
ns.baidu.com has address 192.168.248.128
[root@localhost ~]# host mail.baidu.com
mail.baidu.com has address 192.168.245.12
[root@localhost ~]# host ftp.baidu.com
ftp.baidu.com is an alias for www.baidu.com.
www.baidu.com has address 192.168.245.13
[root@localhost ~]# host www.baidu.com
www.baidu.com has address 192.168.245.13
DNS的反向解析:
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.248.128; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
allow-query { any; };
zone "245.168.192.in-addr.arpa" IN {
type master;
file "named.192.168.245";
};
[root@localhost ~]# vim /var/named/named.192.168.245
$TTL 1D
@ IN SOA ns.baidu.com. admin.baidu.com. ( 0 1D 1H 1W 3H )
IN NS ns.baidu.com.
128 IN PTR ns.baidu.com.
128 IN PTR www.baidu.com.
128 IN PTR mail.baidu.com.
128 IN PTR ftp.baidu.com.
[root@localhost ~]# systemctl restart named
客户机测试
[root@localhost ~]# host 192.168.248.128 192.168.248.128
Using domain server:
Name: 192.168.248.128
Address: 192.168.248.128#53
Aliases:
128.248.168.192.in-addr.arpa domain name pointer mail.baidu.com.
128.248.168.192.in-addr.arpa domain name pointer ftp.baidu.com.
128.248.168.192.in-addr.arpa domain name pointer ns.baidu.com.
128.248.168.192.in-addr.arpa domain name pointer www.baidu.com.
[root@localhost ~]# nslookup 192.168.248.128
128.248.168.192.in-addr.arpa name = mail.baidu.com.
128.248.168.192.in-addr.arpa name = ftp.baidu.com.
128.248.168.192.in-addr.arpa name = ns.baidu.com.
128.248.168.192.in-addr.arpa name = www.baidu.com.