Cloud servers typically have the ability to flexibly bind and unbind IP addresses, hence these are not fixed in the network properties but are automatically assigned via DHCP (Dynamic Host Configuration Protocol). When a user's incorrect manipulation of the network properties leads to connectivity issues with the cloud server, it becomes necessary to reconfigure DHCP. This article explains how to set up DHCP on various Linux operating systems.
Begin by inspecting the current network configuration file. Execute the following command to view it.
# ls /etc/sysconfig/network-scripts/ifcfg-*
ifcfg-eth0   ifcfg-loThe result shows that the current network adapter is named eth0. Next, edit this configuration file.
# nano /etc/sysconfig/network-scripts/ifcfg-eth0Replace the file with the content below, substituting eth0 with the actual network adapter name.
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
NM_CONTROLLED="no"
IPV6_AUTOCONF="yes"
IPV6INIT="yes"
NOZEROCONF="yes"Be sure to delete any static route files in the system, then restart the network or reboot the operating system.
# rm /etc/sysconfig/network-scripts/route-eth0 -f
# service network restartFirst, inspect the current network configuration file. Execute the following command to view it.
# ls /etc/sysconfig/network-scripts/ifcfg-*
ifcfg-enp1s0The result shows the network adapter named as enp1s0. Next, edit this configuration file.
# nano /etc/sysconfig/network-scripts/ifcfg-enp1s0Replace the file with the content below, substituting enp1s0 with the actual network adapter name.
TYPE="Ethernet"
DEVICE="enp1s0"
ONBOOT="yes"
BOOTPROTO="dhcp"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"Restart the network or reboot the operating system. The command to restart the network is as follows, replace enp1s0 with the actual network adapter name.
# nmcli con load /etc/sysconfig/network-scripts/ifcfg-enp1s0
# nmcli con up 'System enp1s0'First, inspect the current network configuration file. Execute the following command to view it.
# ls /etc/netplan/
10-enp1s0.yamlThe result shows the network adapter named as enp1s0. Next, edit this configuration file.
# nano /etc/netplan/10-enp1s0.yamlReplace the file with the content below, substituting enp1s0 with the actual network adapter name. Note that YAML files require proper indentation, so pay attention to the format while editing.
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: yesRestart the network or reboot the operating system.
# netplan applyEdit the network configuration file.
# nano /etc/network/interfacesReplace the file with the content below, substituting enp1s0 at three places with the actual network adapter name.
# This file describes the network interfaces available on your system
#source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug enp1s0
iface enp1s0 inet dhcp
iface enp1s0 inet6 autoRestart the network or reboot the operating system.
systemctl restart networking.serviceExecute the following command to reset the network properties to DHCP, replacing enp1s0 at three places with the actual network adapter name.
nmcli connection modify enp1s0 ipv4.method auto
nmcli connection down enp1s0
nmcli connection up enp1s0Edit the network configuration file.
# vi /etc/rc.confReplace the file with the content below, substituting 'example' with the actual hostname, and 'vtnet0' with the actual network adapter name.
hostname="example"
sshd_enable="YES"
ntpd_enable="YES"
static_routes="linklocal"
devmatch_blacklist="virtio_random.ko"
sendmail_submit_enable="NO"
ifconfig_vtnet0="DHCP"Reboot the operating system.
# reboot23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58