DNS服务器部署

2018/12/05 posted in  Linux

简单DNS服务器部署

  1. 安装dnsmasq

    sudo apt-get install dnsmasq
    
  2. 添加域名解析记录

    sudo vim /etc/hosts
    ##加入你要解析的域名和ip
    192.168.1.10 example.xxx.com
    192.168.1.11 example2.xxx.com
  3. 设置静态IP以及上级DNS服务器

    sudo vim /etc/network/interface
    ##加入下面的代码,其中enp0s3为网卡名称
    auto enp0s3
    iface enp0s3 inet static
    address 192.168.2.222
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameserver 114.114.114.114
  4. 启动服务

    sudo /etc/init.d/dnsmasq start
    

智能DNS解析部署,根据源IP的不同网段解析不同的IP地址

  1. 安装bind9

    sudo apt-get install bind9
    
  2. 修改配置文件

    sudo vim /etc/bind/named.conf
    

    增加如下内容,声明两个视图,view_2,view_11

    include "/etc/bind/name.2.conf";
    view "View_2" {
    match-clients {"2";};
    zone "1234tv.lan" IN {
    type master;
    file "1234tv.lan-2.zone";
    allow-update {none;};
    };
    };
    include "/etc/bind/name.111.conf";
    view "View_111" {
    match-clients {"111";};
    zone "1234tv.lan" IN {
    type master;
    file "1234tv.lan-111.zone";
    allow-update {none;};
    };
    };

    具体的视图文件如下:

    name.2.conf

    acl "2" {
        192.168.2.0/24;
    };

    name.111.conf

    acl "111" {
        192.168.111.0/24;
    };

    DNS解析文件文件:

    1234tv.lan-2.zone

    $TTL    604800
    @       IN      SOA     1234tv.lan. root.1234tv.lan. (
    2 ; Serial
    604800 ; Refresh
    86400 ; Retry
    2419200 ; Expire
    604800 ) ; Negative Cache TTL
    ;
    @ IN NS 1234tv.lan.
    @ IN A 192.168.2.222
    gitlab IN A 192.168.2.84

    1234tv.lan-111.zone

    $TTL    604800
    @       IN      SOA     1234tv.lan. root.1234tv.lan. (
    2 ; Serial
    604800 ; Refresh
    86400 ; Retry
    2419200 ; Expire
    604800 ) ; Negative Cache TTL
    ;
    @ IN NS 1234tv.lan.
    @ IN A 192.168.111.222
    gitlab IN A 192.168.111.84