您好,登录后才能下订单哦!
首先我的环境是在本地的VMware虚拟机,所以先将VMware中的dhcp服务关闭
关闭防火墙,关闭selinux这些必须关闭:
systemctl stop firewalld
setenforce 0
在centos8上安装dhcp-server端
[root@Centos8 ~]#yum install dhcp-server.x86_64
查看安装的包和文件
[root@Centos8 ~]#rpm -ql dhcp-server
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp #客户端
/etc/dhcp/dhcpd.conf #dhcp配置文件(空文件)
/etc/dhcp/dhcpd6.conf #ipv6配置文件
/etc/openldap/schema
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/.build-id
/usr/lib/.build-id/61
/usr/lib/.build-id/61/6771248bc042fe96877bd9496ad99a4a4817fc
/usr/lib/.build-id/e0
/usr/lib/.build-id/e0/17e374d1a55a7254398988114fdd6a0bd63df3
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/sbin/dhcpd #服务器端
/usr/share/doc/dhcp-server
/usr/share/doc/dhcp-server/dhcp-lease-list.pl
/usr/share/doc/dhcp-server/dhcpd.conf.example #配置文件范例
/usr/share/doc/dhcp-server/dhcpd6.conf.example
/usr/share/doc/dhcp-server/ldap
/usr/share/doc/dhcp-server/ldap/README.ldap
/usr/share/doc/dhcp-server/ldap/dhcp.schema
/usr/share/doc/dhcp-server/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases #地址分配记录
/var/lib/dhcpd/dhcpd6.leases
[root@Centos8 ~]#
然后启动dhcp服务
[root@Centos8 ~]#systemctl start dhcpd.service
发现启动报错,是因为dhcp如果没有配置本网段的dhcp规则是拒绝启动的。
查看配置文件:
[root@Centos8 ~]#vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
dhcp默认配置文件是空的,但是它说了看/usr/share/doc/dhcp-server/dhcpd.conf.example这个文件,这个是dhcp配置的一些范例。
[root@Centos8 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
直接替换配置文件,再次查看:
[root@Centos8 ~]#vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#其中全局语句块和subnet语句块均可使配置生效,subnet语句块优先级高于全局语句块:
#全局语句块:
# option definitions common to all supported networks...
#指定获取主机域后缀:
option domain-name "wj02.com";
#指定DNS,可选
option domain-name-servers 180.76.76.76, 119.29.29.29;
#ip的租期,单位:秒
default-lease-time 86400; #默认是600s,客户端会在租期的一半也就是300s后进行续租,组曲太短会占用大量的网络带宽,建议改时间长一点。这里修改为86400s,一天。
#最大租期时间
max-lease-time 100000;
...
log-facility local7;
...
#subnet配置
#指定网段
subnet 192.168.38.0 netmask 255.255.255.0 {
#指定分配的ip范围,可以跳过一些地址
range 192.168.38.10 192.168.38.120;
range 192.168.38.150 192.168.38.254;
#指定网关
option routers 192.168.38.2;
}
#为一个mac地址分配一个固定的ip,效果等同于静态获取
host test {
hardware ethernet 00:0c:29:58:4f:12;
fixed-address 192.168.39.102;
}
#为00:0c:29:58:4f:12这个mac地址固定的分配192.168.39.120这个地址
......
dhcp还有语法检查功能:
dhcpd -t -cf /etc/dhcp/dhcpd.conf
当然如果语法不对,启动也会报错的,这个其实不重要。
配置文件修改完毕后,重新启动dhcp服务
[root@Centos8 ~]#systemctl start dhcpd
启动成功。
在客户端获取ip
dhclient –d
因为配置文件里我绑定了mac地址,所以这个服务器应该分配到192.168.38.102这个ip
至此,dhcp服务器搭建成功。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。