Linux delves into DHCP and relay services

catalogue

 

1, DHCP service foundation

1.1.DHCP service overview

1.2. Advantages of DHCP

1.3.DHCP allocation method

1.4.DHCP lease process

1.4.1 client request IP address

1.4.2 server response

1.4.3. Client select IP address

1.4.3 server lease determination

1.4.4 re login

1.4.5 renewal of lease

2, DHCP dynamic configuration host address

2.1.DHCP service

2.2. The assignable address information mainly includes

2.3. The experimental steps of configuring DHCP service are as follows

2.3.1 troubleshooting

2.3.2. View dhcpd assigned lease time

2.3.3. View dhcpd logs

2.3.3. Grab bag

2.3.4. Install the bag capturing tool

2.3.5 viewing the allocation status of dhcp clients

3, Implement DHCP relay service

3.1. Experimental network topology

3.2. step

         3.2.1. Configure devices on the ensp simulator

         3.2.2.DHCP server configuration

3.2.3 verify whether the network adapter is added successfully

3.2.4 configuring network card information

3.1.5. Verify whether the network card information is configured successfully

1, DHCP service foundation

1.1.DHCP service overview

Dynamic Host Configuration Protocol, a protocol specially used to automatically assign TCP/IP parameters to computers in TCP/IP networks

1.2. Advantages of DHCP

  • Reduce administrator workload
  • Avoid the possibility of input errors
  • Avoid IP address conflicts
  • The IP address of each user segment does not need to be reconfigured when the IP address of each user segment is changed
  • Improved IP address utilization
  • Convenient client configuration

1.3.DHCP allocation method

  • Automatic assignment: permanently used after being assigned to an IP address
  • Manual assignment: the DHCP server administrator specifies the IP address specifically
  • Dynamic allocation: release the IP after use for use by other clients

1.4.DHCP lease process

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

There are four steps:

            

1.4.1 client request IP address

  • When a DHCP client starts, the client does not have an IP address, so the client needs to obtain a legal address through DHCP.
  • At this time, the DHCP client sends DHCP Discover information by broadcasting to find the DHCP server

                           

1.4.2 server response

● when the DHCP server receives the information from the client requesting the IP address, it will find out whether there is a legal IP address provided to the client in its own P address pool

● if yes, the DHCP server marks this IP address, adds it to the DHCP Offer message, and then broadcasts a DHCP Offer message

1.4.3. Client select IP address

● the DHCP client extracts the IP address from the first DHCP Offer message received, and the DHCP server that sends the IP address reserves the address, so that the address cannot be assigned to another DHCP name.

 

1.4.3 server lease determination

● after receiving the DHCP Request message, the DHCP server broadcasts a successful confirmation to the client in the form of DHCPACK message, which contains the valid lease of IP address and other configurable information.

● when the client receives the DHCPACK message, configure the lP address to complete the initialization of TCP/IP

1.4.4 re login

● each time ODHCP client logs in to the network again, it does not need to send DHCPDiscover information, but directly send DHCP Request information including the IP address assigned last time

 

1.4.5 renewal of lease

● when the lease term of the IP address leased by the DHCP server to the client reaches 50%, the lease needs to be updated

● the client directly sends a DHCP Request package to the server providing the lease to update the existing address lease

 

Note: when the host is assigned a network segment address of 169.254.0.0, it indicates that DHCP is not assigned to the client. At this time, you should check the DHCP server

2, DHCP dynamic configuration host address

2.1.DHCP service

● automatically assign addresses to a large number of clients and provide centralized management

● reduce management and maintenance costs and improve network configuration efficiency

2.2. The assignable address information mainly includes

● IP address and subnet mask of network card

● corresponding network address and broadcast address

● default gateway address

● DNS server address

 

2.3. The experimental steps of configuring DHCP service are as follows

Step 1: configure the network card information address as soft connection to facilitate subsequent operations
ln -s /etc/sysconfig/network-scripts/ifcfg-ens33 /root/ens33

Step 2: close the network manager NetworkManager
systemctl stop NetworkManager

Step 4: turn off the firewall
systemctl  stop firewalld

Step 3: Pass yum  Download and install dhcp
yum -y install dhcp

2.3.1 troubleshooting

  • The error message is:

  • Problem Description: the above information shows that the image file cannot be pulled, which means that the external network cannot be connected. ping www.baidu.com Com

  • Check whether the route exists.

  • Default route missing
route add default gw 192.168.1.2 dev ens33
  • Try ping www.baidu.com again com

  • The network has been connected. Download and install again

  • The above query service through rpm -q dhcp has been successfully installed
Step 3: Pass rpm -qc dhcp View profile location
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

Step 4: Pass vim Command open/etc/dhcp/dhcpd.conf Copy in text/usr/share/doc/dhcp*/dhcpd.conf.example
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page

Step 5: transfer/usr/share/doc/dhcp*/dhcpd.conf.example Copy content from to/etc/dhcp/dhcpd.conf
cat  /usr/share/doc/dhcp*/dhcpd.conf.example > /etc/dhcp/dhcpd.conf

Step 6: modify/etc/dhcp/dhcpd.conf stay subnet Add a new code under the last code module subnet
# Subnet is followed by the network segment, netmask is followed by the subnet mask
 subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.3 192.168.1.100; #Web address distribution scope
    option routers 192.168.1.2; # default gateway 
    default-lease-time 600; #Default effective time after allocation
    max-lease-time 7200;     #Maximum effective time
 }


Step 7: start dhcp service
systemctl  start dhcpd

Step 8: View dhcp Service startup status
[root@localhost ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since IV 2021-05-06 09:05:49 CST; 56s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 77007 (dhcpd)
   Status: "Dispatching packets..."
    Tasks: 1
   CGroup: /system.slice/dhcpd.service
           └─77007 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid


2.3.2. View dhcpd assigned lease time

 

 

2.3.3. View dhcpd logs

less -m /var/lib/dhcpd/dhcpd.leases

2.3.3. Grab bag

The predecessor of dhcp is bootp

2.3.4. Install the bag capturing tool

yum -y install wireshak*

2.3.5 viewing the allocation status of dhcp clients

 

3, Implement DHCP relay service

 

3.1. Experimental network topology

 

 3.2. step

       3.2.1. Configure devices on the ensp simulator

  • The configuration of PC2 and PC3 is the same

  • cloud1 is configured as follows

You need to perform the following operations on the virtual machine first

Add network adapter

Then configure could1 as follows

sw1:

sys  #Enter the system
sys sw1
vlan b 10 20 30  #Create vlan 10 20 30
#The following is the vlan setting for the interface
int e0/0/2
p l a
p d v 10 
int e0/0/3
p l a
p d v 20
int e0/0/4
p l a
p d v 30
int e0/0/1
p l t
p t a v a

RW1:

sys
sys RW1
dhcp enable
vlan b 10 20 30 
int g0/0/1
p l t
p t a v a
int vlanif 10
ip add 192.168.10.254 24
  dhcp select relay
  dhcp relay server-ip 192.168.1.20
int vlanif 20
ip add 192.168.20.254 24
  dhcp select relay
  dhcp relay server-ip 192.168.1.20
int vlanif 30
ip add 192.168.1.2 24
  

 3.2.2.DHCP server configuration

  yum -y install dhcp

3.2.3 verify whether the network adapter is added successfully

Verify with the command ifconfig -a

3.2.4 configuring network card information

Step 1: cp -a /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens37
 Step 2: vim /etc/sysconfig/network-scripts/ifcfg-ens37
 Step 3: set network card information
 TYPE=Ethernet
 BOOTPROTO=static
 NAME=ens37
 DEVICE=ens37
 ONBOOT=yes
 IPADDR=192.168.2.2
 GATWAY=192.168.2.254
 #DNS1=114.114.114.114
 Step 4: save
 Step 5: restart the network card
  systemctl restart network
 Step 6: close linux Own network manager to avoid interference
  systemctl stop NetworkManager
 Step 7: set the startup and self startup of the network manager to off state
  systemctl disable NetworkManager

3.1.5. Verify whether the network card information is configured successfully

Execute: ifconfig command to view

3.1.6. Set dhcp profile

Step 3: Pass rpm -qc dhcp View profile location
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

Step 4: Pass vim Command open/etc/dhcp/dhcpd.conf Copy in text/usr/share/doc/dhcp*/dhcpd.conf.example
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page

Step 5: transfer/usr/share/doc/dhcp*/dhcpd.conf.example Copy content from to/etc/dhcp/dhcpd.conf
cat  /usr/share/doc/dhcp*/dhcpd.conf.example > /etc/dhcp/dhcpd.conf

Step 6: modify/etc/dhcp/dhcpd.conf stay subnet Add a new code under the last code module subnet
# Subnet is followed by the network segment, netmask is followed by the subnet mask
 subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.3 192.168.1.100; #Web address distribution scope
    option routers 192.168.1.2; # default gateway 
    default-lease-time 600; #Default effective time after allocation
    max-lease-time 7200;     #Maximum effective time
 }

 subnet 192.168.20.0 netmask 255.255.255.0 {
    range 192.168.20.3 192.168.20.100; #Web address distribution scope
    option routers 192.168.20.254; # default gateway 
    default-lease-time 600; #Default effective time after allocation
    max-lease-time 7200;     #Maximum effective time
 }
 subnet 192.168.10.0 netmask 255.255.255.0 {
    range 192.168.10.3 192.168.10.100; #Web address distribution scope
    option routers 192.168.10.254; # default gateway 
    default-lease-time 600; #Default effective time after allocation
    max-lease-time 7200;     #Maximum effective time
 }

Step 7: start dhcp service
systemctl  start dhcpd

Step 8: View dhcp Service startup status
[root@localhost ~]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since IV 2021-05-06 09:05:49 CST; 56s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 77007 (dhcpd)
   Status: "Dispatching packets..."
    Tasks: 1
   CGroup: /system.slice/dhcpd.service
           └─77007 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

  

 

 

Keywords: Linux Operation & Maintenance Load Balance ssh dhcp

Added by MikeUK on Wed, 09 Feb 2022 11:18:24 +0200