centos7部署DHCP服务
yum -y install dhcp //安装DHCP服务
vim /etc/dhcp/dhcpd.conf //配置文件,里面什么都没有,告诉我们在/usr/share/doc/dhcp*/dhcpd.conf.example有个配置模板
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf //将模板cp过来
vim /etc/dhcp/dhcpd.conf //编辑DHCP配置文件
subnet 192.168.130.0 netmask 255.255.255.0 { //声明网段和子网掩码
range 192.168.130.10 192.168.130.20; //设置分配DHCP地址的地址池,根据实际
option domain-name-servers 202.96.128.86; //指定DNS服务器地址
option domain-name "internal.example.org"; //搜索域,根据情况设置,这里选择注释#
option routers 192.168.130.2; //设置客户机的默认网关地址
option broadcast-address 192.168.130.255; //广播地址
default-lease-time 300; //默认租约时间
max-lease-time 7200; //最大租约时间
ddns-update-style none; //启用或禁用全局动态dns更新
}
vim /etc/sysconfig/network-scripts/ifcfg-ens33 //修改网卡配置的如下几项
BOOTPROTO=static
IPADDR=192.168.130.5
NETMASK=255.255.255.0
GATEWAY=192.168.130.2
DNS1=202.96.128.86
ONBOOT=yes
ifup ens33 //启动网卡
systemctl start dhcpd //启动服务
systemctl enable dhcpd //下次重启启动DHCP服务
systemctl status dhcpd //查看DHCP的状态
netstat -tunlp | grep dhcpd //查看DHCP端口
客户端
dhclient -d ens33 //重新获取DHCP地址
dhclient -r ens33 //释放获取的DHCP地址
ifconfig //查看网卡信息 | ip a
DHCP服务端
less /var/lib/dhcpd/dhcpd.leases //查看DHCP租约信息