Preparation
1. CentOS 7 as server
CentOS 7 as a client
2. First set the DHCP server on the virtual machine and the network connection of the client to the host-only mode (in order to better simulate the production server)
2. Open the virtual network editor and turn off "Use local DHCP server IP address to virtual machine" in host-only mode
Server side configuration
1. Edit network configuration
vim /etc/sysconfig/network-scripts/ifcfg-ens33
Configure network-related instructions:
TYPE=Ethernet #Set the network card type, "Ethernet" means Ethernet
DEVICE=ens33 #Set the name of the network card
ONBOOT=yes #Set whether the network card is activated when the Linux operating system starts
BOOTPROTO=static #Set the configuration method of the network card, "static" means to use a static IP address, and "dhcp" means to obtain an address dynamically
IPADDR=192.168.80.3 #Set the IP address of the network card
NETMASK=255.255.255.0 #Set the subnet mask of the network card
GATEWAY=192.168.80.2 #Set the default gateway address of the network card
DNS1=192.168.80.2 #Set the IP address of the DNS server
Practical case:
Note: Set BOOTPROTO to static (static ip)
Change ONBOOT to yes
2. Restart the network
systemctl restart network
3. Check whether the DHCP server is installed
rpm -q dhcp
If not installed, use: yum -y install dhcp command to install dhcp
4. Configure DHCP
vim /etc/dhcp/dhcpd.conf
Configuration related instructions:
subnet: subnet segment
netmask: subnet mask
range: the range allocated by the dhcp server
option domain-name-servers: server address
option domain-name: domain name
option routers: gateway ip address
option broadcast-address: broadcast address
default-lease-time : default lease time
max-lease-time : maximum lease time
Practical case
5. Turn on the DHCP server
systemctl start dhcpd
6. Check whether DHCP is running normally
If active (running) is displayed , it means normal operation
Client side configuration and testing
Seven. Network configuration on the client
vim /etc/sysconfig/network-scripts/ifcfg-ens33
Note: BOOTPROTO changed to dhcp
Change ONBOOT to yes
Eight. Check the network information on the client
type ifconfig
You can see that the ip address of ens33 is 192.168.101.77 of the dhcp server, indicating that it has been successful