①配置前的环境准备
##确保dhcp服务器有固定ip
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=satic //ip获取模式为static 静态
ONBOOT=yes
HWADDR=00:0c:29:f5:82:fe
IPADDR=192.168.1.1
NETMASK=255.255.255.0
[root@localhost ~]# /etc/init.d/network restart //重启network服务
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
[root@localhost ~]# chkconfig network on //保证network服务默认启动
[root@localhost ~]#
##安装dhcp服务的rpm包
[root@localhost ~]# rpm -q dhcp
package dhcp is not installed
[root@localhost ~]# mount /dev/hdc /media/
mount: block device /dev/hdc is write-protected, mounting read-only
[root@localhost ~]#
[root@localhost ~]# rpm -ivh /media/Server/dhcp-3.0.5-31.el5_8.1.x86_64.rpm
warning: /media/Server/dhcp-3.0.5-31.el5_8.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:dhcp ########################################### [100%]
[root@localhost ~]#
##编辑dhcpd主配置文件
[root@localhost ~]# vim /etc/dhcpd.conf
##打开后是空文件,可以将下面的模板导入
/usr/share/doc/dhcp*/dhcpd.conf.sample
以下是主要的配置内容
ddns-update-style interim; //DHCP和DNS更新模式,必须包括的设置项
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 { //全局的子网和掩码
option routers 192.168.1.254; //网关
option subnet-mask 255.255.255.0; //掩码
option domain-name "domain.org";
option domain-name-servers 192.168.1.253; //主机所在域
range dynamic-bootp 192.168.1.128 192.168.1.250;//地址池
default-lease-time 21600;//默认租期 ,可以放到全局下
max-lease-time 43200; //最大租期,可以放到全局下
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;//声明的保留地址
}
}
[root@localhost ~]# /etc/init.d/dhcpd
Usage: /etc/init.d/dhcpd {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}
[root@localhost ~]# /etc/init.d/dhcpd configtest //对dhcpd配置文件检测
Syntax: OK
[root@localhost ~]# /etc/init.d/dhcpd restart //开启dhcpd服务
关闭 dhcpd: [确定]
启动 dhcpd: [确定]
[root@localhost ~]# chkconfig dhcpd on //确保dhcpd服务默认开机启动
③测试 :
windows 下运行cmd
ipconfig /all
ipconfig /release //释放已获得ip地址
ipconfig /renew //重新获取
linux 输入命令
dhclient -d 网卡名 //从dhcp服务器获得ip
ifconfif 网卡名 //查看ip