源码安装bind9.16.13
源码安装Bind-9.16.13
环境准备
1、 使用yum完成以下软件安装。
yum -y install net-tools
yum -y install gcc*
yum -y install tcpdump
yum -y install cmake
yum -y install bind-utils
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum -y install libffi-devel -y
yum -y install libxml*
yum -y install git
yum -y install libtool
yum -y install wget
yum -y install vim
yum -y install python-pip
yum -y install libcap-devel
2、 在https://www.isc.org/download/ 下载最新stable版本bind
[root@dnscache ~]# wget https://downloads.isc.org/isc/bind9/9.16.13/bind-9.16.13.tar.xz
3、 执行以下命令安装libuv
yum install -y epel-release
yum install -y libuv
yum install -y libuv-devel
4、安装ply,如果不安装ply模块,bind在编译时会报错
#pip install ply
5、 创建named用户及相关目录。
使用53端口作为named组和named用户的ID号
groupadd -g 53 -r named
useradd -u 53 -s /sbin/nolgin -r named -g named
安装bind
1、 解压下载的新版本bind
[root@dnscache ~]# tar -xvf bind-9.16.13.tar.xz
2、 编译,安装bind
[root@dnscache ~]# cd bind-9.16.13
[root@dnscache bind-9.16.13]# ./configure --prefix=/usr/local/bind
[root@dnscache bind-9.16.13]# make && make install
3、 安装成功后 /usr/local/bind目录中的内容如下
bind初始化配置
1、# cd /usr/local/bind/
2、[root@dnscache bind]# sbin/rndc-confgen > etc/rndc.conf
注意:如果这里卡住不动可改用下面的命令
sbin/rndc-confgen -r /dev/urandom > etc/rndc.conf
3、[root@dnscache bind]# cd /usr/local/bind/etc/
4、[root@dnscache etc]# tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
此时named.conf文件内容如下:
4、 编辑配置文件,在当前文件添加以下内容
# vim /usr/local/bind/etc/named.conf
- options {
listen-on port 53 {127.0.0.1; };
listen-on-v6 port 53 {::1;};
directory "/usr/local/bind/var/run";
pid-file "named.pid";
recursion yes;
querylog yes;
allow-query { any; };
};
logging {
channel query_log {
file "data/bind_query.log" versions 3;
severity dynamic;
print-category yes;
print-time yes;
print-severity yes;
};
category queries { query_log; };
};
zone "." IN{
type hint;
file "named.ca";
};
include "/usr/local/bind/etc/named.rfc1912.zones";
5、 在/usr/local/bind/var/run目录下创建一个data目录用来存放日志文件
# cd /usr/local/bind/var/run/
# mkdir data
6、 在/usr/local/bind/var/run目录下生成named.ca数据文件
# cd /usr/local/bind/var/run/
# dig -t NS . >/usr/local/bind/var/run/named.ca
7、 在/usr/local/bind/etc/目录下创建named.rfc1912.zones文件,并添加以下内容
# vim /usr/local/bind/etc/named.rfc1912.zones
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
8、 在/usr/local/bind/var/run目录下创建对应数据文件
由named.rfc1912.zones文件可知有named.localhost、named.loopback、named.empty数据文件
# cd /usr/local/bind/var/run/
# vim named.localhost
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
# vim named.loopback
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
PTR localhost.
# vim named.empty
$TTL 3H
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
9、# chown -R named:named /usr/local/bind
10、检查named.conf文件
# cd /usr/local/bind/sbin/
# ./named-checkconf ../etc/named.conf
运行bind
1、 执行如下命令启动bind
# /usr/local/bind/sbin/named -u named -c /usr/local/bind/etc/named.conf
2、 测试能正常解析
# ps -ef|grep named
# netstat -anp|grep 53
# dig @127.0.0.1 www.baidu.com
设置bind开机启动服务
1、 在/etc/rc.d/init.d/目录下编写一个名为named的shell脚本
# cd /etc/rc.d/init.d/
# vim named
#!/bin/bash
#chkconfig: 545 35 75
#description: named DNS service manager
data=" /usr/local/bind/sbin/named -u named -c /usr/local/bind/etc/named.conf"
function START(){
eval $data && echo -e "BIND9 start\033[32m ok\033[0m"
}
function STOP(){
kill `cat /usr/local/bind/var/run/named.pid` && echo -e "BIND9 stop\033[32m ok\033[0m"
}
case "$1" in
start)
START
;;
stop)
STOP
;;
restart)
STOP
sleep 3
START
;;
*)
echo "Usage: named (start|stop|restart)"
;;
esac
2、# chmod +x /etc/rc.d/init.d/named
3、# chkconfig --add named
4、# chkconfig named on
5、测试是否能正常使用
写在最后:
1、 源码安装后dns的启动方式:
service network start
2、 named主配置文件位置:
/usr/local/bind/etc/named.conf
3、 检查主配置文件合法性的方式:
cd /usr/local/bind/sbin/
./named-checkconf ../etc/named.conf