我做的主从dns服务器+dhcp+http测试

   dns在互联网中的重要性不言而喻,据说在linux中,dns的搭建是最繁杂的服务,很容易出错。网上有很多架设dns服务的例子,但很多讲的只是架设一台dns且中间不时的出现一些错误,我想架设一对主从dns服务,经过些许实验现已比较熟练,现在把文档生成如下:

一、实验环境:在vmware虚机下,建两台rehat5.6分别作为主从dns服务器,一台ip指定为192.168.65.151,为主dns服务器,主机名为master;另一台ip指定为192.168.65.129,为辅助dns服务器,主机名为slave。在主dns上配置dhcp服务,目的是给客户机自动分配ip地址和dns地址;在从服务器上配置web服务,目的是为了更好的区分当主dns挂了,从dns能继续提供解析服务。再建一台winxp虚机,作为客户端用。如图:wKiom1MheMmwtTKuACLKkClr2iE027.jpg

二.实验过程如下:

(1)对主dns服务器的操作:

1.设置ip

[root@master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=static

IPADDR=192.168.65.151

NETWORK=192.168.65.0

BROADCAST=192.168.65.255

NETMASK=255.255.255.0

GATEWAY=192.168.65.151

HWADDR=00:0C:29:03:54:66

ONBOOT=yes

2.设定主机名

[root@master ~]# vim /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=master

3.然后[root@master ~]#reboot  #重启的目的是让设置的主机名master生效。

4.安装dns和dhcp服务软件。是由于提供dns服务的主流软件时bind,在这里我装的是bind。但在安装bind前,先配置yum源,因为用rpm安装bind会有依赖关系包出现,用yum可以避免。

配置yum源:

#cd /etc/yum.repos.d/

#cp rhel-source.repo rhel-local.repo

#vim /etc/yum.repos.d/rhel-local.repo

[rhel-local]

name=Red Hat Enterprise Linux $releasever - Source

baseurl=file:///media/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

把rhel-local.repo中的内容改成上面的即可,来自光盘安装的yum源配置好了

然后 #mount /dev/cdrom /media

现在开始配置bind(即dns服务)以及dhcp。

#yum install bind bind-chroot bind-utils caching-nameserver dhcp -y

解释:bind为dns主服务软件;bind-chroot:为了dns更加安全,bind提供了bind-chroot保护路径功能,目的就是为了更加安全;caching-nameserver提供了缓存文件。详见百度

5.配置dhcp服务。编辑dhcp主配置文件

#cd /usr/share/doc/dhcp-3.0.5/

默认情况下dhcp主配置文件不存在,所以进行一下操作

#cat dhcpd.conf.sample > /etc/dhcpd.conf  #作用是建立dhcp主配置文件。

编辑dhcp主配置文件:

# vim /etc/dhcpd.conf

ddns-update-style interim;

ignore client-updates;


subnet 192.168.65.0 netmask 255.255.255.0 {


# --- default gateway

option routers192.168.65.151;

option subnet-mask255.255.255.0;


option nis-domain"mydns.com";

option domain-name"mydns.com";

option domain-name-servers192.168.65.151;

option domain-name-servers192.168.65.129;


option time-offset-18000;# Eastern Standard Time

#option ntp-servers192.168.1.1;

#option netbios-name-servers192.168.1.1;

# --- Selects point-to-point node (default is hybrid). Don't change this unless

# -- you understand Netbios very well

#option netbios-node-type 2;


range dynamic-bootp 192.168.65.220 192.168.65.230;

default-lease-time 21600;

max-lease-time 43200;


# we want the nameserver to appear at a fixed address

host ns {

next-server marvin.redhat.com;

hardware ethernet 12:34:56:78:AB:CD;

fixed-address 207.175.42.254;

}

}

将dhcpd.conf改动如上。

然后启动dhcp服务:

#service dhcpd start   #也可以  #/etc/rc.d/init.d/dhcpd start

设置dhcp服务开机在运行等级为3和5情况下自启动(即在字符界面和图形界面):

#chkconfig dhcpd --level 35 on

6.配置bind(dns)服务。

#cd /var/named/chroot/etc

默认bind没有dns主配置文件,手动建立named.conf如下:

#mv named.caching-nameserver.conf named.conf

编辑named.conf内容如下:

# vim /var/named/chroot/etc/named.conf

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; };

allow-query-cache { any; };

allow-transfer {192.168.65.129;};

};

include "/etc/rndc.key";

zone "mydns.com" {

type master;

file "mydns.com.zone";

};

zone "65.168.192.in-addr.arpa" {

type master;

file "65.168.192.zone";

};

zone "." {

type hint;

file "named.ca";

};

配置完named.conf后,还要到/var/named/chroot/var/named/下创建 mydns.com.zone 和65.168.192.zone两个文件,如下:

> mydns.com.zone

>65.168.192.zone

编辑mydns.com.zone,如下:

# vim mydns.com.zone

$TTL86400

@IN SOA@       root (

42; serial (d. adams)

3H; refresh

15M; retry

1W; expiry

1D ); minimum


       IN NSmydns.com

IN A192.168.65.151

IN AAAA::1

wwwIN A192.168.65.129

编辑65.168.192.zone,如下

# vim 65.168.192.zone

$TTL86400

@       IN      SOA     mydns.com. root.localhost.  (

                                     1997022700 ; Serial

                                     28800      ; Refresh

                                     14400      ; Retry

                                     3600000    ; Expire

                                     86400 )    ; Minimum

       IN      NS      mydns.com.

129     IN      PTR     www.mydns.com.

编辑完后按Esc键,然后输入:wq保存退出即可。

现在可以启动named服务了:

#service named start

将named服务设置成开机自启动:

#chkconfig named --level 35 on

至此,主dns服务器上面相关配置完成。

(2)。对辅助dns服务器的操作。

1.配置静态ip:

# cat /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=static

IPADDR=192.168.65.129

NETWORK=192.168.65.0

BROADCAST=192.168.65.255

NETMASK=255.255.255.0

GATEWAY=192.168.65.151

HWADDR=00:0C:29:F8:73:52

ONBOOT=yes

2.设置主机名

# hostname

slave

3.安装dns和http软件

#yum install bind bind-chroot bind-utils caching-nameserver httpd -y

4.http和bind、dhcp不同,http软件装好可以直接启用:

#service httpd start

设置httpd开机自启动:

#chkconfig httpd --level 35 on

5.配置bind

# cat /var/named/chroot/etc/named.conf

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; };

allow-query-cache { any; };

};

include "/etc/rndc.key";

zone "mydns.com" {

type slave;

file "slaves/mydns.com.zone";

masters {192.168.65.151;};

};

zone "65.168.192.in-addr.arpa" {

type slave;

file "slaves/65.168.192.zone";

masters {192.168.65.151;};

};

zone "." {

type hint;

file "named.ca";

};

到此不需要到/var/named/chroot/var/named下创建编辑文件了,因为这台服务器为从dns服务器,配置到现在已经够用的了。启动bind:

#service named start

设置named开机自启动:

#chkconfig named --level 35 on

哦了。

6.本地测试配置好的dns服务:

# host www.mydns.com

www.mydns.com has address 192.168.65.129

# host 192.168.65.129

129.65.168.192.in-addr.arpa domain name pointer www.mydns.com.

(3)客户端winxp系统上测试dns服务:

wKioL1Mdk_LCKSzMAAFpIXOFNB0630.jpg

wKiom1MdlBiCN9GEAAF9S1p_nx0985.jpg

wKioL1Mdk_LhEopMAAIl3lSrqNs994.jpg


哦了,实验表明,当主dns服务器挂了,从服务器dns可以继续完成解析工作。


















本文出自 “个人感受” 博客,谢绝转载!

你可能感兴趣的:(我做的主从dns服务器+dhcp+http测试)