一、 搭建DNS server服务器
- 安装依赖包
yum install bind* -y
- 配置文件
options {
listen-on port 53 { any; }; #修改此处 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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; #修改此处 any
3. 修改配置文件
vim /etc/named.rfc1912.zones
# 添加正向解析此处用test.com为例
zone "test.com" IN {
type master;
file "test.com.zone";
allow-update { none; };
};
- 复制文件并修改
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost test.com.zone
[root@localhost named]# vim test.com.zone
$TTL 1D
@ IN SOA @ root.test.com. ( #修改此行root.test.com.
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
AAAA ::1
www IN A 192.168.10.11 #添加此行,A记录www.test.com 192.168.10.11
- 重启服务
systemctl restart named
- 验证
# 1. 修改本地dns为本机ip
[root@localhost named]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.10.3
# 2. 用dig/host/nslookup解析www.test.com
dig www.test.com
host www.test.com
nslookup www.test.com
7. 客户端测试
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.10.3
#相同命令测试
#需要将服务端和客户端都关闭内核防火墙
setenforce 0 && iptables -F
dig www.test.com
host www.test.com
nslookup www.test.com
|