DNS主从服务器中域(zone)文件类型不一致问题的解决方法

时间:2022-06-01 20:03:48

一、背景

公司的DNS服务器做了主从配置,最近在使用从服务器解析的时候,发现莫名其妙的解析不了,经过反复的检查,配置没有发现任何问题,在看域文件的时候,发现有乱码,问题应该就是出在这里了。通过file命令查看了一番,主服务器的域文件类型是text,从服务器的文件类型是data。

二、解决方法

(一)查阅资料

经过查阅官方资料,BIND9的域文件支持以其他格式读取或备份,raw格式是当前可用的一个附加格式,使用file命令查看文件类型显示是data,使用raw格式主要是为了提高加载速度。raw格式的域文件可以通过named-compilezone命令来进行转换,从而达到编辑的目的,这样操作显然比较麻烦了。

In addition to the standard textual format, BIND 9 supports the ability to read or dump to zone files
in other formats. The raw format is currently available as an additional format. It is a binary format
representing BIND 9’s internal data structure directly, thereby remarkably improving the loading time.
For a primary server, a zone file in the raw format is expected to be generated from a textual zone file
by the named-compilezone command. For a secondary server or for a dynamic zone, it is automatically
generated (if this format is specified by the masterfile-format option) when named dumps the zone
contents after zone transfer or when applying prior updates.
If a zone file in a binary format needs manual modification, it first must be converted to a textual form by
the named-compilezone command. All necessary modification should go to the text file, which should then be converted to the binary form by the named-compilezone command again.
Although the raw format uses the network byte order and avoids architecture-dependent data alignment
so that it is as much portable as possible, it is primarily expected to be used inside the same single
system. In order to export a zone file in the raw format or make a portable backup of the file, it is
recommended to convert the file to the standard textual representation.

(二)解决方法

1 . 在上面的资料中,仔细阅读masterfile-format这一行,似乎有了新的思路。
2 . 修改从服务器相关的配置文件(/etc/named.conf ),添加如下一行:

masterfile-format text ;

3 . 重启从服务器:

systemctl restart named

4 . 过几秒查看slave目录下的域文件内容,是否跟主服务器一致。