本节我们将通过脚本来实现动态添加域名及解析记录。
1.安装bind
请参考:http://blog.csdn.net/zhu_tianwei/article/details/45045431
2.管理脚本
脚本都放在chroot/bin目录下
管理脚本./bin/slim-bind
- ./bin/slim-bind
- Usage:./bin/slim-bind start | stop | restart |reload |status
管理bind的启动、关闭、重启、重新加载配置、状态。
3.检查脚本
1)检查zone文件是否有效
- ./bin/slim-checkzone -h
- usage: ./bin/slim-checkzone [-z zone -f zonefile] [-h]
- z zone name
- f zone file
- h output this help and exit
说明:z 指定zone名称
f 指定zone的文件
2)检查named.conf是否正确
- ./bin/slim-checkconf -h
- usage: ./bin/slim-checkconf named.conf [-h]
- h Output this help and exit
- The named.conf file is relatvie to "chroot",such as /etc/named.conf.
- By using chroot, you must use the root user.
由于使用了chroot,使用该脚本必须使用root权限,指定的named.conf是chroot的相对路径。
如:./bin/slim-checkconf /etc/named.conf4.添加删除域名脚本
- ./bin/slim-zone-randfs -h
- usage: ./bin/slim-zone-randfs [-s server -p port -o [r|a|n|d|f|s] -v view -z zone -f zonefile] [-h]
- command is one of the following:
- s bind server ip(default:127.0.0.1)
- p bind server port(default:953)
- o operation type
- r reload configuration file and zones.
- a add zone to given view. Requires new-zone-file option.
- n resend NOTIFY messages for the zone.
- d removes zone from given view.
- f flushes the server's caches for a view or zone.
- s display status of the server.
- v view name
- z zone name
- f zone file
- h Output this help and exit
- when the zone doesn't exit,we can call the rndc to add the zone dynamicly,which 'view' 'zone' 'zonefile' must be used.
- 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.添加删除解析记录脚本
- ./bin/slim-rdata-ad -h
- usage: ./bin/slim-rdata-ad [-s server -p port -o [a|d] -v view -r rdata ] [-h]
- s bind server ip(default:127.0.0.1)
- p bind server port(default:53)
- o operation type
- a add zone record
- d delete zone record
- v view name
- r zone rdata string,such as "www.slimsmart.cn 3600 IN A 1.1.1.1"
- 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管理页面,方便维护管理。