首页 » LINUX » linux下bind9.8+dlz+mysql 的dns服务器局域网配置

linux下bind9.8+dlz+mysql 的dns服务器局域网配置

 

linux下bind9.8+dlz+mysql 的dns服务器局域网配置

安装1.mysql

我用的二进制包安装

groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
cd /usr/local/src
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.24-linux2.6-x86_64 /usr/local/mysql
cd /usr/local/mysql
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld
export PATH=$PATH:/usr/local/mysql/bin
service mysqld start
mysql //这里初始没有密码直接回车
//这里把root用远程访问打开后,方便管理。我用的navicat for mysql 管理
grant all privileges on *.* to root@'%' identified by 'mysqlpassword';//语序远程连接
flush privileges;

//创建bind dlz的mysql数据库及表
create database bind;
use bind;
CREATE TABLE `dns_records` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `zone` varchar(255) NOT NULL DEFAULT '' COMMENT '区域',
 `host` varchar(255) NOT NULL DEFAULT '' COMMENT '主机名',
 `type` varchar(255) NOT NULL DEFAULT '' COMMENT 'DNS数据类型',
 `data` varchar(255) NOT NULL DEFAULT '' COMMENT 'IP地址/主机名/完整的域名',
 `ttl` int(11) NOT NULL DEFAULT '0' COMMENT '存活时间',
 `mx_priority` varchar(255) NOT NULL DEFAULT '' COMMENT 'mx优先级',
 `refresh` int(11) NOT NULL DEFAULT '0' COMMENT 'SOA的刷新时间记录',
 `retry` int(11) NOT NULL DEFAULT '0' COMMENT 'SOA的重试时间记录',
 `expire` int(11) NOT NULL DEFAULT '0' COMMENT 'SOA的过期时间记录',
 `minimum` int(11) NOT NULL DEFAULT '0' COMMENT 'SOA的最短时间记录',
 `serial` bigint(20) NOT NULL DEFAULT '0' COMMENT 'SOA的连续时间记录',
 `resp_person` varchar(255) NOT NULL DEFAULT '' COMMENT 'SOA负责人记录',
 `primary_ns` varchar(255) NOT NULL DEFAULT '' COMMENT 'SOA的主要名称服务器记录',
 PRIMARY KEY (`id`),
 KEY `host` (`host`),
 KEY `zone` (`zone`),
 KEY `type` (`type`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
#插入一条数据备测试
insertinto dns_records (zone,host,type,data,ttl,retry) values('aaa.com','www','A','192.168.199.2','86400','15');

安装2.bind


cd /usr/local/src

wget ftp://ftp.isc.org/isc/bind9/9.8.7/bind-9.8.7.tar.gz

tar zxvf bind-9.8.7.tar.gz

cd ./bind-9.8.7

./configure --prefix=/usr/local/bind9 --disable-openssl-version-check --with-dlz-mysql=/usr/local/mysql

make && make install

cd /usr/local/bind9
./sbin/rndc-confgen -a
./sbin/rndc-confgen > ./etc/named.conf
#这里先看key
cat etc/rndc.key
key "rndc-key" {
 algorithm hmac-md5;
 secret "hq1L847nM6A/sDQ9ZBIX5w==";
};

vi ./etc/named.conf

# Start of rndc.conf
key "rndc-key" {
 algorithm hmac-md5;
 secret "hq1L847nM6A/sDQ9ZBIX5w==";
};
#
controls{
 inet 127.0.0.1 port 953
 allow { 127.0.0.1; } keys { "rndc-key"; };
};
options {
 #default-key "rndc-key";
 #default-server 127.0.0.1;
 #default-port 953;
 directory "/usr/local/bind9/etc/";
 pid-file "/usr/local/bind9/var/run/named.pid";
 allow-query{any;};
 allow-query-cache{ any; };
 recursion yes;
 version "bns-dns1";
};
# End of rndc.conf

#include "/usr/local/bind9/etc/my.acl";
acl "my" {
 127.0.0.1/18;
 192.168.3.0/24;#局域网网段
 };
view "my"{
 match-clients{my;};
 dlz "Mysql zone" {
 database "mysql
 {host=127.0.0.1 dbname=bind ssl=false port=3306 user=root pass=mysqlpassword}

 {select zone from dns_records where zone = '$zone$'}

 {select ttl, type, mx_priority,
 case when lower(type)='txt' then concat('\"', data, '\"')
 when lower(type)='soa' then concat_ws('',data,resp_person,serial,refresh,retry,expire,minimum)
 else data end as mydata from dns_records where zone = '$zone$' and host = '$record$'}";
 };
};

#保存即可

启动named


./sbin/named -4 -n 2 -f &

原文链接:linux下bind9.8+dlz+mysql 的dns服务器局域网配置,转载请注明来源!

0