一、实验拓扑
RHEL5.9
--------------RHEL5.9(vmnet4)-------------------(vmnet4)
Win7
实验前提条件
1. 所有试验机在相同网络
2. DHCP服务器有固定IP
实验操作步骤:
1. 设置ip
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 //设服务器端ip
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:5d:a8:80
IPADDR=192.168.1.253
PREFIX=24
[root@localhost ~]# cat /etc/sysconfig/network //设服务器网关
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com //主机名
GATEWAY=192.168.1.254
[root@localhost ~]# cat /etc/resolv.conf //设dns服务器地址
search tarena.com
nameserver 202.106.0.20
[root@localhost ~]# service network restart //重启网络服务
[root@localhost ~]# chkconfig network on //开机自启动网络
验证:
[root@dhcpser ~]# ifconfig eth0 //查看IP是否正确
[root@dhcpser ~]# route -n //查看网关是否启用
[root@dhcpser ~]# hostname //查看主机名是否正确
[root@dhcpser ~]# cat /etc/resolv.conf //查看DNS设置
2. 安装软件包
[root@dhcpser ~]# rpm -q dhcp//查询dhcp是否安装
放入RHEL5.9 iso镜像
[root@dhcpser ~]# cd /misc/cd/Server//切换到关盘Server目录下
[root@dhcpser Server]# ls *dhcp* //查看与dhcp相关的rpm包
[root@dhcpser Server]# rpm -ivh dhcp-3.0.5-31.el5_8.1x86_64.rpm //安装dhcp
[root@dhcpser Server]# rpm -q dhcp //查看是否安装
dhcp-3.0.5-31.el5_8.1
3. 修改配置文件
[root@dhcpser ~]# cat -n /etc/dhcpd.conf //配置dhcp地址池,网关,dns,地址
保留等
1 ddns-update-style none;
2 default-lease-time 21600; //默认租期
3 max-lease-time 43200; //最大租期
4 option subnet-mask 255.255.255.0; //子网掩码
5 option domain-name "tarena.com"; //域名
6 option domain-name-servers 202.106.0.20; //DNS服务器地址
7 subnet 192.168.1.0 netmask 255.255.255.0 { //声明网段
8 option routers 192.168.1.254; //默认网关地址
9 range dynamic-bootp 192.168.1.10 192.168.1.20; //IP分配范围
10 host win7 { //设置保留地址,识别名称
11 hardware ethernet 00:0C:29:E1:F6:25; //客户机MAC地址
12 fixed-address 192.168.1.80; //固定的IP地址
13 }
14 }
4. 启动服务
[root@dhcpser ~]# rpm -ql dhcp | grep init.d //查看服务名
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
[root@dhcpser ~]# service dhcpd restart //重启DHCP服务
[root@dhcpser ~]# chkconfig dhcpd on //设置DHCP服务开机自动启动
注:如果启动失败,可以检测主配置文件语法
[root@dhcpser ~]# service dhcpd configtest //检查语法
5. 验证
Linux:
# dhclient -d eth0//临时获取
# dhclient -r eth0//释放
Windows:
开始>运行>cmd>ipconfig /release//释放ip
开始>运行>cmd>ipconfig /renew//重新获取ip
注:DHCP主配置文件模版位置/usr/share/doc/dhcp-*/dhcpd.conf.sample