首页 > 代码库 > 搭建一个简单的DHCP服务器
搭建一个简单的DHCP服务器
实验环境:
系统:RHEL6.4
一.给DHCP服务器配置固定IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=.......
TYPE=Ethernet
UUID=......
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.50.253
NETMASK=255.255.255.0
[root@localhost ~]#service network restart
[root@localhost ~]#chkconfig network on
[root@localhost ~]inconfig eth0
二.安装dhcp软件包
[root@localhost ~]rpm -q dhcp
package dhcp is not installed
放入RHEL6.4.iso
[root@localhost ~]cd /misc/cd/Packages/
[root@localhost Packages]ls dhcp*
dhcp-4.1.1-34.P1.el6.x86_64.rpm
dhcp-common-4.1.1-34.P1.el6.x86_64.rpm
[root@localhost Packages]rpm -ivh dhcp-4.1.1-34.P1.el6.x86_64.rpm
warning: dhcp-4.1.1-34.P1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:dhcp ########################################### [100%]
三.配置DHCP服务器
[root@localhost ~]vim /etc/dhcpd/dhcpd.conf
ddns-update-style none; //动态更新类型
subnet 192.168.50.0 netmask 255.255.255.0 { //网段声明
range 192.168.50.10 192.168.50.20; //IP分配范围
range 192.168.50.50 192.168.50.60;
option domain-name-servers 192.168.50.252,114.114.114.114; //DNS服务器地址
option domain-name "tarena.com"; //默认搜索域
option routers 192.168.50.254; //默认网关
default-lease-time 21600; //默认租期
max-lease-time 43200; //最大租期
}
host hostname { //识别名称
hardware ethernet 00:00:00:00:00:00; //客户机MAC地址
fixed-address 192.168.50.33; //分配给改客户机的固定IP
}
四.启动服务
[root@localhost ~]service dhcpd status
dhcpd已停
[root@localhost ~]service dhcpd start
启动dhcpd : [确定]
[root@localhost ~]chkconfig --list dhcpd
dhcpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@localhost ~]chkconfig dhcpd on
五.客户端验证
Windows平台
网络设置选择自动选取,ipconfig /release
ipconfig /renew
Linux 平台
临时
dhclient -d eth0 获取
dhclient -r eth0 释放
永久
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:00:00:00:00:00
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
[root@localhost ~]#service network restart
[root@localhost ~]#ifconfig eth0
错误检查:
service dhcpd configtest //检查dhcpd.conf语法错误
根据提示一步步排错,如果语法OK,服务启动不了,查看本机IP地址.