Linux network service-DHCP principle and configuration-DHCP relay experiment + theory

1. How DHCP works

1.1, understand the DHCP service

  • DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol)
  • Designed and developed by the Internet task force
  • A protocol specifically used to automatically assign TCP/IP parameters to computers in a TCP/IP network

1.2, the benefits of using DHCP

  • 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

1.3, DHCP allocation 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

1.4, DHCP lease process

The process by which the client obtains an IP address from the DHCP server is called the DHCP lease process

It is divided into four steps:

  • The client searches for the server in the network
  • The server responds to the client
  • The client sends a service request to the target server
  • Server provides services to clients

1.4.1, the client requests an IP address

  • When a DHCP client is started, the client does not have an IP address, so the client must obtain a legal address through DHCP
  • At this time, the DHCP client broadcasts the DHCP Discover to find the DHCP server

Insert picture description here

1.4.2, server response

  • When the DHCP server receives the information requesting the IP address from the client, it searches its own IP address pool to find out whether there is a legal IP address provided to the client
  • If so, the DHCP server will mark the IP address, add it to the DHCPOffer message, and then broadcast it—the DHCP Offer message

Insert picture description here

1.4.3, the client selects the IP address

  • The DHCP client extracts the IP address from the first DHCP Offer message received, and the DHCP server that issued the IP address reserves the address so that the address cannot be allocated to another DHCP client

Insert picture description here

1.4.4, the server determines the lease

  • After receiving the DHCP Request message, the DHCP server broadcasts a successful confirmation to the client in the form of a DHCPACK message, which contains a valid lease of the IP address and other configurable information
  • When the client receives the DHCP ACK message, configure the IP address and complete the initialization of TCP/IP

Insert picture description here

1.4.5, re-login

  • Each time the DHCP client logs on to the network again, it does not need to send DHCPDiscover information, but directly sends the DHCP Request request information containing the IP address assigned the previous time.

Insert picture description here

1.4.6, renew the lease

  • When the lease period of the IP address leased by the DHCP server to the client reaches 50%, the lease must be renewed
  • The client directly sends a DHCP Request packet to the server providing the lease, requesting to renew the existing address lease

Two, DHCP server configuration

2.1. Use DHCP to dynamically configure the host address

  • DHCP service
    1. Automatically allocate addresses for a large number of clients and provide centralized management
    2. Reduce management and maintenance costs and improve network configuration efficiency

  • The address information that can be allocated mainly includes
    1, the IP address of the network card, the subnet mask
    2, the corresponding network address, the broadcast address
    3, the default gateway address
    4, the DNS server address

2.2, the main configuration file

2.2.1 The content of dhcpd.conf

Insert picture description here

2.2.2, global configuration, acting on the entire DHCP server

  • ddns-update-style none; ## Prohibit dns dynamic update

  • default-lease-time 21600; ## Default lease term

  • max-lease-time 43200; ## Maximum lease term

  • option domain-name “domain.org”; ## Specify domain name

  • option domain-name-servers 202.106.0.20; ## Assign dns address

2.2.3, Subnet network segment statement, acting on the entire subnet segment

  • Range parameter: Set the P address pool for allocation
  • option subnet-mask parameter: set the client's subnet mask
  • option routers parameter: set the default gateway address of the client

2.2.4, host host statement, acting on a single host

  • Hardware ethernet parameter: specify the MAC address of the corresponding host
  • fixed-address parameter: specify the IP address reserved for the host

Three, DHCP relay service experiment

3.1. Experimental topology

Insert picture description here

3.2, SW2 configuration

sysname SW2
#
vlan batch 10 20 30

interface Ethernet0/0/1
 port link-type access
 port default vlan 10
#
interface Ethernet0/0/2
 port link-type access
 port default vlan 20
#
interface Ethernet0/0/3
 port link-type access
 port default vlan 30

interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 2 to 4094

3.3, SW1 configuration

sysname RSW1
#
vlan batch 10 20 30

dhcp enable            ###开机自启dhcp服务

interface Vlanif10
 ip address 192.168.10.1 255.255.255.0
un sh
 dhcp select relay
 dhcp relay server-ip 192.168.100.10
#
interface Vlanif20
 ip address 192.168.20.1 255.255.255.0
un sh
 dhcp select relay
 dhcp relay server-ip 192.168.100.10
#
interface Vlanif30
 ip address 192.168.100.1 255.255.255.0
un sh
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094

3.4, server configuration

Insert picture description here

3.5, PC1, PC2 configuration

PC1, 2 enable DHCP service

Insert picture description here
Insert picture description here

3.6, virtual machine configuration

192.168.10.0 network segment

yum -y install dhcpd
在虚拟机进入 vi  /etc/dhcp/dhcpd.conf
在里面添加配置文件
注意!逐个PC添加然后保存退出
192.168.10.1网段的PC:
subnet 192.168.10.0 netmask 255.255.255.0{
    
    
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
option domain-name "www.bdqn1.com";
option domain-name-servers 114.114.114.114,8.8.8.8;
default-lease-time 21600;
max-lease-time 43200;
}
配置完之后
systemctl restart dhcpd  ###配完之后重启一下dhcp服务

Then enter PC1, get and verify
Insert picture description here

192.168.20.0 network segment

192.168.20.1网段的PC:
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;
option subnet-mask 255.255.255.0;
option domain-name "www.bdqn2.com";
option domain-name-servers 114.114.114.114,8.8.8.8;
default-lease-time 21600;
max-lease-time 43200;
}
systemctl restart dhcpd  ###配完之后重启一下dhcp服务

Then enter PC2, get it and verify it

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46563938/article/details/109181056