概述:
现在搭建DNS的软件很多,我们以以下软件做测试
bind
Part 1: 使用 bind 搭建DNS 服务器
软件包:
===========================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================
Installing:
bind x86_64 32:9.9.4-14.el7 rhel-yum 1.8 M
bind-chroot x86_64 32:9.9.4-14.el7 rhel-yum 81 k
bind-dyndb-ldap x86_64 3.5-4.el7 rhel-yum 91 k
服务名:
named
1. 安装软件包
yum install -y bind*
2. 设置守护进程
systemctl restart named
systemctl enable named
systemctl status named
3. 开启防火墙
[root@localhost ~]# firewall-cmd --permanent --add-port=53/udp
success
[root@localhost ~]# firewall-cmd --reload
success
4. 配置 /etc/named.conf, 开放端口访问以及允许查询
options {
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; };
------------>
options {
listen-on port 53 { any; };
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 { any; };
5. 在文件 /etc/named.rfc1912.zones,添加定义的zone
zone "qq.com" IN {
type master;
file "qq.zone";
allow-update { none; };
};
6. 配置创建 qq.zone 文件
cd /var/named/
cp named.localhost qq.zone
编辑qq.zone 文件
qq.com. NS desktop0.example.com.
www.qq.com. A 1.1.1.1
7. 重启守护进程
systemctl restart named
systemctl status named
Issue 1:[root@localhost named]# systemctl restart named
Job for named.service failed. See 'systemctl status named.service' and 'journalctl -xn' for details.
[root@localhost named]# journalctl -xn
-- Logs begin at Tue 2017-11-14 22:48:37 CST, end at Thu 2017-11-16 23:10:02 CST. --
Nov 16 23:10:00 localhost.localdomain named-checkconf[10104]: zone qq.com/IN: NS '192.168.56.12.qq.com' has no address reco
Nov 16 23:10:00 localhost.localdomain named-checkconf[10104]: zone qq.com/IN: not loaded due to errors.
Nov 16 23:10:00 localhost.localdomain named-checkconf[10104]: _default/qq.com/IN: bad zone
Nov 16 23:10:00 localhost.localdomain systemd[1]: named.service: control process exited, code=exited status=1
Nov 16 23:10:00 localhost.localdomain systemd[1]: Failed to start Berkeley Internet Name Domain (DNS).
-- Subject: Unit named.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Issue 2:
[root@localhost named]# systemctl status named
named.service - Berkeley Internet Name Domain (DNS)
Loaded: loaded (/usr/lib/systemd/system/named.service; enabled)
Active: active (running) since Thu 2017-11-16 23:14:36 CST; 7s ago
Process: 10223 ExecStop=/bin/sh -c /usr/sbin/rndc stop > /dev/null 2>&1 || /bin/kill -TERM $MAINPID (code=exited, status= 0/SUCCESS)
Process: 10232 ExecStart=/usr/sbin/named -u named $OPTIONS (code=exited, status=0/SUCCESS)
Process: 10231 ExecStartPre=/usr/sbin/named-checkconf -z /etc/named.conf (code=exited, status=0/SUCCESS)
Main PID: 10234 (named)
CGroup: /system.slice/named.service
ââ10234 /usr/sbin/named -u named
Nov 16 23:14:36 localhost.localdomain named[10234]: zone 0.in-addr.arpa/IN: loaded serial 0
Nov 16 23:14:36 localhost.localdomain named[10234]: zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
Nov 16 23:14:36 localhost.localdomain named[10234]: zone localhost/IN: loaded serial 0
Nov 16 23:14:36 localhost.localdomain named[10234]: zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0....ial 0
Nov 16 23:14:36 localhost.localdomain named[10234]: zone localhost.localdomain/IN: loaded serial 0
Nov 16 23:14:36 localhost.localdomain named[10234]: zone qq.com/IN: loading from master file qq.zone failed: permis...enied
Nov 16 23:14:36 localhost.localdomain named[10234]: zone qq.com/IN: not loaded due to errors.
Nov 16 23:14:36 localhost.localdomain named[10234]: all zones loaded
Nov 16 23:14:36 localhost.localdomain systemd[1]: Started Berkeley Internet Name Domain (DNS).
Nov 16 23:14:36 localhost.localdomain named[10234]: running
Hint: Some lines were ellipsized, use -l to show in full.
8. 在客户端配置DNS
nameserver 192.168.56.12
9. 测试是否成功
[root@dpf01 ~]# host www.qq.com
www.qq.com has address 1.1.1.1