一、更改计算机名ns1
[root@server10 ~]# hostnamectl set-hostname ns1 更改计算机名ns1
[root@server10 ~]# exit 退出
二、安装dns
[root@ns1 ~]# dnf -y install bind bind-utils 安装dns
三、编辑dns的配置文件
[root@ns1 ~]# vim /etc/named.conf 编辑dns的配置文件
acl internal-network { 定义内部网络的访问控制列表
10 192.168.7.0/24; 内部网络的网段192.168.7.0
11 };
12 options {
13 listen-on port 53 { any; }; 监听ipv4的任何地址
14 listen-on-v6 port 53 { any; }; 监听ipv6的任何地址
21 allow-query { localhost;internal-network; }; 允许本机和内部网络向dns服务器发起查询请求
22 allow-transfer { localhost; }; 允许本地传输
62 zone "benet.com" IN { 定义正向区域benet.com
63 type master; 类型为组dns服务器
64 file "benet.com.lan"; 文件的名称为benet.com.lan (正向区域文件的名称)
65 allow-update { none; }; 不允许更新
66 };
67
68 zone "7.168.192.in-addr.arpa" IN { 定义反向查询区域
69 type master; 类型为组dns服务器
70 file "7.168.192.db"; 反向区域文件的名称:7.168.192.db
71 allow-update { none; }; 不允许更新
72 };
四、编辑dns的系统文件
[root@ns1 ~]# vim /etc/sysconfig/named 编辑dns的系统文件
OPTIONS="-4" #dns只允许ipv4
五、进入dns区域的目录
[root@ns1 ~]# cd /var/named/ 进入dns区域的目录
六、创建dns正向区域文件
[root@ns1 named]# vim benet.com.lan 创建dns正向区域文件
$TTL 86400 生存周期86400秒
@ IN SOA 定义起始授权机构 ns1.benet.com. 域名ns1.benet.com. root.benet.com. dns的邮箱地址 (
2025030511 配置文件修改的版本 格式是年月日+修改的次数
3600 用来设定辅助dns与组dns进行同步的时间间隔为3600秒
1800 如果辅助dns服务器在进行更新失败后要隔1800秒进行重试
604800 设定复制dns在与组dns同步失败后604800秒清除对应的记录
86400 最小生存周期86400秒
)
IN NS ns1.benet.com. 域名服务器为ns1.benet.com.
IN A 192.168.7.10 定义主机指针记录为192.168.7.10
IN MX 10 mail.benet.com. 定义邮件交换器为mail.benet.com.
ns1 IN A 192.168.7.10 指向dns服务器的ip地址
www IN A 192.168.7.11 指向web服务器的ip地址
七、将正向区域文件复制给反向区域文件
[root@ns1 named]# cp benet.com.lan 7.168.192.db 将正向区域文件复制给反向区域文件
八、编辑vim 7.168.192.db反向区域文件
[root@ns1 named]# vim 7.168.192.db
$TTL 86400
@ IN SOA ns1.benet.com. root.benet.com. (
2025030511
3600
1800
604800
86400
)
IN NS ns1.benet.com.
10 IN PTR ns1.benet.com. dns服务器的反向指针记录
11 IN PTR www.benet.com. web服务器的反向指针记录
九、启动防火墙及在防火墙里添加dns服务
[root@ns1 ~]# systemctl enable --now firewalld 启动防火墙并设置防火墙开机启动
Created symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service → /usr/lib/systemd/system/firewalld.service.
Created symlink /etc/systemd/system/multi-user.target.wants/firewalld.service → /usr/lib/systemd/system/firewalld.service.
[root@ns1 ~]#
[root@ns1 ~]# firewall-cmd --add-service=dns 在防火墙里添加dns服务(在防火墙里添加dns端口 dns端口号53)
success
[root@ns1 ~]# firewall-cmd --runtime-to-permanent 在防火墙里添加永久运行时
success
十、在win11虚拟机上测试
10.0 网络配置
ip: 192.168.7.21
子网掩码: 255.255.255.0
dns: 192.168.7.10
ping 192.168.7.10
10.1 非交互式测试域名服务器
C:\Users\qq>nslookup ns1.benet.com 非交互式测试域名服务器
服务器: ns1.benet.com
Address: 192.168.7.10
名称: ns1.benet.com
Address: 192.168.7.10
10.2 非交互式测试web服务器
C:\Users\qq>nslookup www.benet.com 非交互式测试web服务器
服务器: ns1.benet.com
Address: 192.168.7.10
名称: www.benet.com
Address: 192.168.7.11
10.3 进行交互式测试
C:\Users\qq>nslookup 进行交互式测试
默认服务器: ns1.benet.com
Address: 192.168.7.10
> set type=ns 设置类型为域名服务器
> ns1.benet.com 域名服务器的网址
服务器: ns1.benet.com
Address: 192.168.7.10
benet.com 输出正向区域文件的信息
primary name server = ns1.benet.com 表示设置成功
responsible mail addr = root.benet.com
serial = 2025030511
refresh = 3600 (1 hour)
retry = 1800 (30 mins)
expire = 604800 (7 days)
default TTL = 86400 (1 day)
> set type=cname 设置类型为别名
> www.benet.com 输入web服务器的网址
服务器: ns1.benet.com
Address: 192.168.7.10
benet.com
primary name server = ns1.benet.com
responsible mail addr = root.benet.com
serial = 2025030511
refresh = 3600 (1 hour)
retry = 1800 (30 mins)
expire = 604800 (7 days)
default TTL = 86400 (1 day)
> set type=all 设置类型为所有
> benet.com 输入主机名:benet.com
服务器: ns1.benet.com
Address: 192.168.7.10
benet.com
primary name server = ns1.benet.com
responsible mail addr = root.benet.com 输出邮件交换器为mail.benet.com.
serial = 2025030511
refresh = 3600 (1 hour)
retry = 1800 (30 mins)
expire = 604800 (7 days)
default TTL = 86400 (1 day)
benet.com nameserver = ns1.benet.com
benet.com internet address = 192.168.7.10
benet.com MX preference = 10, mail exchanger = mail.benet.com
> exit