最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
centos7 搭建bind-chroot DNS的步骤详解
时间:2022-06-30 21:00:41 编辑:袖梨 来源:一聚教程网
一.bind-chroot介绍
DNS是一种将域名解析为IP地址的服务.如:www.turbolinux.com.cn通过DNS解析,可以
得到210.77.38.126.
bind是linux的DNS服务器程序.bind-chroot是bind的一个功能,使bind可以在一个
chroot的模式下运行.也就是说,bind运行时的/(根)目录,并不是系统真正的/(根)目录,只是
系统中的一个子目录而已.这样做的目的是为了提高安全性.因为在chroot的模式下,bind可以
访问的范围仅限于这个子目录的范围里,无法进一步提升,进入到系统的其他目录中.
二.bind-chroot DNS的搭建及配置
1、安装Bind Chroot DNS 服务器
[root@centos7 ~]# yum install bind-chroot bind -y
2、拷贝bind相关文件,准备bind chroot 环境
[root@centos7 ~]# cp -R /usr/share/doc/bind-*/sample/var/named/* /var/named/chroot/var/named/
3、在bind chroot 的目录中创建相关文件
[root@centos7 ~]# touch /var/named/chroot/var/named/data/cache_dump.db
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named_stats.txt
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named_mem_stats.txt
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named.run
[root@centos7 ~]# mkdir /var/named/chroot/var/named/dynamic
[root@centos7 ~]# touch /var/named/chroot/var/named/dynamic/managed-keys.bind
4、 将 Bind 锁定文件设置为可写
[root@centos7 ~]# chmod -R 777 /var/named/chroot/var/named/data
[root@centos7 ~]# chmod -R 777 /var/named/chroot/var/named/dynamic
5、 将 /etc/named.conf 拷贝到 bind chroot目录
[root@centos7 ~]# cp -p /etc/named.conf /var/named/chroot/etc/named.conf
6、 在/etc/named.conf中对 bind 进行配置。
在 named.conf 文件尾添加 example.local 域信息, 创建转发域(Forward Zone)与反向域(Reverse Zone)(LCTT 译注:这里example.local 并非一个真实有效的互联网域名,而是通常用于本地测试的一个域名;如果你需要做权威 DNS 解析,你可以将你拥有的域名如这里所示配置解析。):
[root@centos7 ~]# vi /var/named/chroot/etc/named.conf
..
..
zone "example.local" {
type master;
file "example.local.zone";
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.zone";
};
..
..
named.conf 完全配置如下:
//
// named.conf
//
// 由Red Hat提供,将 ISC BIND named(8) DNS服务器
// 配置为暂存域名服务器 (用来做本地DNS解析).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { any; };
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(递归) 功能。
- 如果你要建立一个 递归 DNS 服务器, 那么需要开启recursion 功能。
- 如果你的递归DNS服务器有公网IP地址, 你必须开启访问控制功能,
只有那些合法用户才可以发询问. 如果不这么做的话,那么你的服
服务就会受到DNS 放大攻击。实现BCP38将有效抵御这类攻击。
*/
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "example.local" {
type master;
file "example.local.zone";
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.zone";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
7、 为 example.local 域名创建转发域与反向域文件
a)创建转发域
[root@centos7 ~]# vi /var/named/chroot/var/named/example.local.zone
添加如下内容并保存:
;
; Addresses and other host information.
;
$TTL 86400
@ IN SOA example.local. hostmaster.example.local. (
2014101901 ; Serial
43200 ; Refresh
3600 ; Retry
3600000 ; Expire
2592000 ) ; Minimum
; Define the nameservers and the mail servers
IN NS ns1.example.local.
IN NS ns2.example.local.
IN A 192.168.0.70
IN MX 10 mx.example.local.
centos7 IN A 192.168.0.70
mx IN A 192.168.0.50
ns1 IN A 192.168.0.70
ns2 IN A 192.168.0.80
b)创建反向域
[root@centos7 ~]# vi /var/named/chroot/var/named/192.168.0.zone
;
; Addresses and other host information.
;
$TTL 86400
@ IN SOA example.local. hostmaster.example.local. (
2014101901 ; Serial
43200 ; Refresh
3600 ; Retry
3600000 ; Expire
2592000 ) ; Minimum
0.168.192.in-addr.arpa. IN NS centos7.example.local.
70.0.168.192.in-addr.arpa. IN PTR mx.example.local.
70.0.168.192.in-addr.arpa. IN PTR ns1.example.local.
80.0.168.192.in-addr.arpa. IN PTR ns2.example.local.
8、开机自启动 bind-chroot 服务
[root@centos7 ~]# /usr/libexec/setup-named-chroot.sh /var/named/chroot on
[root@centos7 ~]# systemctl stop named
[root@centos7 ~]# systemctl disable named
[root@centos7 ~]# systemctl start named-chroot
[root@centos7 ~]# systemctl enable named-chroot
ln -s '/usr/lib/systemd/system/named-chroot.service' '/etc/systemd/system/multi-user.target.wants/named-chroot.service'
安装方法二,rpm包安装
二.bind-chroot的安装
1.rpm包
在GTES10,10.5,11中,都已包含有bind-chroot包,可以直接安装相应rpm包.
# rpm -ivh bind-chroot.xxx.rpm
2.源码包安装
源码下载地址:
http://www.isc.org/index.pl
以bind-9.4.1-P1版本为例.
# tar zxvf bind-9.4.1-P1.tar.gz
# cd bind-9.4.1-P1
# ./configure
# make
# make install
三.bind-chroot的使用
1.rpm包方式
在GTES 11上,如果已经安装了bind-chroot的包,则bind的默认启动方式就是chroot方式.
# /etc/init.d/named start
# ps -ef | grep named
named 2090 2613 1 0 07:49 ? 00:00:00 /usr/sbin/named -u named -t /var/named/chroot
2.源码包方式
使用源码包安装完成bind后,使用下面步骤进行配置:
建立named用户
# useradd named
建立chroot后所需的目录和文件
# mkdir -p /var/named/chroot/etc
# mkdir /var/named/chroot/dev
# mkdir -p /var/named/chroot/var/named/data
# mkdir -p /var/named/chroot/var/run
# cp /var/named/* /var/named/chroot/var/named/
# cp /etc/rndc.key /var/named/chroot/etc/
建立chroot后,所需的设备文件
# cd /var/named/chroot/dev
# mknod null c 1 3
# mknod random c 1 8
# mknod zero c 1 5
# chmod 666 null random
# chown -R named.named /var/named /var/run
建立named.conf配置文件
# vi /var/named/chroot/etc/named.conf
options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
// query-source address * port 53;
};
controls {
inet 127.0.0.1 allow { 127.0.0.1; } keys { rndckey; };
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localdomain" IN {
type master;
file "localdomain.zone";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { 127.0.0.1 ; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "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 {
type master;
file "named.ip6.local";
allow-update { none; };
};
zone "255.in-addr.arpa" IN {
type master;
file "named.broadcast";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.zero";
allow-update { none; };
};
include "/etc/rndc.key";
启动bind
# /usr/local/sbin/named -u named -t /var/named/chroot
# ps -ef | grep named
named 15739 1 0 08:27 ? 00:00:00 /usr/local/sbin/named -u named -t /var/named/chroot
现在bind已经运行在chroot模式下了.