实验01:DHCP服务器配置

  • 实验目标

  • 公司要求将闲置的一台Linux 主机配置为DHCP服务器,以便为局域网内员工的办公用机提供自动分配IP地址的服务,以提高网络管理和维护的效率。需要满足的基本要求如下所述。

  • 1.为192.168.10.0/24网段的客户机自动配置网络参数。

  • 用来给客户机自动分配的IP地址范围是:

                        192.168.10.50-192.168.10.100

                                        192.168.10.120-192.168.10.200

  • 客户机的默认网关地址设为192.168.10.254

  • 客户机所使用的DNS服务器设为192.168.10.253202.106.0.20

  • 默认搜索域后缀为tarena.com

  • 将默认租约时间设为8小时,最大租约时间24小时

  • 2.为打印服务器分配保留地址(Win7

  •          这台打印机每次开启电源后获得的IP地址都应该是192.168.10.8

  • 3.验证DHCP服务器的IP分配情况、客户机的租约信息

  • 实验步骤

  • 实验准备

Dhcp服务器一台,客户机一台

使所有实验机器在相同网络

二.配置DHCP服务器

1.为服务器配置ip地址以及子网掩码

 

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

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

HWADDR=00:0c:29:05:ef:c9

IPADDR=192.168.10.253

NETMASK=255.255.255.0

~     

 

  1. 2.为服务器配置主机名以及网关

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

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=dhcpser.tarena.com

GATEWAY=192.168.10.254

 3.识别主机名

[root@localhost ~]# vim /etc/hosts

  1. 127.0.0.1              localhost.localdomain localhost

::1            localhost6.localdomain6 localhost6

  1. 192.168.10.253   dhcpser.tarena.com    dhcpser

 4.重新启用网络服务

[root@localhost ~]# service network restart

正在关闭接口 eth0                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0                                            [确定]

[root@localhost ~]# chkconfig network on

  1. 5.服务器端验证配置

[root@localhost ~]# ifconfig eth0

eth0      Linkencap:Ethernet  HWaddr00:0C:29:05:EF:C9 

          inetaddr:192.168.10.253  Bcast:192.168.10.255  Mask:255.255.255.0

[root@localhost ~]# route -n

Kernel IP routing table

Destination    Gateway         Genmask         Flags Metric Ref    Use Iface

  1. 192.168.10.0   0.0.0.0         255.255.255.0   U    0      0        0 eth0

  2. 169.254.0.0     0.0.0.0         255.255.0.0     U    0      0        0 eth0

  3. 0.0.0.0        192.168.10.254  0.0.0.0         UG   0      0        0 eth0

[root@localhost ~]# hostname

dhcpser.tarena.com

[root@localhost~]# ping dhcpser.tarena.com

PINGdhcpser.tarena.com (192.168.10.253) 56(84) bytes of data.

64 bytes fromdhcpser.tarena.com (192.168.10.253): icmp_seq=1 ttl=64 time=0.096

三.安装软件包

[root@localhost~]# cd /media/Server/

[root@localhostServer]# rpm -ivh dhcp-3.0.5-31.el5_8.1.x86_64.rpm

warning:dhcp-3.0.5-31.el5_8.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID37017186

Preparing...               ########################################### [100%]

   1:dhcp                  ########################################### [100%]

[root@localhostServer]# rpm -q dhcp

dhcp-3.0.5-31.el5_8.1

四.修改配置文件

[root@localhost~]#  vim /etc/dhcpd.conf

ddns-update-styleinterim;

subnet192.168.10.0 netmask 255.255.255.0 {

        option routers                  192.168.10.254;

        option subnet-mask              255.255.255.0;

        option domain-name              "tarena.com";

        option domain-name-servers      192.168.10.253,202.106.0.20;

        range dynamic-bootp 192.168.10.50192.168.0.100;

        range dynamic-bootp 192.168.10.120192.168.0.200;

        default-lease-time 28800;

        max-lease-time 86400;

        host client {

                hardware ethernet12:34:56:78:AB:CD;

                fixed-address 192.168.10.8;

        }

}

五.启用服务

[root@localhost~]# service dhcpd restart

启动 dhcpd                                               [确定]

[root@localhost~]# chkconfig dhcpd on

[root@localhost~]# netstat -ln | grep :67

udp        0     0 0.0.0.0:67                 0.0.0.0:* 

六.客户端测试

  1. 1.修改固定配置

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

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

HWADDR=00:0c:29:23:a5:76

  1. 2.重新启用网络服务

[root@localhost ~]# service network restart

正在关闭接口 eth0                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0

正在决定 eth0 IP 信息...完成。

                                                          [确定]

  1. 3.重新查看ip地址

[root@localhost~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:23:A5:76 

          inet addr:192.168.10.200  Bcast:192.168.10.255  Mask:255.255.255.0

  1. 4.服务器端查看租约文件

  1. 5.客户端查看租约文件

[root@localhost~]# vim /var/lib/dhclient/dhclient-eth0.leases

lease {

  interface "eth0";

  fixed-address 192.168.10.200;

  option subnet-mask 255.255.255.0;

  option routers 192.168.10.254;

  option dhcp-lease-time 28800;

  option dhcp-message-type 5;

  option domain-name-servers192.168.10.253,202.106.0.20;

  option dhcp-server-identifier 192.168.10.253;

  • 问题和经验总结

故障现象:

[root@localhost~]# service dhcpd restart

启动 dhcpd                                               [失败]

解决办法:

[root@localhost ~]# service dhcpdconfigtest

.....

Address range 192.168.10.50 to192.168.0.100, netmask 255.255.255.0 spans multiple subnets!

 

If you did not get this software fromftp.isc.org, please

get the latest from ftp.isc.org and installthat before

requesting help.

........

进入/etc/dhcpd.conf,将地址池的192.168.0.100192.168.0.200改为192.168.10.

100192.168.10.200