|
1.基础环境
centos6.9 172.16.255.141 dns
centos6.9 172.16.255.142 client
2.基础优化
yum groupinstall "Development tools" -y
yum install vim wget lrzsz -y
yum install epel-release -y
关闭selinux
关闭防火墙
3.安装并启动mysql
yum install mysql*
/etc/init.d/mysqld start
进入mysql修改mysql的root密码
set password for root@'localhost'=password('123456');
4.创建dns数据库、表
CREATE DATABASE `dnsdb` DEFAULT CHARACTER SET utf8;
use dnsdb;
CREATE TABLE `records` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL DEFAULT '0',
`pid` bigint(20) NOT NULL DEFAULT '0',
`oid` int(11) NOT NULL DEFAULT '0',
`zone` varchar(30) NOT NULL DEFAULT '',
`host` varchar(30) NOT NULL DEFAULT '',
`rtype` varchar(20) NOT NULL DEFAULT '',
`data` varchar(30) NOT NULL DEFAULT '',
`ttl` int(11) NOT NULL DEFAULT '3600',
`view` varchar(255) NOT NULL DEFAULT 'any',
`mx_priority` bigint(20) DEFAULT NULL,
`refresh` int(11) NOT NULL DEFAULT '28800',
`retry` int(11) NOT NULL DEFAULT '14400',
`expire` int(11) NOT NULL DEFAULT '86400',
`minimum` int(11) NOT NULL DEFAULT '86400',
`serial` varchar(255) NOT NULL DEFAULT '2018070100',
`resp_person` varchar(255) NOT NULL DEFAULT 'test.com',
`primary_ns` varchar(255) NOT NULL DEFAULT 'ns1.test.com',
`second_ns` varchar(255) NOT NULL DEFAULT 'ns2.test.com',
`data_count` int(11) NOT NULL DEFAULT '0',
`ups` int(11) NOT NULL DEFAULT '0',
`avil` int(11) NOT NULL DEFAULT '0',
`rtime` datetime NOT NULL,
`status` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
添加记录
INSERT INTO records (zone,host,rtype,data) VALUES ('test.com', '@', 'A', '192.168.0.103');
INSERT INTO records (zone,host,rtype,data) VALUES ('test.com', 'www', 'A', '192.168.0.104');
INSERT INTO records (zone,host,rtype,data) VALUES ('test.com', 'bbs', 'A', '192.168.0.105');
5.安装bind9
yum install openssl-devel openldap-devel unixODBC-devel gcc -y
wget ftp://ftp.isc.org/isc/bind9/9.11.0-P2/bind-9.11.0-P2.tar.gz
tar zxvf bind-9.11.0-P2.tar.gz
cd bind-9.11.0-P2
export CPPFLAGS="-I/usr/lib64/mysql $CPPFLAGS"
export LDFLAGS="-L/usr/lib64/mysql $LDFLAGS"
export LD_LIBRARY_PATH="/usr/lib64/mysql"
./configure --prefix=/usr/local/bind --enable-threads --enable-largefile --disable-ipv6 --disable-openssl-version-check --with-dlz-mysql=yes
make && make install
查看是否安装成功
/usr/local/bind/sbin/named -v
创建rndc配置文件
../sbin/rndc-confgen -r /dev/urandom > rndc.conf
创建named.ca配置文件
wget -O named.ca http://www.internic.net/domain/named.root
创建named.conf配置文件
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
创建dns运行用户
groupadd -g -r 25 named
groupadd -r -g 25 named
useradd -r -u 25 -s /bin/nologin -d /usr/local/named -g named named
修改named.conf配置文件支持dlz
vim /usr/local/bind/etc/named.conf
key "rndc-key" {
algorithm hmac-md5;
secret "fLcWiN5v7aYWwPoV0NeK1A==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
logging {
channel bind_log {
file "/tmp/bind.log" versions 3 size 20m;
severity info;
print-time yes;
print-severity yes;
print-category yes;
};
category default {
bind_log;
};
};
options {
listen-on port 53 { 172.16.255.141; };
directory "/usr/local/bind";
Pid-file "named.pid";
allow-query-cache { any; };
allow-query { any; };
};
dlz "Mysql zone" {
database "mysql
{host=localhost dbname=dnsdb ssl=false port=3306 user=root pass=123456 }
{select zone from records where zone = '$zone$' and view='any' limit 1}
{select ttl, rtype, mx_priority, case when lower(rtype)='txt' then concat('\"', data, '\"') when lower(rtype) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum) else data end as mydata from records where zone = '$zone$' and host = '$record$' and view='any' and ups='0'}
{}
{select ttl, rtype, host, mx_priority, case when lower(rtype)='txt' then concat('\"', data, '\"') else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from records where zone = '$zone$' and view='any' and ups='0'}";
};
6.启动bind
/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -f -g -u named &
client机器
安装bind应用插件(dig、nslookup等)
yum install -y bind-utils
修改dns文件
vim /etc/resolv.conf
nameserver 172.16.255.141
查询dns解析是否生效
dig test.com
dig www.test.com
dig -t A bbs.test.com
|
|