项目环境:
linux操作系统,centos7.9,dhcp
目的:搭建一个dhcp服务器
dhcp实验 搭建dhcp服务器,准备两台linux虚拟机(两边的网卡模式要一样,都是桥接)
1.下载dhcp对应的插件
[root@localhost named]# yum install -y dhcp
2.复制对应的配置文件到/etc/dhcp目录下
[root@localhost named]# cd /etc/dhcp
[root@localhost dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example ./dhcpd.conf
3.更改配置文件
[root@localhost dhcp]# vim dhcpd.conf
log-facility local7;
subnet 192.168.2.0 netmask 255.255.255.0 { ==》更改为对应2网段,和子网掩码
range 192.168.118.10 192.168.118.100; ==》配置对应的ip池
option domain-name-servers 114.114.114.114; ==更改域名服务器
option routers 192.168.118.2; ====》更改为自己的路由
default-lease-time 600;
max-lease-time 7200;
}
4.启动网卡重新获得ip地址的方法
[root@localhost dhcp]# systemctl restart network
(客户机操作)
5.保存租约历史
[root@server ~]# dhclient -lf /var/lib/dhclient/dhclient.leases
6.查看文件查看是否分的ip地址
[root@server ~]# cat /var/lib/dhclient/dhclient.leases
lease {
interface "ens33";
fixed-address 192.168.2.103;
option subnet-mask 255.255.255.0;
option routers 192.168.2.1;
option dhcp-lease-time 600;
option dhcp-message-type 5;
option domain-name-servers 114.114.114.114;
option dhcp-server-identifier 192.168.2.119; ======》为我们设置的dhcp服务器地址,成功
renew 5 2023/07/28 12:24:10;
rebind 5 2023/07/28 12:28:55;
expire 5 2023/07/28 12:30:10;
}
(在服务器操作查看)
7.在dhcp服务器端看给哪些客户机分配了ip地址
[root@localhost sc]# cat /var/lib/dhcpd/dhcpd.leases
lease 192.168.2.103 {
starts 5 2023/07/28 12:24:25;
ends 5 2023/07/28 12:34:25;
cltt 5 2023/07/28 12:24:25;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:11:71:40;
client-hostname "server";
}