DNS BIND 搭建域名智能解析DNS服务器之动态添加解析

本节我们将通过脚本来实现动态添加域名及解析记录。

1.安装bind

请参考:http://blog.csdn.net/zhu_tianwei/article/details/45045431

2.管理脚本

脚本都放在chroot/bin目录下

管理脚本./bin/slim-bind

  1. ./bin/slim-bind
  2. Usage:./bin/slim-bind start | stop | restart |reload |status

管理bind的启动、关闭、重启、重新加载配置、状态。
3.检查脚本

1)检查zone文件是否有效

  1. ./bin/slim-checkzone -h
  2. usage: ./bin/slim-checkzone [-z zone -f zonefile] [-h]
  3.     z   zone name
  4.     f   zone file
  5.     h   output this help and exit

说明:z 指定zone名称

f 指定zone的文件

2)检查named.conf是否正确

  1. ./bin/slim-checkconf -h
  2. usage: ./bin/slim-checkconf named.conf [-h]
  3.     h   Output this help and exit
  4. The named.conf file is relatvie to "chroot",such as /etc/named.conf.
  5. By using chroot, you must use the root user.

由于使用了chroot,使用该脚本必须使用root权限,指定的named.conf是chroot的相对路径。
如:./bin/slim-checkconf /etc/named.conf4.添加删除域名脚本

  1. ./bin/slim-zone-randfs -h
  2. usage: ./bin/slim-zone-randfs  [-s server -p port -o [r|a|n|d|f|s] -v view -z zone -f zonefile] [-h]
  3. command is one of the following:
  4.     s   bind server ip(default:127.0.0.1)
  5.     p   bind server port(default:953)
  6.     o   operation type
  7.         r       reload configuration file and zones.
  8.         a       add zone to given view. Requires new-zone-file option.
  9.         n       resend NOTIFY messages for the zone.
  10.         d       removes zone from given view.
  11.         f       flushes the server's caches for a view or zone.
  12.         s       display status of the server.
  13.     v   view name
  14.     z   zone name
  15.     f   zone file
  16.     h   Output this help and exit
  17. when the zone doesn't exit,we can call the rndc to add the zone dynamicly,which 'view' 'zone' 'zonefile' must be used.
  18. the zonefile is relatvie to "chroot",such as /var/named/zone/test.com.zone.

该脚本可以动态添加、删除域名、加载配置、刷新缓存,以及查看bind状态说明:

s  指定bind服务器IP地址,默认是127.0.0.1

p  指定rndc启动端口,默认是953

o  执行操作类型,主要有如下几种类型:

r 加载配置

a 添加域名

n 重新发送notify消息

d 删除域名

f 刷新缓存

s 查看状态
v  所操作的视图

z  所操作的zone 名称

f  所操作的zone文件

5.添加删除解析记录脚本

  1. ./bin/slim-rdata-ad -h
  2. usage: ./bin/slim-rdata-ad [-s server -p port -o [a|d] -v view -r rdata ] [-h]
  3.     s   bind server ip(default:127.0.0.1)
  4.     p   bind server port(default:53)
  5.     o   operation type
  6.         a  add zone record
  7.         d  delete zone record
  8.     v   view name
  9.     r   zone rdata string,such as "www.slimsmart.cn 3600 IN A 1.1.1.1"
  10.     h   output this help and exit

该脚本动态向每个视图添加域名的解析记录。说明:

s  指定bind服务器IP地址,默认是127.0.0.1

p  指定rndc启动端口,默认是953

o  执行操作类型,主要有如下几种类型:

a 添加解析记录   d 删除解析记录

v  所操作的视图

r  解析记录值rdata

脚本地址:https://github.com/slimina/slim-bind

大家可以利用这些脚本,动态添加域名解析,也可以开发web管理页面,方便维护管理。

发表评论