You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Images
Enabling DHCP service in Linux image
Copy page
Download PDF
Enabling DHCP service in Linux image
This topic describes how to enable the DHCP service on the Linux operating system.​
About DHCP​
Dynamic Host Configuration Protocol (DHCP) is a network protocol used to automatically assign IP addresses, subnet masks, default gateways, and other network configuration information to network devices.​
When a device connects to a network, it sends a request to a DHCP server to obtain the IP address and other configuration information. The DHCP server then assigns an appropriate IP address and other configuration information to the device based on its configured policies and available IP address pool.​
Applicable scenario​
If your ECS instance or locally stored image uses a static IP address, you must enable DHCP in the image before creating a custom image from the ECS instance or by importing the image. Otherwise, the custom image created may fail to obtain a dynamic IP address.​
Procedure​
  1. Enable the DHCP service.​
  • CentOS Stream 8/9, CentOS 6.x/7.x/8.x, Fedora 33/34/35, Rocky Linux, and AlmaLinux​
  1. Execute the following command in the instance to view the network interface alias.​
  • ​
    ifconfig​
    ​
  • Sample output​
  • ​​​
  1. Execute the following command in the instance to open the network configuration file.​
Replace eth0 in the command with the name of the actual network interface. In the example provided in this topic, eth0 is used.​
  • ​
    vim /etc/sysconfig/network-scripts/ifcfg-eth0 ​
    ​
  1. Press i to enter edit mode, and change the value of the BOOTPROTO parameter to dhcp.​
Replace eth0 with the name of the actual network interface. In the example provided in this topic, eth0 is used.​
  • ​
    BOOTPROTO=dhcp​
    ​
  1. Press the Esc key, enter :wq, and press Enter to save and exit the file.​
  1. Execute the following command to restart the network service.​
  • CentOS 8.x and Fedora 33/34/35​
  • ​
    nmcli c reload​
    nmcli d connect eth0​
    ​
  • CentOS 7.x, CentOS Stream 8/9, Rocky Linux, and AlmaLinux​
  • ​
    systemctl restart network​
    ​
  • CentOS 6.x​
  • ​
    service network restart​
    ​
  • Ubuntu 16 and Debian 9/10/11​
  1. Execute the following command in the instance to view the network interface alias.​
  • ​
    ip addr​
    ​
  • Sample output​
  • ​​​
  1. Execute the following command to open the network configuration file.​
  • ​
    vim /etc/network/interfaces​
    ​
  • Sample output​
  • ​​​
  1. Press i to enter edit mode, and modify the target network interface configuration to the following content.​
In the example provided in this topic, eth0 is used. Replace eth0 in the command with the name of the actual network interface.​
  • ​
    auto eth0​
    iface eth0 inet dhcp ​
    ​
  • Example after modification​
  • ​​​
  1. Press the Esc key, enter :wq, and press Enter to save and exit the file.​
  1. Execute the following command to restart the network service.​
  • ​
    systemctl restart networking​
    ​
  • Ubuntu 18/20/22​
  1. Execute the following command in the instance to view the network interface alias.​
  • ​
    ifconfig​
    ​
  • Sample output​
  • ​​​
  1. Execute the following command to open the network configuration file.​
Replace 01-netcfg.yaml in the command with the actual configuration file.​
  • ​
    vim /etc/netplan/01-netcfg.yaml​
    ​
  • Sample output​
  • ​​​
  1. Press i to enter edit mode, and modify the following configuration items.​
In the example provided in this topic, the eth0 network interface is used. Modify the configuration of your actual network interface.​
  • ​
    eth0:​
    dhcp4: yes​
    dhcp6: no​
    ​
  • Example after modification​
  • ​​​
  1. Press the Esc key, enter :wq, and press Enter to save and exit the file.​
  1. Execute the following command to restart the network service.​
  • ​
    netplan apply​
    systemctl restart systemd-networkd​
    ​
  • OpenSUSE 15.4​
  1. Execute the following command in the instance to view the network interface alias.​
  • ​
    ip addr​
    ​
  • Sample output​
  • ​​​
  1. Execute the following command to open the network configuration file.​
Replace eth0 in the command with the actual name of the network interface.​
  • ​
    vim /etc/sysconfig/network/ifcfg-eth0​
    ​
  • Sample output​
  • ​​​
  1. Press the i key to enter edit mode, and modify the values of the BOOTPROTO and STARTMODE parameters.​
  • ​
    BOOTPROTO='dhcp'​
    STARTMODE='auto'​
    ​
  • Example after modification​
  • ​​​
  1. Press the Esc key, enter :wq, and press Enter to save and exit the file.​
  1. Execute the following command to restart the network service.​
  • ​
    systemctl restart wicked​
    ​
  1. At this point, you have enabled the DHCP service in the Linux image. Then, you can create a custom image (Linux) from the instance or import the custom image.​
Last updated: 2026.06.18 17:49:52