Linux centos DNS服务器搭建详解(包含5.6版本)

DNS在日常网络应用中无处不在,当你打开新浪、百度、人人时,其实你已经在使用DNS了。

首先,我们来了解下什么是DNS:

域名系统英文Domain Name System,缩写DNS)是因特网的一项服务。它作为将域名IP地址相互映射的一个分布式数据库,能够使人更方便的访问互联网。DNS 使用TCPUDP端口53。

——摘自维基百科

DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串。

——摘自百度百科

简单点来说,DNS所做的事就是当你在浏览器地址栏上访问诸如www.baidu.com这类域名时将其映射为对应的ip地址,从而通过ip对相应服务器发送请求指令。


好了,下面进入正题,博主将手把手带大家搭建一个属于自己的DNS服务器。

前提条件:一台有固定公网IP的装有Linux系统的机器。

CentOS 6:

1.安装bind

bind是一款开放源码的DNS服务器软件,可使用yum -y install bind 安装。

2.配置主配置文件/etc/named.conf

在原有named.conf文件基础上修改如下:

listen-on port 53 {any; };

allow-query     { any; };

//listen-on-v6 port 53 { ::1; };

3.配置/etc/named.rfc1912.zones

配置这步之前,我们要了解/etc/named.rfc1912.zones与第二步的/etc/named.conf关系。

细心的你不难发现,在named.conf下面有一行:

include "/etc/named.rfc1912.zones";

include为引用,即/etc/named.conf文件中用到了/etc/named.conf文件,其实也就相当于一个比较大的文件被按照各自特有功能分割开来,而又由引用互相紧密联系在一起,这样做的好处显而易见,在查找、修改相应功能时会清晰、快速不少。

博主named.conf文件中引用如下:

include "/etc/named.rfc1912.zones";

如果你的named.conf中没有找到这行,反而找到如下字样:

include "/etc/named.xxx.zones";

那么接下来你要配置的就不是/etc/named.rfc1912.zones,而是/etc/named.xxx.zones了。

下面我们已named.rfc1912.zones文件为例,添加对dota.net域名的解析

named.rfc1912.zones中添加如下配置:

zone "dota.net" IN { #本地正解定义
type master; #类型为master
file "dota.net.zone";#正解文件名
};

4.创建正解解析文件

在过程3中我们配置了

file "dota.net.zone";#正解文件名

接下来我们就要创建dota.net.zone文件来对dota.net域名进行具体解析

4.1进入/var/named/文件夹下

4.2创建名为dota.net.zone文件

4.3打开dota.net.zone文件并配置内容如下:

$TTL 86400
@ IN SOA localhost. root.localhost(
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS www.dota.net.
www IN A 111.111.111.111

即可将www.dota.net域名映射至IP 111.111.111.111


CentOS 5:

In Redhat Enterprise linux or Centos 5 There will be no default named .conf file in /etc directory. We Need to copy sample configuration files from /usr/share/doc/bind-9.3.4/sample/etc/ to /etc directory by using the following command.

cp /usr/share/doc/bind-9.3.4/sample/etc/* /etc/

Copy zone files to /var/named directory from /usr/share/doc/bind-9.3.4/sample/var/named.

cp -a /usr/share/doc/bind-9.X/sample/var/named/* /var/named

We need to create the dns keygen using following command

dns-keygen

a7oGexQBd93D3cyIJWxw6kZxEPCS2O7LvqM6SiT4z2RteBZPgjmdYlTfdGpy

We need to insert the keygen in /etc/named.conf file

vi /etc/named.conf

key ddns_key

{

algorithm hmac-md5;

secret a7oGexQBd93D3cyIJWxw6kZxEPCS2O7LvqM6SiT4z2RteBZPgjmdYlTfdGpy;

};

Open up /etc/named.conf file, enter zone details as per domain requirements. The following file edited to minimal configuration, this is enough to run a DNS Server. You can copy and use it for your server also.

vi /etc/named.conf

options

{

directory “/var/named”; // the default

dump-file “data/cache_dump.db”;

statistics-file “data/named_stats.txt”;

memstatistics-file “data/named_mem_stats.txt”;

};

logging

{

channel default_debug {

file “data/named.run”;

severity dynamic;

};

};

zone “itzgeek.com” IN { —–> Name of the Zone

type master;

file “itzgeek.com“; —–> Name of the file where Zone Saved

allow-update { none; };

};

zone “4.65.10.reverse” IN { —–> Name of the Zone

type master;

file “4.65.10.reverse “; —–> Name of the file where Zone Saved

allow-update { none; };

};

key ddns_key

{

algorithm hmac-md5;

secret a7oGexQBd93D3cyIJWxw6kZxEPCS2O7LvqM6SiT4z2RteBZPgjmdYlTfdGpy ;

};

Create a zone file called itzgeek.com for forward zone under /var/named directory. All domain names should end with dot (.).

There are some special keywords for Zone Files
A – A record
NS – Name Server
MX – Mail for Exchange
CN – Canonical Name

vi /var/named/itzgeek.com

$TTL 86400
@ IN SOA itzgeek.com. root@itzgeek.com. (
24211201 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS itzgeek.com.
IN A 10.65.4.55
ns1 IN A 10.65.4.56
server IN A 10.65.4.56
www IN A 10.65.4.56
mail IN A 10.65.4.56
itzgeek.com. IN MX 10 mail.itzgeek.com.

Create a zone file called itzgeek.com for forward zone under /var/named directory, create reverse pointer to the above forward zone entries.
PTR – Pointer
SOA – Start of Authority

vi /var/named/10.65.4.reverse

$TTL 86400
@ IN SOA itzgeek.com. root@itzgeek.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS itzgeek.com.
55 IN PTR itzgeek.com.
56 IN PTR server.itzgeek.com.
56 IN PTR mail.itzgeek.com.
56 IN PTR www.itzgeek.com.
56 IN PTR ns1.itzgeek.com.

Restart the service using the following command

# service named restart

Simply test the server using command to check forward zone.

# host itzgeek.com

itzgeek.com has address 10.65.4.55
itzgeek.com mail is handled by 10 mail.itzgeek.com

This is for the reverse zone

# host 10.65.4.55

55.4.65.10.in.addr.arpa domain name pointer itzgeek.com.

These above command are good enough to check the DNS. To know more about DNS resolving details we can use Dig or Nslookup

Search Term:

Configure DNS on CentOS 5 / RHEL 5 ,Configure DNS on CentOS 5 / RHEL 5, Configure DNS on CentOS 5, Configure DNS on CentOS, Configure DNS on linux, Configure DNS on RHEL 5 , Configure DNS on RHEL , Configure DNS on CentOS , Configure DNS on CentOS 5, Configure DNS on CentOS 5 / RHEL 5



Read more: http://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-configure-dns-server-on-centos-5-rhel-5.html#ixzz3MybU6k6c 
© 2014 ITzGeek. All rights reserved. 


5.开启服务

service named start




PS:由于时间有限,今日就到这里,未来两三天将会对DNS反解、转发器,DNS服务相关注意事项及常见问题解答与大家分享。欢迎大家留言一起讨论交流,有不正确的地方也请指出,谢谢。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值