1、DNS安装
yum install -y bind bind-utils
2、修改配置文件 : /etc/named.conf
下面事例中用的本机IP为:192.168.31.119
注意事项:
1)、options.listen-on port 53 { 配置真实IP,不要配置为本机127.0.0.1; };
2)、allow-query { localhost;192.168.31.0/24; }; #配置子网,否则外部客户机访问不到
//
// 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 { 192.168.31.119; };
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;192.168.31.0/24; };// this is very important for foreign addr query dns server.
/*
- 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 yes;
dnssec-validation yes;
/* 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 "named.ca";
};
zone "test.com" IN {
type master;
file "test.com.zone";
allow-update {none;};
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
3、创建DNS解析配置文件:/var/named/test.com.zone
$TTL 3600
@ IN SOA ns.test.com. root(
2019
1D
1H
1W
3H )
NS ns
ns A 192.168.3.4
check A 192.168.3.5
ok A 192.168.31.120
bss A 192.168.31.119
my A 192.168.34.2
4、启动DNS服务
#启动
systemctl start named
#停止
systemctl stop named
#查询状态
systemctl status named
5、客户机测试
1)、修改配置 : /etc/resolv.conf
nameserver 192.168.31.119
注意: 这里最好只配置一个nameserver。
2)、nslookup check.test.com 或者 ping check.test.com 查看IP解析是否正确
6、在windows客户机上测试上,注意设置为首选dns服务器
清空dns缓存命令 ipconfig /flushdns