banner
云野阁

云野阁

闲云野鹤,八方逍遥

Setting up a DHCP server

Server Side#

(1) Install dhcp-server online

[root@dncp-103 ~]# yum -y install dhcp-server

(2) Modify the dhcpd service configuration file to complete the setup of the DHCP server

[root@dncp-103 ~]# vi /etc/dhcp/dhcpd.conf
-------------------dhcpd.conf-------------------
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
# Set domain name to "elk.com"
option domain-name     "elk.com";

# Set domain name server to 10.10.2.103
option domain-name-servers    10.10.2.103;

# Declare DHCP Server
# Declare this DHCP server
authoritative;  

# Set default lease time to 600 seconds
default-lease-time 600;
# Set log facility to local4
log-facility local4;
# Set maximum lease time to 7200 seconds
max-lease-time 7200;

# Set Network address, subnet mask and gateway
subnet 10.10.2.0 netmask 255.255.255.0 {
}

# Set IP address range from 10.10.2.202 to 10.10.2.205
subnet 10.10.2.0 netmask 255.255.255.0 {
  range 10.10.2.202 10.10.2.205;
  # Set gateway to 10.10.2.1
  option routers 10.10.2.1;
  # Set subnet mask to 255.255.255.0
  option subnet-mask 255.255.255.0;
  # Set broadcast address to 10.10.2.255
  option broadcast-address 10.10.2.255;
  # Set default lease time to 600 seconds
  default-lease-time 600;
  # Set maximum lease time to 7200 seconds
  max-lease-time 7200;
  # Add other DHCP options here
}
-------------------dhcpd.conf-------------------

(3) Configure the dhcp log path in rsyslog.conf

[root@dncp-103 ~]# vi /etc/rsyslog.conf
-------------------rsyslog.conf-------------------
# Omitted some prompt information for formatting convenience
# Don't log private authentication messages!
# Exclude log messages from local4 facility from /var/log/messages file
*.info;mail.none;authpriv.none;cron.none;local4.none           /var/log/messages
# Log all levels of log messages from local4 facility to /var/log/dhcp/dhcp.log file
local4.* /var/log/dhcp/dhcp.log
# Omitted some prompt information for formatting convenience
-------------------rsyslog.conf-------------------

(4) Start the dhcpd service and restart the rsyslog service to make the configuration effective

# Start the dhcpd service
[root@dncp-103 ~]# systemctl start dhcpd
# Restart the rsyslog service
[root@dncp-103 ~]# systemctl restart rsyslog

(5) Check the status of the dhcpd service

[root@dncp-103 ~]# systemctl status dhcpd

(6) Configure the dhcpd service to start automatically at boot

[root@dncp-103 ~]# systemctl enable dhcpd

(7) Configure the firewall, restart the service to make the configuration effective

# Configure DHCP service access policy to allow normal access
[root@dncp-103 ~]# firewall-cmd --add-service=dhcp --permanent
success
# Reload the firewall policy
[root@dncp-103 ~]# firewall-cmd --reload
success

Client Side#

(1) Check the original IP of the client

[root@dncp-113 ~]# ip a

(2) Change the client's IP to dynamic to verify if the DHCP server can dynamically assign IPs

# Modify the network card configuration file
[root@dncp-113 ~]# vi /etc/NetworkManager/system-connections/ens32.nmconnection
-------------------ens32.nmconnection-------------------
[connection]
id=ens32
uuid=2bb0f492-19e2-37c0-b8fa-1781d3122a83
type=ethernet
autoconnect-priority=-999
interface-name=ens32
timestamp=1713841073

[ethernet]

[ipv4]
# Comment out static IP information
#address1=10.10.2.113/24,10.10.2.1
dns=10.10.2.103;
# Obtain IP address dynamically through DHCP
method=auto

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]
-------------------ens32.nmconnection-------------------

(3) Reload the NetworkManager connection configuration and check the assigned dynamic IP

# Reload the NetworkManager connection configuration
[root@dncp-113 ~]# nmcli c reload
# Connect network interface ens32
[root@dncp-113 ~]# nmcli d connect ens32
Device "ens32" activated successfully with "2bb0f492-19e2-37c0-b8fa-1781d3122a83".
# Check the assigned dynamic IP
[root@dncp-113 ~]# ip a
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.