DHCP服务
仓库:1、本地库;2、网上镜像源(虚拟机能上网即可安装)
1、挂载光盘
在右下角提前连接好光盘
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sr0 4.2G 4.2G 0 100% /mnt
2、编写仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt
gpgcheck=0
[root@localhost yum.repos.d]# yum clean all //清理缓存
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 2835.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 159 M RSS (572 MB VSZ)
Started: Fri Mar 29 21:40:27 2024 - 09:31 ago
State : Sleeping, pid: 2835
`按ctrl c终止`
[root@localhost yum.repos.d]# kill -9 2835 //杀死进程
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache //建立缓存
[root@localhost yum.repos.d]# yum repolist //刷新仓库
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
BaseOS BaseOS 3,971
repolist: 3,971
3、安装软件包
[root@localhost ~]# yum search dhcp //搜索软件包
dhcp.x86_64 : Dynamic host configuration protocol software
[root@localhost ~]# yum install -y dhcp //安装软件包
[root@localhost ~]# rpm -q dhcp //查询软件包是否安装
dhcp-4.2.5-68.el7.centos.x86_64
4、关闭防火墙
方法一:放行防火墙
[root@localhost ~]# man firewall-cmd
[root@localhost ~]# firewall-cmd --permanent --add-service=dhcp
success
[root@localhost ~]# firewall-cmd --reload //重新加载防火墙
success
[root@localhost ~]# firewall-cmd --list-all //列出放行信息
public (active)
services: ssh dhcpv6-client `dhcp`
或者
方法二:关闭防火墙
[root@localhost ~]# systemctl stop firewalld
5、关闭selinux
[root@localhost ~]# vim /etc/selinux/config (重启虚拟机才生效)
7 SELINUX=disabled
临时关闭selinux
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
DHCP服务部署
简介:DHCP,动态主机配置协议(给客户端自动分配IP地址) 工作原理: 1、客户端向服务器发送申请 2、服务器回应租约地址 3、客户端对租约地址进行选择 4、租约成功 续约原理: 1、当租约进行到一半时,客户端向服务器发送续约申请 2、当租约进行到75%时,客户端向服务器发送续约申请 169
准备工作 1、给Linux配置IP地址 IP地址:192.168.1.1/24 网关:192.168.1.254 DNS:192.168.1.254 2、编辑----虚拟网络编辑器---仅主机模式---取消DHCP的√ 3、虚拟机设置---网络适配器---仅主机模式 ---------------------------------------------------- 1、挂载光盘 2、编写仓库 3、安装软件包 4、关闭防火墙 5、关闭selinux 6、根据报名查询配置文件路径 [root@localhost ~]# rpm -qc dhcp /etc/dhcp/dhcpd.conf 7、查看主配置文件(无生效内容) [root@localhost ~]# vim /etc/dhcp/dhcpd.conf 8、查看样例文件 [root@localhost ~]# vim /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example 9、将样例文件内容复制到主配置文件中 [root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y 10、再次编写主配置文件 [root@localhost ~]# vim /etc/dhcp/dhcpd.conf :set nu #设置行号 /A #搜索A :1,46d #删除1到46行 :21 #跳转到21行 dG #删除光标之后的所有行 1 subnet 192.168.1.0 netmask 255.255.255.0 { 2 range 192.168.1.10 192.168.1.20; 3 option domain-name-servers 192.168.1.1; 4 option routers 192.168.1.254; 5 default-lease-time 600; 6 max-lease-time 7200; 7 } 11、重启服务 [root@localhost ~]# systemctl restart dhcpd 12、通过windows的vmnet1自动获取IP地址