上次我们主要讲了http服务器的基本搭建方法这次我们主要弄一下DNS服务器:系统依旧是我们CentOS 6.5
首先我们要挂在yum源,但是上篇文章已经详细讲过了,这里不过多赘述。传送门:技能大赛之HTTP服务器搭建
我们直接yum安装就可以了,在Linux系统提供DNS服务的软件名字是bind,服务的名字是named(就挺离谱)
这里我们直接用指令:yum install bing* -y
来安装让软件就可以了。
bind有几个配置文件:vi /etc/named.conf
vi /etc/named.rfc1912.zones
这两个比较重要,我们一个一个来说
vi /etc/named.conf
//
// 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 { any; };
listen-on-v6 port 53 { any; };
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 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”;
};
logging {
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};
zone “.” IN {
type hint;
file “named.ca”;
};
include “/etc/named.rfc1912.zones”;
include “/etc/named.root.key”;
我们要改的地方我已经写咋上面了
三个any :)
接下来:
vi /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone “localhost.localdomain” IN {
type master;
file “named.localhost”;
allow-update { none; };
};
zone “localhost” IN {
type master;
file “named.localhost”;
allow-update { none; };
};
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 {
type master;
file “named.loopback”;
allow-update { none; };
};
zone “1.0.0.127.in-addr.arpa” IN {
type master;
file “named.loopback”;
allow-update { none; };
};
zone “0.in-addr.arpa” IN {
type master;
file “named.empty”;
allow-update { none; };
};
//这些我们用到的很少所以直接留两个就ok了(需要留的已经加粗)
//修改过的文件:
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone “localhost.localdomain” IN {
type master;
file “named.localhost”;
allow-update { none; };
};
zone “1.0.0.127.in-addr.arpa” IN {
type master;
file “named.loopback”;
allow-update { none; };
};
留住这两个,然后第一组的 localhost.localdomain 改成你的顶级域(正向查找)
把文件那行:named.localhost 改成你的配置文件
第二组
1.0.0.127.in-addr.arpa 改成 顶级反向查找域
把文件那行:named.loopback 改成你的配置文件
假设: 你的顶级域正向查找域是:skillchina.com ,反向查找是:40.16.172
你的配置文件应为:
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone “skillchina.com” IN {
type master;
file “named.skillchina.com.zone”;
allow-update { none; };
};
zone “40.16.172.in-addr.arpa” IN {
type master;
file “named.40.16.172.in-addr.arpa”;
allow-update { none; };
};
设置完毕之后我们应该编辑配置文件
配置文件存放目录:/var/named/
我们继续用刚才的假设:
我们应该copy一份配置文件:
cp -p named.localhost named.skillchina.com.zone
cp -p named.loopback named.40.16.172.in-addr.arpa
【-p 的含义是:除复制文件的内容外,还把修改时间和访问权限也复制到新文件中。】
这时候我们在设立一个假设:
您的DNS 服务器IP地址为:172.16.40.4 主机名为:dns
您的DNS服务器需要将
www.skillchina.com 解析到 172.16.40.3
那么您的named.skillchina.com.zone文件内容应为:
$TTL 1D
@ IN SOA skillchina.com. rname.skillchina.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
www A 172.16.40.3
您的named.40.16.172.in-addr.arpa文件内容应为:
$TTL 1D
@ IN SOA skillchina.com. rname.skillchina.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
PTR localhost.
3 PTR www.skillchina.com.
当您把文件编辑完毕,我们需要重启一下bing的进程:/etc/init.d/named restart
千万别忘了防火墙,如果您想对外网服务的话.
我用Windows测试的:
首先打开网络设置,然后属性:
然后输入Dns的ip(必须在同一个局域网内)
然后我们打开cmd(命令提示符),输入: ping www.skillchina.com
如果和图片一样说明您已经设置成功了,如果没有请您重新检查配置文件和您的防火墙
暂无评论内容