bind配置包括启动脚本

一:网络环境
bind9.4
主机名(hostname):centos
ip:192.168.1.168
dns:192.168.1.1(配置完后,需要修改,指向192.168.1.168,修改/etc/resolv.conf),

要达到的目的:把这台主机配置成一台dns服务器
dns server:ns1.test.com
ip:192.168.1.168
www.test.com 192.168.1.168

二:安装过程

安装的目录是/usr/local/named, 所有的域名的文件都是放在 /usr/local/named/var下,这个路径需要注意,很多文章是在/var/named这个目录下,不过我觉得把所有的文件放在named的目录下,会更好。

./configure --prefix=/usr/local/named && make && make install
groupadd bind
useradd -g bind -d /usr/local/named -s /sbin/nologin bind
cd /usr/local/named/etc
/usr/local/named/sbin/rndc-confgen > rndc.conf
cat rndc.conf > rndc.key
chmod 777 /usr/local/named/var

tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf


vi named.conf
添加下面内容(

#################

options {
directory "/usr/local/named/var";          //域名文件存放的绝对路径
pid-file "named.pid";              //如果bind启动,自动会在/usr/local/named/var目录生成一个named.pid文件,打开文件就是named进程的ID
};

zone "." IN {
        type hint;          //根域名服务器
        file "named.root"; //存放在//usr/local/named/var目录,文件名为named.root
};

zone "localhost" IN {
        type master;     //类型为主域名服务器
        file "localhost.zone"; //本地正向解析的文件
        allow-update { none; };
};

zone "0.0.127.in-addr.arpa" IN {
        type master;      //类型为主域名服务器
        file "named.local";   //本地反向解析的文件
        allow-update { none; };
};

zone "test.com" IN {      //建立test.com域
        type master;     
        file "test.zone";    //test.com域映射IP地址可在此文件编写
        allow-update { none; };
};


zone "1.168.192.in-addr.arpa" in {   //反向解析
        type master;  
        file "test.local";              //存放反向解析的文件
        allow-update { none; };
};
########################

cd /usr/local/named/var

1:named.root
dig @a.root-servers.net . ns > named.root

2: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
#############

3:named.local
###############
$TTL    86400
@       IN      SOA     localhost. root.localhost. (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
              IN      NS      localhost.

1       IN      PTR     localhost.
####################


4:test.zone
############

$TTL 86400      ; 1 day
@               IN      SOA     ns1.test.com.      root.test.com. (
                                2008050122 ; serial
                                28800      ; refresh (8 hours)
                                7200       ; retry (2 hours)
                                604800     ; expire (1 week)
                                86400      ; minimum (1 day)
                                )
                        NS      ns1.test.com.
                        A       192.168.1.168
                        MX      10 mail.test.com.
www                     A       192.168.1.168
mail        A      192.168.1.168
ns1        A      192.168.1.168

#########################
5:test.local
#############
$TTL 86400
@ IN SOA ns1.test.com. root.test.com.(
20031001;
7200;
3600;
43200;
86400);
@ IN NS ns1.test.com.
168 IN PTR ns1.test.com.
##############

三:启动脚本

vi /etc/rc.d/init.d/named

#!/bin/bash
# named a network name service.
# chkconfig: 345 35 75
# description: a name server

if [ `id -u` -ne 0 ]
then
echo "ERROR:For bind to port 53,must run as root."
exit 1
fi
case "$1" in
start)
if [ -x /usr/local/named/sbin/named ]; then
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf -u bind && echo . && echo 'BIND9 server started'
fi
;;
stop)
kill `cat /usr/local/named/var/named.pid` && echo . && echo 'BIND9 server stopped'
;;
restart)
echo .
echo "Restart BIND9 server"
$0 stop
sleep 10
$0 start
;;
reload)
/usr/local/named/sbin/rndc reload
;;
status)
/usr/local/named/sbin/rndc status
;;
*)
echo "$0 start | stop | restart |reload |status"
;;
esac


chmod 755 /etc/rc.d/init.d/named

chkconfig --add named

service named start

四:启动测试

/usr/local/named/sbin/named -g

你可以看到启动的过程,如果你的配置文件有错误,所以你可以根据这个排错

启动服务测试一下
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf -u bind &


查看状态

/usr/local/named/sbin/rndc status

启动服务

service named restart

编辑/etc/resolv.conf

修改这个文件,把本机的dns指向本机168

nslookup就可以测试了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值