Linux_DHCP dynamic configuration host address, stand-alone allocation of fixed IP tutorial!

1. Principle of DHCP

The first step: the client searches for the server in the network, the
client sends a DHCP Discover message by broadcasting to find the server. The
second step: the server responds to the client and the
server sends a unicast DHCP Offer
message to provide the client with an IP address, etc. Network information, select an unassigned IP from the IP address pool and assign it to the client.
Step 3: The client sends a service request to the server.
If multiple DHCP servers send DHCP-offer messages to the client, the client only Accept the first received DHCP-offer message and extract the IP address, and then the client sends a DHCP Request message via broadcast to inform the server to select 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 legally available, and adds the lease information of the IP address in the option field

Insert picture description here

2. Advantages and distribution methods of DHCP

1. Advantages:

●Reduce the workload of the administrator
●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 the utilization of IP addresses
●Convenient client configuration

2. DHCP allocation method

●Automatic allocation: permanent use after being assigned to an IP address
●Manual allocation: designated by the DHCP server administrator]
●Dynamic allocation: releasing the IP after use for other clients to use

3. Basic steps of the experiment

1.yum install dhcp

[root@localhost yum.repos.d]# yum install -y dhcp
2. Find the DHCP configuration template, overwrite the file, and modify the configuration file
[root@localhost dhcp-4.2.5]# cd /etc/dhcp
[root@localhost dhcp]# cd /usr/share/doc/dhcp-4.2.5/
[root@localhost dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes
3. Set global configuration parameters:
option domain-name "kkk.com";   #指定默认域名
option domain-name-servers 8.8.8.8;#指定DNS服务器地址

default-lease-time 600;#默认租约为600,单位为秒
max-lease-time 7200;#最大租约为7200,单位为秒
ddns-update-style none;#禁用DNS动态更新
4. Modify the subet network segment statement
subnet 192.168.80.0 netmask 255.255.255.0 {
    
    	   #首先声明dhcp服务器网段以及子网掩码
  range 192.168.80.10 192.168.80.20;		   #设置ip地址池
  option routers 192.168.80.254;	           #指定默认网关
}
subnet 192.168.1.0 netmask 255.255.255.0 {
    
         #其次声明其他网段以及子网
  range 192.168.1.100 192.168.1.200;           #设置ip地址池
  option routers 192.168.1.254;                #指定默认网关   
}
……
5. Start the DHCP service:
[root@localhost dhcp]# systemctl start dhcpd
[root@localhost dhcp]# netstat -naup | grep 67
udp        0      0 0.0.0.0:67              0.0.0.0:*                           43149/dhcpd         
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1222/dnsmasq        

6. Assign a fixed IP address to the single machine (modify the host host statement)
host hostname {
    
                                    #指定需要分配固定IP地址的客户机名称
  hardware ethernet  xx:xx:xx:xx:xx:xx;        #指定该主机的MAC地址
  fixed-address 192.168.80.100;                #指定保留给该主机的IP地址
}

7. Restart the service
[root@localhost dhcp]# systemctl restart dhcpd
[root@localhost dhcp]# systemctl restart dhcpd
[root@localhost dhcp]# systemctl restart dhcpd

Four. Experiment

1. Settings in the virtual machine

1. Modify the network adapter, select VMnet1, host mode
Insert picture description here2. Enter the network editor, the DHCP setting of VMnet1 is unchecked
Insert picture description here3. Modify the IP address of the machine VMnet1
Insert picture description here
4. Set the network card
Insert picture description here

Insert picture description here

2. Configure in ensp

1. This picture is listed in the ensp
Insert picture description here
2. Enter the cloud to perform the corresponding configuration
Insert picture description here3. The configuration of the two-layer switch sw1:
Insert picture description here
4. The configuration of the three-layer switch sw2:
Insert picture description here

Insert picture description here

3. Configuration

1. Yum installs dhcp
Insert picture description here2. Find the DHCP configuration template, overwrite the file, modify the configuration file
Insert picture description here3. Set the global configuration parameters:
Insert picture description here4. Modify the subet network segment statement:
Insert picture description here
5. Start the DHCP service:
Insert picture description here

4. Configure DHCP relay in ensp

1. Enter sw2 and turn on the relay function:
Insert picture description here
2. pc1 and pc2 set dhcp:
Insert picture description here3. In ensp, pc1 and 2 automatically obtain ip:
Insert picture description here

5. Assign a fixed IP address to the single machine (modify the host host statement)

Insert picture description here

Insert picture description here
Insert picture description hereInsert picture description here

Insert picture description hereEnter the WIN10 virtual machine:
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/113918418