Configuring an instance to use DHCP instead of a static IP address lets it automatically get a network configuration. This simplifies setup and helps prevent manual configuration errors. Before you create a custom image, you must configure the instance to use DHCP. This ensures that new instances created from the image do not inherit a static IP, which can cause IP address conflicts or network connectivity issues.
Alibaba Cloud Linux
Alibaba Cloud Linux 3
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
Reload all network interface card (NIC) configurations.
sudo nmcli c reloadActivate the NIC.
sudo nmcli d connect eth0
Alibaba Cloud Linux 4
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration file.
Identify the active connection's ID name to find its configuration file.
sudo nmcli connection show --activeNAME UUID TYPE DEVICE eth0 1dd9a779-d327-56e1-8454-c65e2556c12c ethernet eth0 lo 0973d353-93a1-41f8-8b7b-5922ade582c6 loopback loIn this example,
eth0is theNAMEof the active network connection.Determine the path of the network configuration file.
Replace
<id_name>with theNAMEfrom the previous step.sudo find /etc/NetworkManager/system-connections/ -type f -exec grep -l "id=<id_name>" {} \;/etc/NetworkManager/system-connections/1.nmconnectionThe example output shows the file path is
/etc/NetworkManager/system-connections/1.nmconnection.Check the file and ensure that the
methodunder[ipv4]is set toauto.Replace
<network_configuration_file_path>with the path from the previous step.sudo vi <network_configuration_file_path>
Restart the network service.
Reload all NIC configurations.
sudo nmcli c reloadActivate the NIC.
sudo nmcli d connect eth0
Alibaba Cloud Linux 2
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
sudo systemctl restart network
CentOS
CentOS 6
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
sudo service network restart
CentOS 7
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
sudo systemctl restart network
CentOS 8
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
Reload all network interface card (NIC) configurations.
sudo nmcli c reloadActivate the NIC.
sudo nmcli d connect eth0
Ubuntu
Ubuntu 16 and earlier
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/network/interfacesEnsure the file contains the following parameters, then save and exit.
auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp
Restart the network service.
For Ubuntu 14, run
sudo rebootto restart the system and apply the configuration.For other versions, run
sudo systemctl restart networking.
Ubuntu 18 and later
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Determine the active network configuration file path.
ls /etc/netplan/*.yaml | sort/etc/netplan/100-eth0.yaml /etc/netplan/50-cloud-init.yaml /etc/netplan/99-eth0.yamlNetplan applies configurations alphabetically. In this example, the last file,
/etc/netplan/99-eth0.yaml, overrides earlier ones and is the active configuration.Edit the network configuration file.
Replace
<network_configuration_file_path>with the path from the previous step.sudo vi <network_configuration_file_path>Ensure the file contains the following parameters, then save and exit.
network: version: 2 renderer: networkd ethernets: eth0: dhcp4: yes dhcp6: no
Restart the network service.
sudo netplan apply
Debian
Debian 11 and earlier
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/network/interfacesEnsure the file contains the following parameters, then save and exit.
If the
interfacesfile containssource /etc/network/interfaces.d/*, edit the network configuration in/etc/network/interfaces.d/<network_config_file>.auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp
Restart the network service.
sudo systemctl restart networking
Debian 12
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Determine the active network configuration file path.
ls /etc/netplan/*.yaml | sort/etc/netplan/100-eth0.yaml /etc/netplan/50-cloud-init.yaml /etc/netplan/99-eth0.yamlNetplan applies configurations alphabetically. In this example, the last file,
/etc/netplan/99-eth0.yaml, overrides earlier ones and is the active configuration.Edit the network configuration file.
Replace
<network_configuration_file_path>with the path from the previous step.sudo vi <network_configuration_file_path>Ensure the file contains the following parameters, then save and exit.
network: version: 2 renderer: networkd ethernets: eth0: dhcp4: yes dhcp6: no
Restart the network service.
sudo netplan apply
Red Hat
Red Hat 6
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
sudo service network restart
Red Hat 7
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
sudo systemctl restart network
Red Hat 8 and 9
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes TYPE=Ethernet
Restart the network service.
Reload all network interface card (NIC) configurations.
sudo nmcli c reloadActivate the NIC.
sudo nmcli d connect eth0
Red Hat 10
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration file.
Identify the active connection's ID name to find its configuration file.
sudo nmcli connection show --activeNAME UUID TYPE DEVICE eth0 1dd9a779-d327-56e1-8454-c65e2556c12c ethernet eth0 lo 0973d353-93a1-41f8-8b7b-5922ade582c6 loopback loIn this example,
eth0is theNAMEof the active network connection.Determine the path of the network configuration file.
Replace
<id_name>with theNAMEfrom the previous step.sudo find /etc/NetworkManager/system-connections/ -type f -exec grep -l "id=<id_name>" {} \;/etc/NetworkManager/system-connections/1.nmconnectionThe example output shows the file path is
/etc/NetworkManager/system-connections/1.nmconnection.Check the file and ensure that the
methodunder[ipv4]is set toauto.Replace
<network_configuration_file_path>with the path from the previous step.sudo vi <network_configuration_file_path>
Restart the network service.
Reload all NIC configurations.
sudo nmcli c reloadActivate the NIC.
sudo nmcli d connect eth0
SUSE and OpenSUSE
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Modify the network configuration to use DHCP.
Edit the network configuration file.
sudo vi /etc/sysconfig/network/ifcfg-eth0Ensure the file contains the following parameters, then save and exit.
BOOTPROTO='dhcp' STARTMODE='auto'
Restart the network service to apply the configuration.
sudo systemctl restart wicked