快速搭建BIND服务,并实现解析

公司有测试需求,当连接一个网络后自动会进入产品的测试环境,所以搭建了一个DNS解析服务,来完成此需求。

参考:http://blog.chinaunix.net/uid-30149335-id-5069146.html   找了个教程参考了一下,然后根据自己需求更改  

一、安装BIND

yum install -y bind
cp /etc/named.conf /etc/named.conf.bak  
>/etc/named.conf
vim /etc/named.conf 

加入如下配置:

options {
    directory "/var/named";
};

zone "." IN  {
    type hint;
    file "named.ca";
};

zone "localhost" IN {
    type master;
    file "localhost.zone";
};

zone "0.0.127.in-addr.arpa" IN {
    type master;
    file "named.local";
};
chown named /etc/named.conf        #如果属组是named可以不改
cd /var/named/
dig -t NS . > named.ca
vim localhost.zone //加入
@                   IN      SOA     localhost.  admin.localhost.     (
                                                                        2013081601
                                                                        1H
                                                                        10M
                                                                        7D
                                                                        1D
                                                                           )
@                   IN          NS          localhost.
localhost.          IN          A           127.0.0.1

vim named.local //加入

 
$TTL 86400
@                    IN      SOA     localhost.  admin.localhost.      (
                                                                        2013081601
                                                                        1H
                                                                        10M
                                                                        7D
                                                                        1D
                                                                        )
@                    IN          NS          localhost.
1                    IN          PTR         localhost

rndc-confgen -r /dev/urandom -a  // 这一步是生成 rndc.key, 如果没有这个key namd 是启动不了的 ####话说我也没测试到底能不能启动。。。

检测配置是否有问题: named-checkconf   

netstat -lnp  |grep named  // 查看一下named进程是否监听了53端口

/etc/init.d/named start   #看看能不能起来,没起来的话根据报错去解决,起来的话就能正常解析了

二、增加一个域名(zone) 备:这就是我的需求,需要把产品的域名解析到我们的测试机上,增加一个域名解析

vim /etc/named.conf   ##请根据自己的域名及IP更改

zone "hotel.test.com" IN {
    type master;
    file "hotel.test.com.lan";
};

zone "10.168.192.in-addr.arpa" IN {
    type master;
    file "10.168.192.db";
};

cd /var/named/

vi hotel.test.com

$TTL    86400
@        IN    SOA   ns.hotel.test.com. root.hotel.test.com. (
               2007041501   ;Serial
               3600         ;Refresh
               1800         ;Retry
               604800       ;Expire
               86400        ;Minimum TTL

)
               IN    NS     ns.hotel.test.com.
               IN    A       192.168.10.10
               IN    MX 10   ns.hotel.test.com.
 
ns             IN    A       192.168.10.10

vi 10.168.192.db

$TTL    86400
@       IN    SOA  ns.hotel.test.com. root.hotel.test.com. (
              2007041501     ;Serial
              3600           ;Refresh
              1800           ;Retry
              604800         ;Expire
              86400          ;Minimum TTL
)
              IN        NS    ns.hotel.test.com.
 
              IN        PTR   hotel.test.com.
              IN        A     255.255.255.0
 
17            IN        PTR   ns.hotel.test.com.

  

把本机DNS改成自己的,然后dig测试一下

[root@TBJ named]# dig hotel.test.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.3 <<>> hotel.test.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34986
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;hotel.test.com.			IN	A

;; ANSWER SECTION:
hotel.test.com.		86400	IN	A	192.168.10.10

;; AUTHORITY SECTION:
hotel.test.com.		86400	IN	NS	ns.hotel.test.com.

;; ADDITIONAL SECTION:
ns.hotel.test.com.	86400	IN	A	192.168.10.10

;; Query time: 0 msec
;; SERVER: 115.182.63.152#53(115.182.63.152)
;; WHEN: Thu Feb  9 17:44:51 2017

  

完事。

 

 

 

posted @ 2017-02-09 17:46  Quan7  阅读(1570)  评论(0编辑  收藏  举报