在CentOS 6上设置BIND DNS服务器

时间:2020-03-21 11:42:28  来源:igfitidea点击:

使用VirtualBox设置Linux测试环境环境的第2部分。

检查此教程 文章以获取更多信息。

BIND是开源软件,可为Internet实现域名系统(DNS)协议。
名称BIND代表“伯克利Internet名称域”。

软件

本文使用的软件:

  • CentOS 6
  • Bind 9.8

在我们开始之前

我们将要建立一个通用的DNS服务器,该服务器:

  • 充当两个内部区域的主节点,以及
  • 充当所有其他请求的缓存服务器。

BIND服务器的信息:

  • 主机名:spacewalk,
  • IP:10.8.8.2,
  • 局域网:10.8.8.0/24.

将设置两个内部DNS区域:

  • hl.local –前向区域,可将域名转换为IP地址,
  • 8.8.10 –反向区域,可将IP地址转换为域名。

在我们的案例中,hl.local域代表“测试环境”。

DNS服务器将通过以下方式保护:

  • 以较少的权限运行BIND,
  • 将查询限制为仅LAN,
  • 限制区域仅传输到局域网,
  • 隐藏公开的BIND版本号和主机名,
  • 将iptables配置为仅允许从LAN访问TCP/UDP端口53,

安装

安装BIND软件包:

# yum install -y bind bind-utils

在启动时启动BIND:

# chkconfig named on

更新“ /etc/resolv.conf”文件:

search hl.local
nameserver 127.0.0.1
nameserver 10.8.8.2

我们将peerdns设置为“ no”。

配置

创建一个日志目录:

# mkdir /var/log/named
# chown named:named /var/log/named

/etc/named.conf

提供了一些注释。
请查看BIND v9.8文档以获取更多信息。

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
# Limiting access to local networks only
acl "clients" {
        127.0.0.0/8;
        10.8.8.0/24;
};
options {
	listen-on port 53 { any; };
	listen-on-v6 { none; };
	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";
	# Maximum number of simultaneous client TCP connections to accept
	tcp-clients 50;
	# Disable built-in server information zones
	version none;
	hostname none;
	server-id none;
	# Attempt to do all the work required to answer the query
	recursion yes;
	recursive-clients 100;
        allow-recursion { clients; };
        allow-query { clients; };
	# Only LAN users are allowed to receive zone transfers from the server
        allow-transfer { clients; };
	auth-nxdomain no;
        notify no;
	dnssec-enable yes;
	dnssec-validation auto;
	dnssec-lookaside auto;
	# Path to ISC DLV key
	bindkeys-file "/etc/named.iscdlv.key";
	managed-keys-directory "/var/named/dynamic";
};
# Specifications of what to log, and where the log messages are sent
logging {
        channel "common_log" {
                file "/var/log/named/named.log" versions 10 size 5m;
		severity error;
                print-category yes;
                print-severity yes;
                print-time yes;
        };
        category default { "common_log"; };
        category general { "common_log"; };
        category queries { "common_log"; };
	category client { "common_log"; };
	category security { "common_log"; };
	category query-errors { "common_log"; };
	category lame-servers { null; };
};
# Internal zone definitions
zone "hl.local" {
        type master;
        file "/etc/named/db.hl.local";
        allow-update { none; };
};
zone "8.8.10.in-addr.arpa" {
        type master;
        file "/etc/named/db.8.8.10";
        allow-update { none; };
};

/etc/named/db.hl.local

$TTL    86400
@               IN      SOA     localhost. root.localhost. (
                                    2014101000    ; Serial
                                    86400         ; Refresh
                                    3600          ; Retry
                                    604800        ; Expire
                                    7200 )        ; Negative Cache TTL
@               IN      NS      localhost.
@		IN	A	10.8.8.2
dhcp            IN      A       10.8.8.2
dns             IN      A       10.8.8.2
ntp		IN	A	10.8.8.2
puppet          IN      A       10.8.8.2
smtp            IN      A       10.8.8.2
spacewalk       IN      A       10.8.8.2

/etc/named/db.8.8.10

$TTL    86400
@               IN      SOA     localhost. root.localhost. (
                                    2014101000    ; Serial
                                    86400         ; Refresh
                                    3600          ; Retry
                                    604800        ; Expire
                                    7200 )        ; Negative Cache TTL
@               IN      NS      localhost.
2		IN	PTR	dhcp.hl.local.	    ;10.8.8.2
2		IN	PTR	dns.hl.local.	    ;10.8.8.2
2		IN	PTR	ntp.hl.local.	    ;10.8.8.2
2		IN	PTR	puppet.hl.local.    ;10.8.8.2
2		IN	PTR	smtp.hl.local.	    ;10.8.8.2
2		IN	PTR	spacewalk.hl.local. ;10.8.8.2

验证BIND配置

# named-checkconf /etc/named.conf

如果未出现任何错误,请重新启动服务:

# /etc/init.d/named restart

在BIND服务器上配置iptables以允许LAN访问

iptables将通过Puppet进行配置。
以下几行仅用于:

# iptables -A INPUT -s 10.8.8.0/24 -p tcp -m state --state NEW --dport 53 -j ACCEPT
# iptables -A INPUT -s 10.8.8.0/24 -p udp -m state --state NEW --dport 53 -j ACCEPT

故障排除

检查日志:

# tail /var/log/messages
# tail /var/log/named/named.log