前置环境设置
关闭VMware的DHCP
基础环境设置
1.关闭防火墙
[root@cloud ~]# systemctl stop firewalld [root@cloud ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
2.关闭seLinux
[root@cloud ~]# setenforce 0 [root@cloud ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
3.修改为静态网络
[root@cloud ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes DEVICE=ens33 ONBOOT=yes IPADDR=192.168.75.88 PREFIX=24 GATEWAY=192.168.75.2 DNS1=114.114.114.114 [root@cloud ~]# systemctl restart network
二、搭建DHCP服务
1.安装dhcp
[root@cloud ~]# yum install -y dhcp
2.修改dhcp文件
# 将模板文件文件复制到主配置文件下 [root@cloud ~]# cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y # 提示是否覆盖 # 修改dhcp配置文件,内容在47行 [root@cloud ~]# vi /etc/dhcp/dhcpd.conf subnet 192.168.75.0 netmask 255.255.255.0 { range 192.168.75.30 192.168.75.40; # 分配的地址池 option domain-name-servers 114.114.114.114; # 分配的DNS option domain-name "dhcp"; # 域 option routers 192.168.75.2; # 网关路由 default-lease-time 600; # 租凭时间,单位默认为s max-lease-time 7200; # 最大租凭时间 }
3.启动dhcp服务
[root@cloud ~]# systemctl restart dhcpd [root@cloud ~]# systemctl enable dhcpd
三、测试
克隆,或创建一台虚拟机
1.修改IP地址
[root@cloud ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes DEVICE=ens33 ONBOOT=yes IPADDR=192.168.75.88 NETMASK=255.255.255.0 GATEWAY=192.168.75.2 DNS1=114.114.114.114 # 修改成 TYPE=Ethernet BOOTPROTO=dhcp #改成动态 DEFROUTE=yes DEVICE=ens33 ONBOOT=yes
2.重启网络
[root@cloud ~]# systemctl restart network
3.查看是否有ip地址,并且查看IP是否在分配地址池内
4.查看是否能否上网