------------------bind+mysql-------------------------------------------
安装mysql
下载bind,mysql-bind
# tar -zxvf bind-9.3.3.tar.gz
# tar -zxvf mysql-bind-0-1.gz
# cp mysql-bind-0.1/mysqldb.c bind-9.3.3/bin/named/
# cp mysql-bind-0.1/mysqldb.h bind-9.3.3/bin/named/include/
# cd bind-9.3.3
# vi bin/named/Makefile.in
找到:
# Add database drivers here.
#
DBDRIVER_OBJS =
DBDRIVER_SRCS =
DBDRIVER_INCLUDES =
DBDRIVER_LIBS =
改成
DBDRIVER_OBJS = mysqldb.@O@
DBDRIVER_SRCS = mysqldb.c
DBDRIVER_INCLUDES = -I'/usr/local/mysql/include'
DBDRIVER_LIBS = -L'/usr/local/mysql/lib' -lmysqlclient -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv
]# vi bin/named/main.c
找到/*
* Add calls to register sdb drivers here.
*/
/* xxdb_init(); */
添加 mysqldb_init();
找到
/*
* Add calls to unregister sdb drivers here.
*/
/* xxdb_clear(); */
添加 mysqldb_clear();
./configure –prefix=/usr/local/named –enable-threads
make
make install
#cd /usr/local/named/etc
# ../sbin/rndc-confgen >rndc.conf
# tail -10 rndc.conf | head -9 | sed s/#\//g >named.conf
# vi localhost.zone
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS @
1D IN A 127.0.0.1
vi named.local
$TTL 600
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
@ IN NS localhost.
1 IN A 127.0.0.1
# dig > named.root
# vi named.conf
添加
zone "." {
type hint;
file "named.root";
};
zone "localhost" {
type master;
file "named.local";
};
zone "0.0.127.in-addr.arpa" {
type master;
file "named.127.0.0.1";
};
zone "mydomain.com" {
type master;
database "mysqldb ddns mydomain 192.168.18.29 ddns ddns";
};
zone "18.168.192.in-addr.arpa" {
type master;
database "mysqldb ddns ptr 192.168.18.29 ddns ddns";
};
mysql>
建立ddns数据库
建立ddns用户,密码也为ddns;
插入sql到ddns
创建正向查询表
CREATE TABLE mydomain (name varchar(255) default NULL, ttl int(11) default NULL, rdtype varchar(255) default NULL,
rdata varchar(255) default NULL ) TYPE=MyISAM;
INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'SOA', 'mydomain.com. www.mydomain.com. 200309181 28800 7200 86400 28800′);
INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'NS', 'ns0.mydomain.com.');
INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'NS', 'ns1.mydomain.com.');
INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'MX', '10 mail.mydomain.com.');
INSERT INTO mydomain VALUES ('w0.mydomain.com', 259200, 'A', '172.16.1.235′);
INSERT INTO mydomain VALUES ('w1.mydomain.com', 259200, 'A', '172.16.1.100′);
INSERT INTO mydomain VALUES ('mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');
INSERT INTO mydomain VALUES ('mail.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');
INSERT INTO mydomain VALUES ('ns0.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');
INSERT INTO mydomain VALUES ('ns1.mydomain.com', 259200, 'Cname', 'w1.mydomain.com.');
INSERT INTO mydomain VALUES ('www.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');
INSERT INTO mydomain VALUES ('ftp.mydomain.com', 259200, 'Cname', 'w0.mydomain.com.');
创建反向查询表
CREATE TABLE ptr (name varchar(255) default NULL, ttl int(11) default NULL, rdtype varchar(255) default NULL, rdata varchar(255) default NULL ) TYPE=MyISAM;
INSERT INTO `ptr` VALUES ('1.16.172.in-addr.arpa', 17600, 'SOA', 'mydomain.com. www.mydomain.com. 200309181 28800 7200 86400 28800′);
INSERT INTO `ptr` VALUES ('1.16.172.in-addr.arpa', 17600, 'NS', 'ns0.mydomain.com.');
INSERT INTO `ptr` VALUES ('1.16.172.in-addr.arpa', 17600, 'NS', 'ns1.mydomain.com.');
INSERT INTO `ptr` VALUES ('235.1.16.172.in-addr.arpa', 17600, 'PTR', 'ddns.mydomain.');
//启动bind
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf
启动named,第一次运行它提示找不到libmysqlclient.so.15,但是在mysql编译安装的时候已经生成了这个文件,于是手动拷贝他到/usr/lib/libmysqlclient.so.15,启动正常,可以解析所有域名。
//查看bind日志
tail -f /var/log/messages | grep named
停止bind
killall -9 named
转载于:https://blog.51cto.com/hbzylm/912793