前言
假装有前言
我们首先先配置网卡
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
使用vim进入配置界面
保存退出后重启:
[root@localhost ~]# systemctl restart network #重启
[root@localhost ~]# ifconfig #查看
然后开始配置DHCP
挂载光盘,配置本地源仓库
[root@localhost ~]# mount /dev/cdrom /mnt/ #把光盘挂载到/mnt目录下
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir repos.bak
[root@localhost yum.repos.d]# mv *.repo repos.bak #备份
cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim local.repo
[local] #仓库类别
name=local #仓库名称
baseurl=file:///mnt #指定URL 访问路径为光盘挂载目录
gpgcheck=0 #不验证软件包的签名
enabled=1 #开启此yum源,此为默认项,可省略
[root@localhost ~]# yum clean all #清除缓存
[root@localhost ~]# yum makecache #生成新的缓存源
[root@localhost ~]# yum install -y dhcp #安装dhcp
开始配置DHCP
DHCP配置文件如下
etc/dhcp/dhcpd.conf
[root@localhost ~]# cd /etc/dhcp/ #进入DHCP配置文件目录
[root@localhost dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf scripts
[root@localhost dhcp]# less dhcpd.conf #查看内容
[root@localhost dhcp]# cd /usr/share/doc/dhcp-4.2.5/ #到该目录下去寻找dhcp配置模板
[root@localhost dhcp-4.2.5]# ls
[root@localhost dhcp-4.2.5]# less dhcpd.conf.example
[root@localhost dhcp-4.2.5]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf # ##将模板覆盖到/etc/dhcp/dhcpd.conf中
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes
[root@localhost dhcp-4.2.5]# cd /etc/dhcp/ #回到/etc/dhcp目录下
[root@localhost dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf scripts
[root@localhost dhcp]# vim /etc/dhcp/dhcpd.conf #编辑配置文件
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
Subnet 192.168.100.0 netmask 255.255.255.0 { #网段,子网掩码
range 192.168.100.100 192.168.100. 200; #配置地址池
option routers 192. 168.100.1; #默认网关
}
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168. 10.100192.168.10. 200;
option routers 192.168.10.1;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.100 192.168. 20.200;
option routers 192.168. 20.1;
}
# This is a very basic subnet declaration.
关闭防火墙,重启网络和DHCP服务,用ping命令验证一下网络
[root@localhost dhcp]# systemctl stop firewalld #关闭防火墙
[root@localhost dhcp]# setenforce 0 #关闭内核防护
[root@localhost dhcp]# systemctl restart network #重启网络
[root@localhost dhcp]# systemctl restart dhcpd #重启DHCP服务
[root@localhost dhcp]# ping 192.168.100.1
...
[root@localhost dhcp]# ping 192.168.10.1
...
[root@localhost dhcp]# ping 192.168.20.1
...
这样就是配好了的,现在可以开一台虚拟机来尝试这连接DHCP自动获取 IP地址了