首先需要安装DHCP服务
[root@localhost Server]# rpm -ivh dhcp-3.0.5-31.el5_8.1.x86_64.rpm
将其设为开机启动
[root@localhost etc]# chkconfig dhcpd on
[root@localhost etc]# chkconfig --list dhcpd
dhcpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
配置文件
[root@localhost etc]# vim dhcpd.conf
ddns-update-style interim; 动态更新类型,必须有
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 "tarena.com";
option domain-name-servers 202.106.0.20,192.168.1.254; DNS服务器
range dynamic-bootp 192.168.1.20 192.168.1.50; IP分配范围
range dynamic-bootp 192.168.1.80 192.168.1.100;
default-lease-time 21600; 默认租约期
max-lease-time 43200; 最大租约期
host win7 {
hardware ethernet 00:0C:29:1D:0B:0C;为主机分配固定IP,只能用在host声明
fixed-address 192.168.1.88; 指定主机物理地址,只能用在host声明
}
host linux {
hardware ethernet 00:0C:29:C7:BB:E6;
fixed-address 192.168.1.66;
}
}
测试dhcp服务器
[root@localhost ~]# service dhcpd configtest
Syntax: OK
重启服务
[root@localhost ~]# service dhcpd restart
将客户端设为自动获取IP地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
重启客户端network,查看IP
[root@localhost ~]# service network restart
[root@localhost ~]# ifconfig
查看服务器IP分配情况(在服务器)
[root@localhost ~]# less /var/lib/dhcpd/dhcpd.leases
查看客户端已获取的IP租约
[root@localhost ~]# less /var/lib/dhclient/dhclient.leases
或
[root@localhost ~]# less /var/lib/dhclient/dhclient-eth0.leases
注:服务器本身必须有IP地址,IP分配范围必须在声明网段内
转载于:https://blog.51cto.com/857398758/1369543