配置dns主从服务器,能够实现正常的正反向解析
实验步骤:
第一步环境搭建:DNS服务是基于cs架构实现的,因此我们需要用两台Linux主机,一台充当服务器,一台充当客户机。我们这里用一台ip地址为192.168.23.129的openeuler系统的主机充当服务器,另一台IP地址为192.168.23.128红帽系统的充当客户机,我们这里方便书写,我们称服务机为serve,客户机为client,并且我们通过修改/etc/hostname文件修改主机名,并用reboot命令重启系统使其生效。
第二步配置主服务器:1.在主服务器上安装DNS服务
yum install bind -y
2.修改配置文件 vim/etc/named.conf
options {
listen-on port 53 { any; }; #监听所有网络端口
listen-on-v6 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";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { localhost; };
allow-transfer {192.168.23.128;};#允许从服务器复制数据
然后在配置文件中添加要解析的域名和DNS记录
zone "www.xsl.com" IN {
type master;
file "/var/named/www.xsl.com.zone";
};
接着创建文件
[root@serve ~]# touch /var/named/www.xsl.com.zone
[root@serve ~]# chown named:named /var/named/www.xsl.com.zone
然后在文件中写入
$TTL 86400
@ IN SOA ns1.xsl.com. admin.xsl.com. (
2022011801 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ; minimum TTL
)
@ IN NS ns1.xsl.com.
@ IN NS ns2.xsl.com.
ns1 IN A 192.168.23.129
ns2 IN A 192.168.23.128
启动主服务器配置
[root@serve ~]# systemctl start named
[root@serve ~]# systemctl enable named
Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.
3.配置从服务器
1.安装bind
yum install bind -y
2.配置文件
vim /etc/named.conf
zone "www.xsl.com" IN {
type slave;
master {192.168.23.129;};
file "/var/named/www.xsl.com.zone";
};
3.启动服务
[root@serve ~]# systemctl start named
[root@serve ~]# systemctl enable named
Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.
第三步配置防火墙:
[root@serve ~]# iptables -I INPUT -p udp --dport 53 -j ACCEPT
[root@serve ~]# iptables-save > /etc/sysconfig/iptables
放开53号端口
然后测试可以用dig或者nolookup
[root@client ~]# nslookup
> server 192.168.23.129
Default server: 192.168.23.129
Address: 192.168.23.129#53
第四步配置反向命令:
1.修改配置文件/etc/named.conf
在主服务器上添加
zone "129.23.168.192.in-addr.arpa" {
type master;
file "/var/named/129.23.168.192.rev";
};
创建并修改文件
[root@serve ~]# touch /var/named/129.23.168.192.rev
[root@serve ~]# vi /var/named/129.23.168.192.rev
$TTL 86400
@ IN SOA ns1.xsl.com. admin.xsl.com. (
2022011801 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
86400 ; minimum TTL
)
@ IN NS ns1.xsl.com.
@ IN NS ns2.xsl.com.
129 IN PTR xsl.com.
128 IN PTR secondary.xsl.com.
配置从服务器文件
zone "23.168.192.in-addr.arpa" {
type slave;
masters { 192.168.23.129; };
file "/var/named/slaves/23.168.192.rev";
};
测试即可