DNS域名解析简单配置

DNS


DNS 是域名系统 (Domain Name System) 的缩写,它是由解析器和域名服务器组成的。域名服务器是指保存有该网络中所有主机的域名和对应IP地址,并具有将域名转换为IP地址功能的服务器。其中域名必须对应一个IP地址,而IP地址不一定有域名。要有两种形式:主服务器和服务器。DNS就是进行域名解析的服务器。

 

安装一般有两种方式一种是源代码安装,一种是RPM包安装

 

[root@wan-1 ~]# mount /dev/cdrom /mnt/  将光盘挂在到/mnt目录

mount: block device /dev/sr0 is write-protected, mounting read-only

 

使用yum安装需要搭建yum仓库,这里简单的搭建一个yum仓库

[root@wan-1 ~]# vi /etc/yum.repos.d/local.repo

[rhel-source]

name=user   

baseurl=file:///mnt  

enabled=1   

gpgcheck=0

 

[root@wan-1 ~]# yum install bind   使用yum安装bind

 

修改配置文件:

 

[root@wan-1 ~]# vi /etc/named.conf   这是主配置文件,修改的地方不多

 

options {

        listen-on port 53 { 192.168.1.10; };  改成自己的服务器地址

 #       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; };        允许所有人查询

recursion y allow-query   

 

主服务器----正向区:

[root@wan-1 ~]# vi /etc/named.rfc1912.zones  修改子配置文件

zone "benet.com" IN {       这个benet.com 域 是自己定义的

        type master;       类型是master  区域文件有这台服务器自己维护管理

        file "benet.com.zone";    定义的区域文件(名字随便取)

       allow-transfer { 192.168.1.20; };  添加这个命令即可  允许 从服务器(192.168.1.20地址服务器)来同步我


默认定义的文件存放在/var/named 下。默认工作目录就是在/var/named 下,如果是手工编译安装的则不同,是你指定的安装目录。

 

[root@wan-1 ~]# cd /var/named/

[root@wan-1 named]# ls -l

总用量 28

drwxrwx---. 2 named named 4096 8月  14 2013 data

drwxrwx---. 2 named named 4096 8月  14 2013 dynamic

-rw-r-----. 1 root  named 1892 2月  18 2008 named.ca

-rw-r-----. 1 root  named  152 1215 2009 named.empty

-rw-r-----. 1 root  named  152 6月  21 2007 named.localhost

-rw-r-----. 1 root  named  168 1215 2009 named.loopback

drwxrwx---. 2 named named 4096 8月  14 2013 slaves

[root@wan-1 named]# cp -p named.localhost benet.com.zone  named.localhost拷贝到benet.com.zone, -p 是保存原有的权限

 

[root@wan-1 named]# vi benet.com.zone

$TTL 1D   定义生存期限

@       IN SOA  @  admin (

                                        2017051101 ; serial   序列号

                                        1D      ; refresh    刷新时间

                                        1H      ; retry      重试时间

                                        1W      ; expire    过期时间

                                        3H )    ; minimum   无效缓存时间

        NS      @

        A       192.168.1.10  

IN MX   5       mail.benet.com.        这些配置随意配置,需要什么就配置什么,这里

mail IN A       192.168.1.10             只是做测试。在现网中根据需求在做。

www IN  A       192.168.1.11

ftp IN  A       192.168.1.12

smtp IN CNAME   mail

* IN    A       192.168.1.100              泛域名解析  如果你访问的地址不存在时,                         自动跳到  192.168.1.100 这个地址  [root@wan-1 named]# host 123.benet.com

                                      123.benet.com has address 192.168.1.100

 

[root@wan-1 named]# service named start         启动服务器

Generating /etc/rndc.key:                                  [确定]

启动 named:                                           [确定]

 

[root@wan-1 named]# netstat -tnl   tcp 53端口是否在运行。

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:58580               0.0.0.0:*                   LISTEN

tcp        0      0 192.168.1.10:53             0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LIST

 

[root@wan-1 named]# netstat -unl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

udp        0      0 0.0.0.0:111                 0.0.0.0:*                       

udp        0      0 0.0.0.0:881                 0.0.0.0:*                       

udp        0      0 0.0.0.0:631                 0.0.0.0:*                       

udp        0      0 192.168.184.129:123         0.0.0.0:*                                        

udp        0      0 192.168.1.10:53             0.0.0.0:*    

 

 

[root@wan-1 named]# echo "nameserver 192.168.1.10" > /etc/resolv.conf 

[root@wan-1 named]# cat /etc/resolv.conf

nameserver 192.168.1.10

 

使用host测试,如果没有host命令,需要安装bind-utils 这个包。

[root@wan-1 named]# host www.benet.com

www.benet.com has address 192.168.1.11

[root@wan-1 named]# host smtp.benet.com

smtp.benet.com is an alias for mail.benet.com.

mail.benet.com has address 192.168.1.10

[root@wan-1 named]#

[root@wan-1 named]# host mail.benet.com

mail.benet.com has address 192.168.1.10

 

反向区: 在互联网上一般不做反向区


[root@wan-1 named]# vi /etc/named.rfc1912.zones  

zone "1.168.192.in-addr.arpa" IN {

        type master;

        file "benet.com.local";

        allow-update { none; };

};

[root@wan-1 named]# cp -p benet.com.zone benet.com.local

[root@wan-1 named]# vi benet.com.local

$TTL 1D

@       IN SOA  benet.com.  admin.benet.com. (

                                        2017051101 ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      benet.com.

        A       192.168.1.10

10 IN PTR       mail.benet.com.

11 IN PTR       www.benet.com.

12 IN PTR       ftp.benet.com.

 

[root@wan-1 named]# service named reload

重新载入named:                                             [确定]

 

[root@wan-1 named]# host 192.168.1.10

10.1.168.192.in-addr.arpa domain name pointer mail.benet.com.

[root@wan-1 named]#

[root@wan-1 named]# host 192.168.1.11

11.1.168.192.in-addr.arpa domain name pointer www.benet.com.

[root@wan-1 named]# host 192.168.1.12

12.1.168.192.in-addr.arpa domain name pointer ftp.benet.com.

 

[root@wan-1 named]# service iptables stop  关闭防火墙(或者是调防火墙的规则)

iptables:将链设置为政策 ACCEPTfilter                    [确定]

iptables:清除防火墙规则:                                 [确定]

iptables:正在卸载模块:                                   [确定]

[root@wan-1 named]# setenforce 0   临时生效

 

 

 

从服务器:(IP地址:192.168.1.20)

 

[root@wan2 ~]# service iptables stop

iptables:将链设置为政策 ACCEPTfilter                    [确定]

iptables:清除防火墙规则:                                 [确定]

iptables:正在卸载模块:                                   [确定]

[root@wan2 ~]# setenforce 0

 

[root@wan2 ~]# mount /dev/cdrom /mnt/

mount: block device /dev/sr0 is write-protected, mounting read-only

 

[root@wan2 ~]# yum install bind

 

[root@wan2 ~]# vi /etc/named.conf

options {

        listen-on port 53 { 192.168.1.20; };    本服务器的地址

#       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; };   允许所有人

        recursion yes;

 

[root@wan2 named]# vi /etc/named.rfc1912.zones

 

zone "benet.com" IN {

        type slave;     类型是从(slave

        masters { 192.168.1.10; };      定义主服务器是:

        file "slaves/benet.com.zone";   从主服务器下载的文件保存在slaves

};

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

[root@wan2 named]# ls

data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves(默认就存在的)

 

[root@wan2 named]# service named start

Generating /etc/rndc.key:                                  [确定]

启动 named:                                               [确定]

 

[root@wan2 named]# ls slaves/  

benet.com.zone

 

[root@wan2 named]# echo "nameserver 192.168.1.20" > /etc/resolv.conf

 

[root@wan2 named]# host www.benet.com

www.benet.com has address 192.168.1.11  

 

[root@wan2 named]# host ftp.benet.com

ftp.benet.com has address 192.168.1.12

 

也可以通过日志查看


你可能感兴趣的:(Linux)