实验01:搭建简单DHCP服务器

  • 实验目标

  • 搭建简单DHCP服务器

  • 实验步骤

  • 环境准备

  • 安装一台RHEL6.5虚拟机

        1)内存1G、硬盘80G、软件包(桌面、开发工具)

        2)关闭防火墙、关闭SELinux机制

         提示:修改 /etc/selinux/config,设置SELINUX=permissive

         getenforcesetenforce

        3)安装好vmware-tools

        4)网络配置:VMnet4 svr5.tarena.com  192.168.4.5/24

         提示:关闭 NetworkManager 服务

                   修改 ifcfg-eth0文件,ONBOOT=yesNM_CONTROLED=no

        5)配置YUM仓库,确保可用

[root@svr5 ~]#vim  /etc/yum.repos.d/rhel6.repo

[rhel-packages]

name=RHEL6

baseurl=file:///misc/cd

enabled=1

gpgcheck=1

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

 

2. 关机、做快照,压缩备用

3. 克隆出第二台RHEL6.5虚拟机

        1)网络配置:VMnet4 pc205.tarena.com  192.168.4.205 

        2)将 eth1 恢复为 eth0

[root@svr5 ~]#vim /etc/udev/rules.d/70-persistent-net.rules

.. ..

#//删除原有的eth0配置

#// eth1 的配置名称改为 eth0

SUBSYSTEM=="net",ACTION=="add", DRIVERS=="?*",ATTR{address}=="00:0c:29:f1:cb:79", ATTR{type}=="1",KERNEL=="eth*", NAME="eth0"

 

[root@svr5 ~]#reboot

服务器端

1.安装软件包

[root@svr5 ~]# yum -y install dhcp

2.配置主配置文件

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

 1 default-lease-time 7200;

  2 max-lease-time 14400;

  3 subnet 192.168.4.0 netmask255.255.255.0 {

  4   range 192.168.4.28 192.168.4.54;

  5   range 192.168.4.128 192.168.4.200;

  6   option domain-name-servers202.106.0.20,8.8.8.8;

  7   option domain-name "tarena.com";

  8   option routers 192.168.4.1;

  9 }

3.重新启动服务

[root@svr5 桌面]# service dhcpd restart

正在启动 dhcpd                                           [确定]

[root@svr5 桌面]# chkconfig dhcpd on

[root@svr5 桌面]# netstat -anptu | grep dhcp

udp        0      0 0.0.0.0:67                  0.0.0.0:*                               2889/dhcpd 

客户端

1.修改网卡配置文件

[root@pc205 桌面]# vim/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=dhcp

2.重新启动网络服务

[root@pc205 桌面]# service network restart

正在关闭接口 eth0                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0

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

                                                           [确定]

3.查看网卡信息

[root@pc205 桌面]# ifconfig eth0

eth0      Linkencap:Ethernet  HWaddr00:0C:29:B4:73:BE 

          inetaddr:192.168.4.28 Bcast:192.168.4.255 Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:feb4:73be/64Scope:Link

          UP BROADCAST RUNNINGMULTICAST  MTU:1500  Metric:1

          RX packets:11 errors:0dropped:0 overruns:0 frame:0

          TX packets:163errors:0 dropped:0 overruns:0 carrier:0

          collisions:0txqueuelen:1000

          RX bytes:2636 (2.5KiB)  TX bytes:24530 (23.9 KiB)

实验02:保留地址

1. 服务器调整

修改主配置文件

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

default-lease-time 7200;

max-lease-time 14400;

log-facility local7;

subnet 192.168.4.0 netmask 255.255.255.0 {

  range 192.168.4.28192.168.4.54;

  range 192.168.4.128192.168.4.200;

  optiondomain-name-servers 202.106.0.20,8.8.8.8;

  option domain-name"tarena.com";

  option routers192.168.4.1;

         host pc205 {

               hardware ethernet 00:0C:29:4A:8C:27;

                fixed-address 192.168.4.110;

        }

}

2.重新启动服务

[root@svr5 /]# service dhcpd restart

关闭 dhcpd                                              [确定]

正在启动 dhcpd                                           [确定]

3.客户端测试

[root@pc205 桌面]# dhclient -d eth0

Internet Systems Consortium DHCP Client 4.1.1-P1

Copyright 2004-2010 Internet Systems Consortium.

All rights reserved.

For info, please visit https://www.isc.org/software/dhcp/

 

Listening on LPF/eth0/00:0c:29:b4:73:be

Sending on  LPF/eth0/00:0c:29:b4:73:be

Sending on   Socket/fallback

DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7(xid=0x457d6a84)

DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10(xid=0x457d6a84)

DHCPOFFER from 192.168.4.5

DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x457d6a84)

DHCPACK from 192.168.4.5 (xid=0x457d6a84)

bound to 192.168.4.29 -- renewal in 3507 seconds.

  • 问题和经验总结

故障现象:

在客户端不能自动获取ip地址

解决办法:

先检查是否关闭了NetworkManager服务,如果关闭仍不能获取,再检查dhcp服务器的配置是否有误