Linux_RHCE self-study teaching notes - Redhat 8.2 DHCP service teaching and Research Notes

DHCP - Dynamic Host Configuration Protocol Dynamic Host Configuration Protocol: A range of IP addresses is controlled by the server, and clients can automatically get the IP addresses and subnet masks assigned by the server when they log on to the server.
Service Port: UDP 67-Response 68-Request;
This protocol is often used in large local area network environments. Its main function is to centrally manage and assign IP addresses, to dynamically obtain IP addresses, Gateway addresses, DNS server addresses and other information for hosts in the network environment, and to increase the usage of addresses.

working process

  • Discovery phase: DHCP clients look for DHCP servers by sending DHCP Discover messages. Since the IP address of DHCP servers is unknown to clients, DHCP clients broadcast DHCP Discover messages and all DHCP receives them.DHCP servers for Discover messages send response messages from which DHCP clients can know the location of DHCP servers in the network.

  • Provision phase: DHCP servers that receive DHCP Discover messages in the network will select an appropriate IP address from the address pool, connect IP address lease time and other configuration information to send DHCP clients through DHCP Offer messages;

  • Selection phase: If more than one DHCP server responds to a DHCP Offer message to a DHCP client, the DHCP client receives only the first received DHCP Offer message, and then broadcasts a DHCP Request request message containing Option 54, the IP address information of the DHCP server it has selected;
    DHCP Request request message is sent broadcasting to notify all DHCP servers that it chooses the IP address provided by the DHCP server identified in Option 54 and that other DHCP servers can reuse the IP address provided for fragmentation.

  • Confirmation phase: When a DHCP server receives a DHCP Request message answered by a DHCP client, the DHCP server looks for a lease record based on the MAC address carried in the DHCP Request message and, if so, sends a DHCP to the client containing the IP address it provides and other settingsACK message to detect if a host uses an IP address assigned by the server and if no response is received within the specified time, the client uses the address.
    If the DHCP server does not find the corresponding lease record after receiving the DHCP Request message, or if for some reason it is unable to assign the IP address properly, send the DHCP NACK message as a response to inform the DHCP client that the IP address cannot be assigned and the DHCP client needs to resend the DHCP Discover message to request a new IP address.

DHCP Client Send Packet Special:

  • SIP: 0.0.0.0
  • DIP: 255.255.255.255
  • Broadcast message

1. Installation Services

[root@localhost ~]# dnf install -y dhcp-server
Complete!

[root@localhost ~]# rpm -qc dhcp-server
/etc/dhcp/dhcpd.conf			/Main Profile
/etc/dhcp/dhcpd6.conf			/IPv6 configuration file
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

[root@localhost ~]# rpm -qa dhcp-server
dhcp-server-4.3.6-40.el8.x86_64

2. Profiles

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page

[root@localhost ~]# cat /usr/share/doc/dhcp-server/dhcpd.conf.example
#ddns-update-style none;/ DNS Interactive Update Mode
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;						/Default lease time 600 s;
max-lease-time 7200;						/Maximum lease time 7200 s;

subnet 10.152.187.0 netmask 255.255.255.0 {
}

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

subnet 10.5.5.0 netmask 255.255.255.224 {		/Declare segments and masks;
  range 10.5.5.26 10.5.5.30;					/Declare address pool;
  option domain-name-servers ns1.internal.example.org;	/statement DNS IP Address;
  option domain-name "internal.example.org";	/statement DNS;
  option routers 10.5.5.1;						/Declare the gateway address;
  option broadcast-address 10.5.5.31;			/Declare broadcast address;
  default-lease-time 600;						/Default lease time 600 s;
  max-lease-time 7200;						/Maximum lease time 7200 s;
}

host passacaglia {							/fixed IP Address configuration;
  hardware ethernet 0:0:c0:5d:bd:95;			/Physical address;
  filename "vmunix.passacaglia";				/File name;
  server-name "toccata.example.com";			/Server name;
}

host fantasia {								/fixed IP Address configuration;
  hardware ethernet 08:00:07:26:c0:a5;			/Physical address;
  fixed-address fantasia.example.com;			/Fixed allocation IP Address;
}

class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}
ignore client-updates;						/Ignore client updates

3. Service Configuration

(1) Single Segment dhcp Service

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
ignore client-updates;
default-lease-time 2000;
max-lease-time 5000;
option routers 192.168.14.2;
option domain-name "example.org";
option domain-name-servers 114.114.114.114,8.8.8.8;
subnet 192.168.14.0 netmask 255.255.255.0{
        range 192.168.14.20 192.168.14.30;
}
[root@localhost ~]# systemctl restart dhcpd

(2) Multi-segment dhcp service

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
ignore client-updates;
default-lease-time 2000;
max-lease-time 5000;
option domain-name "example.org";
option domain-name-servers 114.114.114.114,8.8.8.8;
subnet 192.168.14.0 netmask 255.255.255.0{
        range 192.168.14.20 192.168.14.30;
option routers 192.168.14.2;
}
subnet 192.168.15.0 netmask 255.255.255.0{
        range 192.168.15.20 192.168.15.30;
option routers 192.168.15.2;
}
[root@localhost ~]# systemctl restart dhcpd

(3) Fixed IP address configuration

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
host xxx {								/The red position can be left unconfigured and not repeated.;
    hardware ethernet 00:0C:29:7F:32:06;
    fixed-address 192.168.40.250;
 }
[root@localhost ~]# systemctl restart dhcpd

Keywords: Linux TCP/IP

Added by GetPutDelete on Sun, 19 Sep 2021 07:55:30 +0300