配置DNS大概步骤:
1. 配置IP地址,DNS指向自己。
2. 关闭防火墙,关闭selinux。
3. 挂载并安装bind包
4. 复制配置文件
5. 配置named.conf主要文件
6. 配置正反向文件
7. 配置正向文件
8. 配置反向文件
9. 重启服务
10. 测试服务
正文
1. 配置IP地址,DNS指向自己。
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
配置文件:
DEVICE=eth0
HWADDR=00:0c:29:95:7d:8e
TYPE=Ethernet
UUID=de320e6a-e587-4419-bd9e-17d7c7833f9f
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.10.10
NETMASK=255.255.255.0
IPV6INIT=no
USERCTL=no
DNS1=192.168.10.10
:wq
保存并退出
2. 关闭防火墙,关闭selinux。
[[email protected] ~]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则:[确定]
iptables:正在卸载模块:[确定]
[[email protected] ~]# setenforce 0
[[email protected] ~]#
3. 挂载并安装bind包
[[email protected] ~]# mkdir /test
[[email protected] ~]# mount /dev/sr0 /test
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cd /test/Packages/
[[email protected] Packages]# rpm -ivh bind-9.8.2-0.17.rc1.el6_4.6.i686.rpm bind-chroot-9.8.2-0.17.rc1.el6_4.6.i686.rpm cachefilesd-0.10.2-1.el6.i686.rpm
warning: bind-9.8.2-0.17.rc1.el6_4.6.i686.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:bind ########################################### [ 33%]
2:bind-chroot ########################################### [ 67%]
3:cachefilesd ########################################### [100%]
[[email protected] Packages]#
主要三个配置文件
bind-9.8.2-0.17.rc1.el6_4.6.i686.rpm
bind-chroot-9.8.2-0.17.rc1.el6_4.6.i686.rpm
cachefilesd-0.10.2-1.el6.i686.rpm
4. 复制配置文件
[[email protected] Packages]# cp -rp /usr/share/doc/bind-9.8.2/sample/* /var/named/chroot/
5. 配置named.conf主要文件
[[email protected] ~]# cd /var/named/chroot/etc/
[[email protected] etc]# vim named.conf
用“set nu”这个命令来设置行号
然后把110行后面的文字全部删除
options
{
directory "/var/named"; // "Working" directory
dump-file "data/cache_dump.db";
statistics-file "data/named_stats.txt";
memstatistics-file "data/named_mem_stats.txt";
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
allow-query { any; }; //localhost改成any
allow-query-cache { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto; //把所有注释都删除
};
Logging //这片配置文件是修改删除剩下的重要配置
{
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view "localhost_resolver"
{
match-clients { any; }; //标记红色是主要要改的
recursion yes;
zone "." IN {
type hint;
file "/var/named/named.ca";
};
6. 配置正反向文件
[[email protected] etc]# vim named.rfc1912.zones
zone "test.com" IN {
type master;
file "named.localhost";
allow-update { none; };
}; //留下这两个配置,其他全删
zone "10.168.192.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
7. 配置正向文件
[[email protected] etc]# cd /var/named/chroot/var/named/
[[email protected] named]# vim named.localhost
$TTL 1D
@ IN SOA dns.test.com. root. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS dns.test.com. //不要忘记了小数点
dns IN A 192.168.10.10
www IN A 192.168.10.10
ftp IN A 192.168.10.10
保存退出
8. 配置反向文件
[[email protected] named]# vim named.loopback
$TTL 1D
@ IN SOA dns.test.com. root. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS dns.test.com.
10 IN PTR dns.test.com.
10 IN PTR www.test.com.
10 IN PTR ftp.test.com.
9. 重启服务
[[email protected] named]# service network restart
正在关闭接口 eth0: 设备状态:3 (断开连接)
[确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: 活跃连接状态:激活的
活跃连接路径:/org/freedesktop/NetworkManager/ActiveConnection/2
[确定]
[[email protected] named]# service named restart
停止 named:[确定]
Generating /etc/rndc.key:[确定]
启动 named:[确定]
[[email protected] named]#
10. 测试
[[email protected] named]# nslookup 192.168.10.10
Server: 192.168.10.10
Address: 192.168.10.10#53
10.10.168.192.in-addr.arpa name = dns.test.com.
10.10.168.192.in-addr.arpa name = www.test.com.
10.10.168.192.in-addr.arpa name = ftp.test.com.
解析出来就证明咱们成功了