1. DNS 服务器安装 bind 服务:
yum -y install bind-utils bind bind-devel bind-libs
2. 配置主配置文件:
vim /etc/named.conf
options {
listen-on port 53 { any; }; #监听的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 { any; }; #允许的ip
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
forwarders { 202.96.128.166;8.8.8.8; };
};
3. 追加域名解析入口配置:
vim /etc/named.rfc1912.zones
zone "dylan.com" IN { # 测试用的域是 dylan.com
type master;
file "dylan.com.zone"; # 配置文件为 dylan.com.zone,该文件目录为 /var/named/ 下
};
4. 配置单独的解析文件
cd /var/named/
cp named.localhost dylan.com.zone
chown named.named dylan.com.zone
修改配置:vim ``dylan.com.zone
$TTL 1D ;TTL 修改配置生效时间,默认为一天
@ IN SOA @ rname.invalid. (
0 ; serial,配置编号,每次改完配置 +1,这样从服务器就知道更新配置
1D ; refresh,从服务器刷新时间,默认一天刷新一次
1H ; retry,如果刷新失败,默认1小时重试一次
1W ; expire,缓存过期时间,一周
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
www IN A 192.168.100.112
5. 启动服务测试
systemctl start named
systemctl enable named
查看端口:
netstat -lnutp| grep 53
ss --inutp|grep 53
本机测试解析:
dig @127.0.0.1 www.dylan.com
查看
另外介绍两种检查配置的方法:
# 检查主配置
named-checkconf /etc/named.conf
# 检查 zone 配置
named-checkzone dylan.com /var/named/dylan.com.zone
6.客户端测试
我们在客户端修改 DNS 配置测试,修改网卡 DNS 配置重启网卡: