bind9 mysql_bind9+mysql dlz(Dynamically Loadable Zones)

本文介绍了如何配置bind9使用MySQL作为动态加载区域(DLZ)的数据源,包括MySQL的安装、配置,以及创建DNS记录的步骤。通过这种方式,可以将DNS记录存储在数据库中,便于管理和维护。
摘要由CSDN通过智能技术生成

yum install openssl openssl-devel

groupadd mysql

useradd -g mysql -s /sbin/nologin -M mysql

chown -R mysql:mysql /usr/local/mysql

./configure  --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client -with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg

make && make install

/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql

cd /usr/local/mysql

cp share/mysql/my-medium.cnf /etc/my.cnf

nohup ./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/usr/local/mysql/var &

登录mysql /usr/local/mysql/bin/mysql

insert into mysql.user(Host,User,Password) values("localhost","dns",password("dns"));

insert into mysql.user(Host,User,Password) values("%","dns",password("dns"));

GRANT ALL PRIVILEGES ON *.* TO 'dns'@'%' IDENTIFIED BY 'dns' WITH GRANT OPTION;

flush privileges;

CREATE TABLE `dns_records` (

`id` int(10) unsigned NOT NULL auto_increment,

`zone` varchar(255) NOT NULL,

`host` varchar(255) NOT NULL default '@',

`type` enum('MX','CNAME','NS','SOA','A') NOT NULL,

`data` varchar(255) default NULL,

`ttl` int(11) NOT NULL default '800',

`mx_priority` varchar(255) default NULL,

`refresh` int(11) default NULL,

`retry` int(11) default NULL,

`expire` int(11) default NULL,

`minimum` int(11) default NULL,

`serial` bigint(20) default NULL,

`resp_person` varchar(255) default NULL,

`primary_ns` varchar(255) default NULL,

PRIMARY KEY  (`id`),

KEY `id` (`id`),

KEY `type` (`type`),

KEY `host` (`host`),

KEY `zone` (`zone`)

) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

--soa

INSERT INTO dns_records (zone,host,type,serial,refresh,retry,expire,minimum,primary_ns,resp_person)

VALUES ('linuxtone.org', '@', 'SOA', 2009030200, 172800, 800, 1209600, 3600 , 'ns1.linuxtone.org', 'root.linuxtone.org.');

--linuxtone.org redirection for any host to linuxtone.org.

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', '*', 'CNAME', 'linuxtone.org.');

--nameserver for zone

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', '@', 'NS', 'ns1.linuxtone.org.');

--toplevel-ip-address of zone itself

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', '@', 'A', '192.168.0.103');

2.#host anlegen:

--ip nameserver (resp_person can be NULL)

INSERT INTO dns_records (zone,host,type,DATA,resp_person)

VALUES ('linuxtone.org', 'ns1', 'A', '192.168.0.103', 'root.linuxtone.org.');

A:www.linuxtone.org

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', 'www', 'A', '192.168.0.108');

A:bbs.linuxtone.org

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', 'bbs', 'A', '192.168.0.109');

3.#host alias anlegen:

--ns2 directs to ns1

INSERT INTO dns_records (zone,host,type,DATA,resp_person)

VALUES ('linuxtone.org', 'ns2', 'CNAME', 'ns1.linuxtone.org.', 'root.linuxtone.org.');

alias:man.linuxtone.org cname www

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', 'man', 'CNAME', 'www');

alias: host.linuxton.org cname bbs

INSERT INTO dns_records (zone,host,type,DATA)

VALUES ('linuxtone.org', 'host', 'CNAME', 'bbs.linuxtone.org.');

4.#mailserver anlegen:

--ns2 directs to ns1

INSERT INTO dns_records (zone,host,type,DATA,mx_priority, resp_person)

VALUES ('linuxtone.org', '*', 'MX', 'mail.linuxtone.org.', '80', 'root.linuxtone.org.');

安装bind,9.4.0以上版本都有DLZ补丁了,DLZ(Dynamically Loadable Zones),允许区域记录放置在数据库中,并且支持多种数据库。

./configure --with-dlz-mysql --enable-largefile --enable-threads=no --prefix=/usr/local/bind --disable-openssl-version-check

make && make install

cd /usr/local/bind/etc/

../sbin/rndc-confgen >rndc.conf

tail -n10 rndc.conf | head -n9 | sed -e s/#\//g >named.conf

dig > named.root  //这一步没做成功也没关系 貌似

vi /usr/local/bind/etc/named.conf

dlz "Mysql zone" {

database "mysql

{host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass= }

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

{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')

else data end from dns_records where zone = '$zone$' and host = '$record$'

and not (type = 'SOA' or type = 'NS')}

{select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire, minimum

from dns_records where zone = '$zone$' and (type = 'SOA' or type='NS')}

{select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,

minimum from dns_records where zone = '$zone$' and not (type = 'SOA' or type = 'NS')}

{select zone from xfr_table where zone = '$zone$' and client = '$client$'}

{update data_count set count = count + 1 where zone ='$zone$'}";

};

启动

/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值