######################################################################
配置dns
yum install -y bind
vim /etc/named.conf
步骤1、listen-on port 53 { 127.0.0.1; };
地址改为dns 服务器的地址
步骤2、 allow-query { localhost; };
地址改为允许访问的IP段 例如 192.168.122.0/24
步骤3、添加域 可以参考 /etc/named.rfc1912.zones
注意反向解析域名格式固定不可以随便写如下
zone "1.0.0.127.in-addr.arpa" IN
zone "122.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.rev";
};
zone "sh.com" IN {
type master;
file "sh.com.hosts";
};
奉上我的配置
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { 192.168.122.20; };
//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 { 192.168.122.0/24; }; //设置允许查询的主机
recursion yes;//是否启用递归式DNS服务器
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";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "sh.com" IN {
type master;
file "sh.com.hosts";
};
zone "122.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.rev";
};
key "rndc-key" {
algorithm hmac-md5;
secret "xgxzJPDFyVGEFnT44Rw3OA==";
};
controls { 192.168.0.rev
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
在奉上我的域文件
sh.com.hosts
$TTL 38400
@ IN SOA rhel.sh.com. root.sh.com.(
1268360234
10800
3600
604800
38400 )
@ IN NS rhel.sh.com.
rhel IN A 192.168.122.20
linux IN A 192.168.122.50
www IN CNAME rhel.sh.com.
mail IN CNAME rhel.sh.com.
ftp IN CNAME rhel.sh.com.
@ IN MX 10 mail.sh.com.
192.168.0.rev
$TTL 1D
@ IN SOA rhel.sh.com. root.sh.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ NS rhel.sh.com.
20 PTR rhel.sh.com.
50 PTR linux.sh.com.
ps:顺带搭建辅助dns服务器步骤和前两步骤相同添加域的格式如下所示:
zone "sh.com" IN {
type slave;
masters{192.168.122.20;};
file "slaves/sh.com.hosts";
};\\会在/var/named/slaves 同步master自动生成所添加相应域的文件。
完全转发dns服务器 在named.conf里面添加
fowarders{IP;};
forward only;
条件转发DNS服务器针对域
转发某个特定域到某个DNS
zone"xx.com"IN{
type forward;
fowarders{IP;};
};
区域委派可以减轻DNS负但 但须新的主机 采用虚拟子域可以简单处理
只用在/var/named/ 地下的域文件
例如$ORIGIN sh.com.
$ORIGIN xx.sh.com.
IN NS leaf.xx.sh.com.
leaf IN A 192.168.122.20
编辑 /etc/resolve.conf 添加父DNS 服务器就可以解析到
缓存服务器 在named.conf 中添加 datasize 大小例如100M;就可以
直接域名sh.com. IN A 192.168.122.2
泛域名解析*.sh.com. IN A 192.168.122.2
访问控制named.conf中添加 allow-query{访问控制列表名称}
acl 访问控制列表名称{! 192.168.122.1:
192.168.122.0/24;
};
允许该网段除了1的dns访问
bind-chroot 是相对安全的dns
#######################################################################
如果开启key
注意。
key "rndc-key" {
algorithm hmac-md5;
secret "xgxzJPDFyVGEFnT44Rw3OA==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
/etc/init.d/named 出现两行错误的时候加入上面在/etc/named.conf
可以cat /etc/rndc.conf
使用dig命令首先安装bind-utils
dig 域名
dig -x ip
dig -t 类型
1.在启动DNS时出现Generating /etc/rndc.key:卡在这里了
[root@RedHat named]# /etc/init.d/named restart
Stopping named: [ OK ]
Generating /etc/rndc.key:
^C
[root@redhat named]#
解决方法:
[root@redhat named]# rndc-confgen -r /dev/urandom -a
wrote key file "/etc/rndc.key"
[root@redhat named]# /etc/init.d/named restart
Stopping named: [ OK ]
Starting named: [ OK ]
linux