首页 > 代码库 > DHCP服务器的搭建与维护
DHCP服务器的搭建与维护
实验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.253、202.106.0.20,
默认搜索域后缀为tarena.com。
将默认租约时间设为8小时,最大租约时间24小时
2.为打印服务器分配保留地址(Win7)
这台打印机每次开启电源后获得的IP地址都应该是192.168.10.8。
3.验证DHCP服务器的IP分配情况、客户机的租约信息
. 实验步骤
一、实验前提条件
1. 所有实验机在相同网络(vmnet4)
2. DHCP服务器有固定IP
二、实验步骤
(一)IP配置
1. 设置ip地址
[root@dhcpser ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:48:71:56 (MAK地址)
IPADDR=192.168.10.253 (ip地址)
NETMASK=255.255.255.0 (子网掩码)
~
2. 设置网关及主机名
[root@dhcpser ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com (主机名)
GATEWAY=192.168.10.254 (网关地址)
3. 配置搜索域
[root@dhcpser ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 dhcpser.tarena.com dhcpser (搜索域)
4. 重启服务
[root@dhcpser ~]# service network restart
[root@dhcpser ~]# chkconfig network on
5. 验证
[root@dhcpser ~]# ifconfig eth0(验证ip地址)
[root@dhcpser ~]# route -n(验证网络)
[root@dhcpser ~]# hostname (验证主机名)
[root@dhcpser ~]# ping dhcpser.tarena.com(验证搜索域)
(二)安装软件包
1 检测是否安装dhcp
[root@dhcpser ~]# rpm -q dhcp
放入RHEL5.9 iso镜像
2. 查看安装软件
[root@dhcpser ~]# cd /misc/cd/Server
[root@dhcpser Server]# ls *dhcp*
3. 安装dhcp
hcpser Server]# 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 ID 37017186
Preparing...
########################################### [100%]
package dhcp-3.0.5-31.el5_8.1.x86_64 is already installed
4. 检测安装结果
[root@dhcpser Server]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
(三)修改配置文件
[root@dhcpser Server]# vim /etc/dhcpd.conf
ddns-update-style interim;
subnet 192.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.50 192.168.10.100;
range dynamic-bootp 192.168.10.120 192.168.10.200;
default-lease-time 28800;
max-lease-time 86400;
host win7 {
hardware ethernet 00:0C:29:D2:B3:F9;
fixed-address 192.168.10.8;
}
}
说明: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.253、202.106.0.20,
默认搜索域后缀为tarena.com。
将默认租约时间设为8小时,最大租约时间24小时
(四)启动服务
[root@dhcpser ~]# service dhcpd restart
[root@dhcpser ~]# chkconfig dhcpd on
[root@dhcpser ~]# netstat -ln | grep :67 (查看该端口是否开启)
udp 0 0 0.0.0.0:67 0.0.0.0:*
注:如果启动失败,可以检测主配置文件语法
[root@dhcpser ~]# service dhcpd configtest
(五)租月文件
1. 服务端
[root@dhcpser ~]# less /var/lib/dhcpd/dhcpd.leases
2. 客户端
[root@localhost ~]# less /var/lib/dhclient/dhclient.leases
. 结果验证
一.客户端检测
1. Linux上检测
[root@localhost~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:0c:29:8c:81:13
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:8C:81:13
inet addr:192.168.10.200 Bcast:192.168.10.255
Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe8c:8113/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:331 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33133 (32.3 KiB) TX bytes:9326 (9.1 KiB)
补充:
[root@localhost ~]# dhclient -d eth0(临时获取)
[root@localhost ~]# dhclient -r eth0 (释放)
二.Windows上检测
1. 首先要设置自动获取
2. 网络—属性—IP自动获取—禁用—启用—状态—详细信息
3. cmd
ipconfig /release释放ip
ipconfig /renew重新获取ip
. 问题和经验总结
. DHCP排错思路
. [root@dhcpser ~]# service dhcpd restart 报错情况分析
案例:
subnet 192.168.10.10 netmask 255.255.255.0 {
option router192.168.10.254;
option subnet-mask255.255.255.0;
option domain-nametarena.com";
option domain-name-servers192.168.10.253,202.106.0.20
range dynamic-bootp 192.168.10.50 192.168.10.100;
range dynamic-bootp 192.168.10.100 192.168.10.200;
default-lease-time 28800;
max-lease-time 86400;
host ns
hardware ethernet 12:34:56:78:AB:CD;
fixed-addess 207.175.42.254;
}
}
1.检测主配置文件语法
[root@dhcpser ~]# service dhcpd configtest
故障现象:
[root@dhcpser ~]# vim /etc/dhcpd.conf
[root@dhcpser ~]# service dhcpd restart
启动 dhcpd: [失败]
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 1: semicolon expected.
ubnet 192.
^
/etc/dhcpd.conf line 4: eof in string constant
}
^
Configuration file errors encountered -- exiting
…………
解决办法:
[root@dhcpser ~]# vim /etc/dhcpd.conf
ddns-update-style interim;
…………
host ns{
…………
}
}
故障现象:
[root@dhcpser ~]# service dhcpd restart
启动 dhcpd: [失败]
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 2: semicolon expected.
ubnet 192.
^
…………
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
ubnet 192.168.10.10 netmask 255.255.255.0 {
…………
解决办法:ubnet——subnet;192.168.10.10——192.168.10.0
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
subnet 192.168.10.0 netmask 255.255.255.0 {
…………
故障现象:……
[root@dhcpser ~]# service dhcpd restart
启动 dhcpd: [失败]
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 3: unknown option dhcp.router
option router 192.
^
…………
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option router 192.168.10.254;
…………
解决办法:router——routers 用man 5 命令查找
[root@dhcpser ~]# man 5 dhcpd.conf
/router
option routers 204.254.239.1;
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option routers 192.168.10.254;
…………
故障现象:
[root@dhcpser ~]# service dhcpd restart
启动 dhcpd: [失败]
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 5: semicolon expected.
option domain-name tarena.
^
/etc/dhcpd.conf line 5: eof in string constant
}
^
/etc/dhcpd.conf line 5: unexpected end of file
}
^
…………
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option domain-name tarena.com";
………………
解决办法:tarena.com”——“tarena.com”
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option domain-name "tarena.com";
…………
故障现象:
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 7: semicolon expected.
range
^
…………
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option domain-name-servers 192.168.10.253,202.106.0.20
range dynamic-bootp 192.168.10.50 192.168.10.100;
…………
解决办法:上面一行出现错误下面报错
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
option domain-name-servers 192.168.10.253,202.106.0.20;
range dynamic-bootp 192.168.10.50 192.168.10.100;
…………
故障现象:
[root@dhcpser ~]# service dhcpd configtest
…………
/etc/dhcpd.conf line 8: lease 192.168.10.100 is declared twice!
range dynamic-bootp 192.168.10.100 192.168.10.200;
^
WARNING: Host declarations are global.They are not limited to
the scope you declared them in.
/etc/dhcpd.conf line 13: semicolon expected.
fixed-addess 207.
^
…………
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
range dynamic-bootp 192.168.10.100 192.168.10.200;
…………
fixed-addess 207.175.42.254;
…………
解决办法:addess——adderss ip范围与上面冲突
[root@dhcpser ~]# vim /etc/dhcpd.conf
…………
range dynamic-bootp 192.168.10.120 192.168.10.200;
…………
fixed-adderss 207.175.42.254;
…………
排错成功:
[root@dhcpser ~]# service dhcpd configtest
Syntax: OK
[root@dhcpser ~]# service dhcpd restart
启动 dhcpd: [确定]
本文出自 “9255610” 博客,请务必保留此出处http://9265610.blog.51cto.com/9255610/1552661
DHCP服务器的搭建与维护