dns服务之bind浅谈

1、 安装需要的软件

[root@cl ~]# yum -y install bind*

# 开机启动
[root@cl ~]# systemctl enable named

2.配置bind

[root@cl ~]# vim /etc/named.conf

options {
        listen-on port 53 { any; };//将大括号内的内容改成any
        //listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };//将大括号内的内容改成any

3.添加正、反向解析域

3.1指向生效的配置文件

[root@cl ~]# vim /etc/named.rfc1912.zones 
//正向
zone "cljhfy.com" IN {
        type master;
        file "cljhfy.com.zone";
        allow-update { none; };
};
//反向
zone "163.168.192.in-addr.arpa" IN {
        type master;
        file "163.168.192.zone";
        allow-update { none; };
};
~                                                                          
~                            

3.2生成配置文件cljhfy.com.zone163.168.192.zone

[root@cl ~]# cd /var/named/

[root@cl named]# vim cljhfy.com.zone 

$TTL 1D
@  IN  SOA cljhfy.com.   admin.cljhfy.com. (
            0   ; serial  
            1D  ; refresh  
            1H  ; retry  
            1W  ; expire 
            3H )    ; minimum 
        NS  www.cljhfy.com.
        NS  ftp.cljhfy.com.
        A  127.0.0.1
        AAAA    ::1
        MX  10 mx.cljhfy.com.
ttl IN  A   192.168.163.128
www     IN  A   192.168.163.128
bbs IN  CNAME   www
mx  IN  A   192.168.163.128
ftp IN  A   192.168.163.128

[root@cl named]# vim 163.168.192.zone 

$TTL 1D
@       IN      SOA     cljhfy.com. admin.cljhfy.com. (
                         0
                         2H
                         10M
                         7D
                         1D )
        NS  ttl.cljhfy.com.
        A   127.0.0.1
        AAAA    ::1
128  IN      PTR     cljhfy.com.
128  IN      PTR     www.cljhfy.com.
128  IN      PTR     ftp.cljhfy.com.
128  IN      PTR     mx.cljhfy.com.
~                                           

//注意:一点要给权限
[root@cl named]# chown named.named cljhfy.com.zone 
[root@cl named]# chown named.named 163.168.192.zone 
[root@cl named]# chmod 755 cljhfy.com.zone 
[root@cl named]# chmod 755 163.168.192.zone 

//启动服务
[root@cl named]# systemctl start named

4.验证

//我是在另一台虚拟主机上实验

[root@cl129 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.163.128
//dns指向我设置好的IP
[root@cl129 ~]# nslookup 192.168.163.128
Server:		192.168.163.128
Address:	192.168.163.128#53

128.163.168.192.in-addr.arpa	name = ftp.cljhfy.com.
128.163.168.192.in-addr.arpa	name = cljhfy.com.
128.163.168.192.in-addr.arpa	name = mx.cljhfy.com.
128.163.168.192.in-addr.arpa	name = www.cljhfy.com.

[root@cl129 ~]# nslookup cljhfy.com
Server:		192.168.163.128
Address:	192.168.163.128#53

Name:	cljhfy.com
Address: 127.0.0.1

[root@cl129 ~]# nslookup ftp.cljhfy.com
Server:		192.168.163.128
Address:	192.168.163.128#53

Name:	ftp.cljhfy.com
Address: 192.168.163.128

[root@cl129 ~]# nslookup mx.cljhfy.com
Server:		192.168.163.128
Address:	192.168.163.128#53

Name:	mx.cljhfy.com
Address: 192.168.163.128

[root@cl129 ~]# nslookup www.cljhfy.com
Server:		192.168.163.128
Address:	192.168.163.128#53

Name:	www.cljhfy.com
Address: 192.168.163.128
//可以使用
原文地址:https://www.cnblogs.com/cljhfy/p/10803107.html