zoukankan      html  css  js  c++  java
  • CentOS7 安装配置DNS服务器

    一、安装

    yum install bind

    二、配置

    1. /etc/named.conf

     1 //
     2 // named.conf
     3 //
     4 // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
     5 // server as a caching only nameserver (as a localhost DNS resolver only).
     6 //
     7 // See /usr/share/doc/bind*/sample/ for example named configuration files.
     8 //
     9 // See the BIND Administrator's Reference Manual (ARM) for details about the
    10 // configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
    11 
    12 options {
    13 listen-on port 53 { any; };
    14 listen-on-v6 port 53 { ::1; };
    15 directory "/var/named";
    16 dump-file "/var/named/data/cache_dump.db";
    17 statistics-file "/var/named/data/named_stats.txt";
    18 memstatistics-file "/var/named/data/named_mem_stats.txt";
    19 allow-query { 0.0.0.0/0; };
    20 
    21 /* 
    22 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
    23 - If you are building a RECURSIVE (caching) DNS server, you need to enable 
    24 recursion. 
    25 - If your recursive DNS server has a public IP address, you MUST enable access 
    26 control to limit queries to your legitimate users. Failing to do so will
    27 cause your server to become part of large scale DNS amplification 
    28 attacks. Implementing BCP38 within your network would greatly
    29 reduce such attack surface 
    30 */
    31 recursion yes;
    32 
    33 dnssec-enable yes;
    34 dnssec-validation yes;
    35 
    36 /* Path to ISC DLV key */
    37 bindkeys-file "/etc/named.iscdlv.key";
    38 
    39 managed-keys-directory "/var/named/dynamic";
    40 
    41 pid-file "/run/named/named.pid";
    42 session-keyfile "/run/named/session.key";
    43 };
    44 
    45 logging {
    46 channel default_debug {
    47 file "data/named.run";
    48 severity dynamic;
    49 };
    50 };
    51 
    52 zone "." IN {
    53 type hint;
    54 file "named.ca";
    55 };
    56 
    57 include "/etc/named.rfc1912.zones";
    58 include "/etc/named.root.key";

    配置说明

    a. 第13行:启动监听地址,默认启动在localhost上,需要修改为监听所有的地址。修改为{ any; }
    b. 第19行:允许查询的地址和端口,默认是本地查询,需要修改为允许任意地址。修改为 { 0.0.0.0/0; }
    c. 第57行,引出了另外一个配置/etc/named.rfc1912.zones
    d. 第15行,引出了一个域名信息配置文件目录/var/named

    2. /etc/named.rfc1912.zones

     1 // named.rfc1912.zones:
     2 //
     3 // Provided by Red Hat caching-nameserver package 
     4 //
     5 // ISC BIND named zone configuration for zones recommended by
     6 // RFC 1912 section 4.1 : localhost TLDs and address zones
     7 // and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
     8 // (c)2007 R W Franks
     9 // 
    10 // See /usr/share/doc/bind*/sample/ for example named configuration files.
    11 //
    12 
    13 zone "localhost.localdomain" IN {
    14 type master;
    15 file "named.localhost";
    16 allow-update { none; };
    17 };
    18 
    19 zone "localhost" IN {
    20 type master;
    21 file "named.localhost";
    22 allow-update { none; };
    23 };
    24 
    25 zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
    26 type master;
    27 file "named.loopback";
    28 allow-update { none; };
    29 };
    30 
    31 zone "1.0.0.127.in-addr.arpa" IN {
    32 type master;
    33 file "named.loopback";
    34 allow-update { none; };
    35 };
    36 
    37 zone "0.in-addr.arpa" IN {
    38 type master;
    39 file "named.empty";
    40 allow-update { none; };
    41 };
    42 
    43 //vvtest.com 正向配置
    44 zone "vvtest.com" IN {
    45 type master;
    46 file "named.vvtest.com";
    47 allow-update { none; };
    48 };
    49 //vvtest.com 逆向配置
    50 zone "25.168.192.in-addr.arpa" IN {
    51 type master;
    52 file "192.168.25.arpa";
    53 allow-update { none; };
    54 };

    配置说明:

    a. 第43~48行,添加域名的正向配置
    b. 第50~54行,添加域名的逆向配置
    c. 第46行,引出了配置文件named.vvtest.com
    d. 第52行,引出了配置文件192.168.25.arpa
    e. c和d中的配置文件目录为/var/named(由named.conf配置的)

    3. /var/named/named.vvtest.com

     1 $TTL 1D
     2 @    IN SOA    vvtest.com. rname.invalid. (
     3 0    ; serial
     4 1D    ; refresh
     5 1H    ; retry
     6 1W    ; expire
     7 3H )    ; minimum
     8 NS    @
     9 A    127.0.0.1
    10 AAAA    ::1
    11 www IN A 192.168.25.128
    12 mail IN A 192.168.25.128

    配置说明:

    a. 第2行,是【vvtest.com.】,最后又一个【.】
    b. 第11行,配置的是域名www.vvtest.com,服务器地址是192.168.25.128
    c. 第12行,配置的是域名mail.vvtest.com,服务器地址是192.168.25.128

    4. /var/named/192.168.25.arpa

     1 $TTL 1D
     2 @ IN SOA vvtest.com. rname.invalid. (
     3 0 ; serial
     4 1D ; refresh
     5 1H ; retry
     6 1W ; expire
     7 3H ) ; minimum
     8 NS @
     9 AAAA ::1
    10 128 PTR www.vvtest.com.

    三、测试

    1. 启动systemctl start named或者service named start
    2. 配置测试机的DNS1服务器地址为192.168.25.128
    3. 从测试机上执行ping www.vvtest.com,如果有收到ping包,恭喜你。

    附、一个个人遇到的纠结无比的问题

    1. 服务器启动,无法Ping通。
    2. 花了大量的时间在反复检查所有的配置文件及选项,确保每一个字符都是一样的。
    3. 看了日志才发现是读取配置文件的时候,permission denied。
    4. chown -R root.named 权限不对的文件(named.vvtest.com和192.168.25.arpa)
    5. 论日志的重要性!没有日志,就是抓虾~
  • 相关阅读:
    Spring-Context之四:Spring容器及bean的定义
    Spring-Context之三:使用XML和Groovy DSL配置Bean
    Spring-Context之二:使用Spring提供的测试框架进行测试
    Spring-Context之一:一个简单的例子
    ActiveMQ第五弹:增加ReDelivery功能
    百度云+ KeePass 网络同步你的密码
    git生成秘钥之后同步到服务器
    谷歌chrome浏览器和火狐firefox浏览器自带http抓包工具和请求模拟插件
    ltnmp
    CentOS 下安装xdebug
  • 原文地址:https://www.cnblogs.com/yoyotl/p/7364754.html
Copyright © 2011-2022 走看看