Linux:DHCP Server Setup

Understanding how the DHCP protocol works

DHCP (Dynamic Host Configuration Protocol) provides the ability to dynamically configure IP addresses.In a DHCP network, clients no longer need to enter network parameters themselves, but are automatically assigned to clients by the DHCP server.

IP Address Rental Process

IP Lease Request

IP Rental Provision

IP Lease Selection

IP Rental Confirmation

Processing after getting IP address
IP Processing on Client Relogin

Each time a DHCP client logs on to the network again, instead of sending DHCP Discover information, it sends DHCP Request request information directly containing the IP address previously assigned.

Renewal of IP Address

DHCP's lease term generally defaults to 8 days, and DHCP clients must renew the lease before it expires.

Configuring DHCP services

Planning IP Address Segment
Determines the range of IP addresses that the DHCP server should distribute to clients.
192.168.10.0/24
192.168.10.100-192.168.10.200
 Determine the correct subnet mask for the client
255.255.255.0
 General Manager's Private Address: 192.168.10.8 (Reserved Address)
Determine all IP addresses that the DHCP server should not distribute to clients.
Determine lease duration for IP addresses
 Gateway address: 192.168.10.254
 DNS server address: 192.168.10.1
Installation and basic configuration of dhcp services
Install DHCP Service
Install DHCP Service
 Execute the "yum install dhcp" command to install. The rpm installation package corresponding to the RHEL6 system is "dhcp.x86_64 12:4.1.1-31.P1.el6".
    Service name: dhcpd
 Main Profile: /etc/dhcp/dhcpd.conf Default Settings as shown in Figure
      
Template file: /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample

The format of the dhcpd.conf configuration file is as follows:
Global parameters
 Declaration {
    Configuration options/local parameters
    Configuration options/local parameters
    ......
}

Configured dhcpd.conf file

option domain-name-servers 192.168.80.1 sets DNS server options, which can be placed in the global section.
Subnet 192.168.80.0 nemask 255.255.255.0 is used to define scopes
 Range 192.168.80.21 192.168.80.254 Specifies the range of IP addresses that can be assigned in the current scope
 Option routers 192.168.80.2 Specifies the gateway for the current scope
 default-lease-time 86400 Default lease time in seconds
 max-lease-time 172800 maximum lease time, typically set to twice the default lease time
Start dhcp service
Service dhcpd start
chconfig --level 35 dhcpd on
Configuration and Test of windows Client
Turn off DHCP function of VMWare virtual network card

Test if you can rent an IP address

Release and reapplication of IP addresses
There are two very important commands related to DHCP services on Windows clients:
ipconfig View basic IP information for this machine
 Ipconfig/all View local IP details 
Ipconfig/release: Release the IP address you have acquired.
Ipconfig/renew: Re-apply for IP address.
The "ipconfig/release" command can actively release an address before the IP lease expires.Executing the "ipconfig/renew" command forces the start of the address request process, enabling clients to regain new IP addresses.
Automatic Private IP Address
Automatic Private Address refers to the address in the 169.254.0.0/16 network segment, which is a temporary alternate address, that is, if the client fails to request an IP address from the DHCP server and is not enabled in the TCP/IP Properties setting
 When Alternate Configuration is used, a temporary address is automatically assigned.
Keep specific IP addresses
The role of preserving IP addresses
The DHCP server can reserve a specific IP address for the specified client, that is, the DHCP server assigns the same IP address to the client each time the client requests an IP address from the DHCP server or updates a lease.
Preserve IP Address Configuration

Option domain-name-servers 192.168.10.1;
Subnet 192.168.10.0 netmask 255.255.255.0{
   Range 192.168.10.20 192.168.10.254;
   Option routers 192.168.10.2;
   Default-lease-time 86400;
   Max-lease-time 172800;
Host teacher{

     Hardware ethernet 00:0C:29:21:98:D6;
     Fixed-address 192.168.10.100;

}
"host teacher",Specify to keep for it IP The client name of the address, which can be set freely, is " teacher". 
"hardware ethernet",Specify the client computer's MAC Address.
"fixed-address",Specify the corresponding reservation IP Address.Yes
Linux Client Configuration
Configure Network Card Profile for Linux Clients
Configure the network card profile for Linux clients: vim/etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT="yes"
BOOTPROTO=dhcp
Restart Network Card
Ifdown eth0
Ifup eth0
View the acquired IP address
Ifconfig
Configuration of multiple scopes
ddns-update-style none;
option domain-name-servers 192.168.10.1;

subnet 192.168.10.0 netmask 255.255.255.0 {
  range 168.20.0 netmask 255.255.255.0 {
  range 192.168.10.100 192.168.10.200;
  option domain-name "internal.example.org";
  option routers 192.168.10.1;
  option broadcast-address 192.168.10.255;
  default-lease-time 600;
  max-lease-time 7200;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
  range 168.20.0 netmask 255.255.255.0 {
  range 192.168.20.100 192.168.20.200;
  option domain-name "internal.example.org";
  option routers 192.168.20.1;
  option broadcast-address 192.168.20.255;
  default-lease-time 600;
  max-lease-time 7200;
}
Configure Superscope
What is a superscope?Combine multiple scopes to form a superscope
ddns-update-style none;
shared-network test {
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.100 192.168.10.200;
  option domain-name-servers 192.168.10.1;
  option domain-name "internal.example.org";
  option routers 192.168.10.1;
  option broadcast-address 192.168.10.255;
  default-lease-time 600;
  max-lease-time 7200;
}
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.100 192.168.0.200;
  option domain-name-servers 192.168.0.1;
  option domain-name "internal.example.org";
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  default-lease-time 600;
  max-lease-time 7200;
}
host web {
  hardware ethernet 00:0C:29:9D:EA:33;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
  Fixed-address 192.168.0.110;
}
host DNS {
  hardware ethernet 00:0C:29:9D:EA:33;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
  Fixed-address 192.168.0.110;
}
Configure DHCP Relay Proxy Server
Relay Proxy Server Network Card Address Configuration
eth0:  192.168.10.2
eth1:  192.168.0.1
Configuring static routes on dhcp servers
ip route add 192.168.0.0/24 via 192.168.10.2
Turn on Forwarding on the relay server: vim/etc/sysctl.conf
Modify: net.ipv4.ip_forward=1
 Enable forwarding: sysctl -p
Install dhcp service on relay server
Configure Main Profile
Subnet 192.168.10.0 netmask 255.255.255.0{
   Range 192.168.10.20 192.168.10.254;
   Option routers 192.168.10.2;
   Default-lease-time 86400;
   Max-lease-time 172800;
}
Subnet 192.168.20.0 netmask 255.255.255.0{
   Range 192.168.0.20 192.168.20.254;
   Option routers 192.16820.1;
   Default-lease-time 86400;
   Max-lease-time 172800;
}
Configure Relay Agent
Configure Relay Agent: vim/etc/sysconfig/dhcrelay
 Modify: INTERFACES="eth0 eth1"
     DHCPSERVERS="192.168.10.1"
Restart service: service dhcrelay start

Keywords: Linux network DNS vim

Added by bo0 on Sat, 23 Nov 2019 10:41:55 +0200