代码改变世界

Linux_DNS服务器

2015-12-06 16:59  云物互联  阅读(148)  评论(0编辑  收藏  举报

目录

DNS

DNS(Domain Name System,域名系统),在Internet上作为域名和IP地址映射的一个分布式数据库,能够使用户更直观、更方便的访问互联网(域名更便于记忆),而不用去记住能够被机器直接读取的IP地址。通过主机名,最终得到该主机名对应的IP地址的过程叫做域名解析(或主机名解析)。所以DNS服务器的功能既是:域名、IP映射,DNS协议运行在UDP协议之上,使用端口号53。
hostname到IPaddress映射有两种方式
1) 静态映射,每台设备上都配置主机到IP地址的映射(hosts),各设备独立维护自己的映射表,而且只供本设备使用;
2) 动态映射,建立一套域名解析系统(DNS),只在专门的DNS服务器上配置主机到IP地址的映射,网络上需要使用主机名通信的设备,首先需要到DNS服务器查询主机所对应的IP地址。
注意:在解析域名时,可以首先采用静态域名解析的方法,如果静态域名解析不成功,再采用动态域名解析的方法。可以将一些常用的域名放入静态域名解析表中,这样可以大大提高域名解析效率。

DNS Server

ServerSite

vim named.conf

    opeions {
    #    listen-on port 53 { 127.0.0.1; }; #Monitoring computer IP. General Comment.
    #    listen-on-v6 post 53 { ::1; };  #As above
        directory     "/etc/named";  #specify directory of store domain data coinfig file
        allow-query { any; };  #specify DNSServer response network segment, 'any' mean that all network segment.
    };
    zone "." IN {
        type hint;
        file "name.ca"; #record 13 root DNSServerIP
    }

Master DNS Server

step1.

yum install -y bind bind-chroot

step2. Edit the config file.
vim /etc/named.conf

        opeions {
        #    listen-on port 53 { 127.0.0.1; }; #monitoring computer IP, General comments.
        #    listen-on-v6 post 53 { ::1; }; #Idem
            directory     "/etc/named";  #specify directory of store domain data coinfig file
            allow-query { any; };   #specify DNSServer response network segment, any mean that all network segment.
        };

Forward Domain

vim /etc/name.rf1912.zone

            zone "fan.com" IN {
                type master;
                file "fan.com.zone";  #need create in the /var/named/fan.com.zone by manual
                allow-update { none; };
            };

Create zone config file:

cp -p /var/named/named.localhost /var/named/fan.com.zone

vim fan.com.zone

            @        NS    hostname.domain.   #one NS flag have to mapping one A flay
            hostname    A    192.168.1.144
            www        A    192.168.1.145
            ftp        A    192.168.1.146
            @        MX    10    mail.fan.com.

Reverse Resolution

vim /etc/name.rf1912.zone

            zone "1.168.192.in-addr.arpa" IN {
                type master;
                file "192.168.1.zone";
                allow-update { none; };
            };

Create zone config file:

cp -p /var/named/named.localhost /var/named/192.168.1.zone

vim 192.168.1.zone

            @        NS     hostname.domain.
            145        PTR  www.fan.com.
            146        PTR     ftp.fan.com.

step3. Start named service

service named restart

Slave DNS Server

step1. Edit Slave dns server’s named.conf file same as master server
step2. Edit the named.rf1912.zones

Forward lookup:

vim /etc/named.rf1912.zones

            zone "fan.com" IN {
                type slave;
                masters { MasterServerIP; };
                file "slaves/fan.com.zone.slave";  #in the /var/names/slaves/ directory
            };

Reverse lookup:

vim /etc/named.rf1912.zones

            zone "1.168.192.in-addr.arpa" IN {
                type slave;
                masters { MasterServerIP; };
                file "slaves/192.168.1.zone.slave";
            };

step3.

service named restart

Split DNS Server

step1. Edit the DNSServer main config file
vim /etc/named.conf

#Comment the root node and line of 'include "/etc/named.rf1912.zone"'
        #zone "." IN {
        #       type hint;
        #       file "named.ca";
        #};
        #include "/etc/named.rf1912.zone"

step2. Add view for public network and private network
Attention:First setting LAN then setting WAN .
vim /etc/named.conf
privateNetwork

        view "lan(viewName)" {
            match-clients { 1992.168.1.0/24; };   #specify split uplook domain networkSepment.
            zone "fan.com" IN {       #define the uplook domain
                type master;
                file "fan.com.zone"
                notify yes;     #allow tthe DNSServer update
                also-notify { 192.168.1.2; };    #assign to the dns slave server
            };
        };

publicNetwork

        view "wan" {
            match-clients { any; };
            zone "fan.com" IN {
                type master;
                file "fan.com.zone"
            };
        };

step3. Create the domain date file in directory with “/var/named” and restart named service.