实验目的:
熟悉域名服务器的各种角色
学会构建主域名服务器
实验内容:
在 CentOS 7 上安装和配置 BIND DNS 服务器
1.安装 BIND
在终端中输入以下命令,安装 BIND:
sudo yum install -y bind bind-utils
2. 配置 BIND
创建 DNS 配置文件 /etc/named.conf 并在其中添加基本的 DNS 配置信息:
sudo vi /etc/named.conf
输入以下内容:
options {
listen-on port 53 { any; };
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; };
recursion yes;
forwarders {
8.8.8.8;
8.8.4.4;
};
};
zone "example.com" IN {
type master;
file "forward.example.com";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "reverse.example.com";
allow-update { none; };
};
3.创建 DNS 记录文件
创建 forward.example.com 记录文件:
sudo vi /var/named/forward.example.com
输入以下内容:
;
;BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA example.com. root.example.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.example.com.
@ IN A 192.168.1.1
ns IN A 192.168.1.1
创建 reverse.example.com 记录文件:
sudo vi /var/named/reverse.example.com
输入以下内容:
;
;BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA example.com. root.example.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.example.com.
1 IN PTR example.com.
4. 启动 BIND
启动 BIND 服务并设置为开机启动:
sudo systemctl enable named
sudo systemctl start named
5.配置防火墙
如果您的服务器已启用防火墙,需要配置防火墙以允许 DNS 流量。在终端中输入以下命令,开启 DNS 服务:
sudo firewall-cmd --permanent --add-port=53/tcp
sudo firewall-cmd --permanent --add-port=53/udp
sudo firewall-cmd --reload
完成上述步骤之后,您的 CentOS 7 DNS 服务器基本上就配置好了。具体的配置过程和命令会因为您的需求而有所变化。
感谢大家的观看!