Catalog title
- Understand DHCP service
- Configure DHCP server
-
- Virtual machine settings
- Install dhcp software
- Configure the /etc/dhcp/dhcpd.conf file
- There is a problem with editing the /etc/dhcp/dhcpd.conf file and an error is reported when the service is restarted
- Configure eNSP
- Add a new PC to specify its ip address
- Linux client uses DHCP to dynamically obtain IP
Understand DHCP service
- DHCP Dynamic Host Configuration Protocol
- A protocol specifically used to automatically assign TCP/IP parameters to computers in a TCP/IP network
- Benefits of using DHCP
- Reduce the workload of administrators
- Avoid the possibility of input errors
- Avoid IP address conflicts
- When changing the IP address segment, there is no need to reconfigure each user's IP address
- Improved utilization of IP addresses
- Convenient client configuration
- DHCP distribution method
- Automatic allocation: permanent use after being allocated an IP address
- Manual allocation: the IP address is specified by the DHCP server administrator
- Dynamic allocation: release the IP after use, for other clients to use
working principle
-
The process by which the client obtains an IP address from the DHCP server is called the DHCP lease process. The
first step: the client searches for the server in the network. The
client sends a DHCP Discover message by broadcast to find the server; the
second step: the server responds to the client for the service
The server sends a DHCP offer message to provide network information such as IP address to the client through broadcast (broadcast Huawei equipment in Linux is unicast), and select an unallocated IP address from the IP address pool to assign to the client;
Step 3: The client sends a service request to the server.
If multiple DHCP servers send a DHCP-offer message to the client, the client only accepts the first received DHCP-offer message and extracts the IP address, and then the client broadcasts Send a DHCP Request message to inform the server to choose to use the IP address locally;
Step 4: The server provides services to the client The
server sends a DHCP Ack message through unicast to inform the client that the IP address is legal and usable, and adds it to the option field The lease period information of the IP address; -
Re-login to the
DHCP client every time you re-login to the network, you do not need to send DHCPDiscover information, but directly send the DHCP Request request information containing the IP address assigned the previous time -
Renewal of lease
When the lease period of the IP address leased by the DHCP server to the client reaches 50%, the lease needs to be renewed. The
client directly sends a DHCP Request packet to the server that provides the lease, requesting to renew the existing address lease.
DHCP dynamically configures the host address
- DHCP service
- Automatically allocate addresses for a large number of clients and provide centralized management
- Reduce management and maintenance costs and improve network configuration efficiency
- The address information that can be allocated mainly includes
- The IP address and subnet mask of the network card
- Corresponding network address, broadcast address
- Default gateway address
- DNS server address
Configure DHCP server
- Simulated by eNSP and ConteOS7
Virtual machine settings
- eNSP settings
- At this time, you can test whether the virtual machine and eNSP can communicate
Install dhcp software
-
Via yum install -y dhcp
-
Or mount the CD image to install through the package in the CD
-
rpm -ivh dhcp-4.2.5-58.el7.centos.x86_64.rpm
Configure the /etc/dhcp/dhcpd.conf file
-
After installation, there will be a dhcp file directory generated in /etc
-
The vim dhcpd.conf file configuration will show that it tells you the location of the template file
-
cd /usr/share/doc/dhcp-4.2.5/
-
Copy cp dhcpd.conf.example /etc/dhcp/dhcpd.conf to the file location indicated
-
vim dhcpd.conf
-
default-lease-time 21600; #The default lease is about 6 hours, in seconds
-
max-lease-time 43200; #The maximum lease is about 12 hours, in seconds
-
option domain-name “benet.com”; #Specify the default domain name
-
option domain-name-servers 8.8.8.8; #Specify DNS server address
-
ddns-update-style none; #disable DNS dynamic update
-
subnet 192.168.100.0 netmask 255.255.255.0{
range 192.168.100.10 192.168.100.20;
option routers 192.168.100.254;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.120;
option routers 192.168.1.254;
}
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.200 192.168.2.220;
option routers 192.168.2.254;
}
- systemctl restart dhcpd #Restart the service
There is a problem with editing the /etc/dhcp/dhcpd.conf file and an error is reported when the service is restarted
vim /var/log/messages View log error content
- netstat -naup | grep 67 #Check whether port 67 of the DHCP server is open
Configure eNSP
- ipconfig /release #release ip
- ipconfig /renew #Re-obtain ip
Add a new PC to specify its ip address
-
Set the port to divide him into vlan10
-
host hostname { hardware ethernet 54:89:98:BE:02:17; fixed-address 192.168.1.105; } #The following content can be deleted
- systemctl restart dhcpd #Restart the service
- ipconfig /release #release ip
- ipconfig /renew #Re-obtain ip
- systemctl stop firewalld
- setenforce 0 ############# may be unsuccessful and need to turn off the firewall
Linux client uses DHCP to dynamically obtain IP
- method 1
- vim /etc/sysconfig/network-scripts/ifcfg-ens33
- BOOTPROTO=dhcp
ifdown ens33 ; ifup ens33 - Method 2
- dhclient -d ens33