All Products
Search
Document Center

:Fix missing IP addresses on CentOS 7 and Windows

Last Updated:Jun 21, 2026

Symptoms

After an ECS instance runs for an extended period without a restart, you may encounter network connectivity issues. Symptoms include a complete network outage or the inability to ping the public IP address and private IP address of the instance.

Cause

When an ECS instance is first launched, the system uses the Dynamic Host Configuration Protocol (DHCP) to automatically assign an IP address to its elastic network interface and obtains a lease expiration time. Under normal conditions, the dhclient process in Linux systems and the DHCP Client service in Windows systems periodically renew this lease with the DHCP server to ensure the IP address remains valid. However, this issue occurs because on instances created from certain CentOS 7 images, the dhclient process may terminate unexpectedly. Additionally, a known issue exists in the DHCP Client service on some Windows Server operating systems. As a result, your instance cannot automatically renew its IP address lease. When the initial lease expires, the private IP address of the instance is released, causing a network failure.

Scope

This article applies to ECS instances that meet the following criteria and use DHCP to automatically assign an IP address to an elastic network interface. No action is required for instances configured with a static IP address.

  • Instances of any type that were created from the following CentOS 7 public images before May 31, 2018, and have not been restarted since November 15, 2018.

    • centos_7_04_64_20G_alibase_20180419.vhd

    • centos_7_04_64_20G_alibase_20180326.vhd

    • centos_7_04_64_20G_alibase_201701015.vhd

    • centos_7_03_64_20G_alibase_20170818.vhd

    • centos_7_02_64_20G_alibase_20170818.vhd

    • centos_7_03_64_40G_alibase_20170710.vhd

    • centos_7_03_64_40G_alibase_20170625.vhd

    • centos_7_03_64_40G_alibase_20170523.vhd

    • centos_7_03_64_40G_alibase_20170503.vhd

  • Instances running the following Windows Server operating systems that were created before November 15, 2018, and have not been restarted since.

    • Windows Server 2008 R2

    • Windows Server 2012 R2

    • Windows Server 2016

    • Windows Server Version 1709

Solutions

Note
  • Before performing high-risk operations, such as modifying an instance or its data, ensure that you have disaster recovery and fault tolerance measures in place.

  • Before you modify the configurations or data of instances such as ECS and RDS, create a snapshot or enable features like RDS log backup.

  • If you have submitted sensitive information such as usernames and passwords on the Alibaba Cloud platform, change them immediately.

Choose one of the following four methods based on your needs.

  • Method 1: Batch fix using Cloud Assistant. This method is suitable for managing multiple instances and is easy to perform from the ECS console.

  • Method 2: Batch fix using a Python SDK script. This method checks instance status and performs automatic fixes across an entire region. This method is for users familiar with scripting.

  • Method 3: Fix using Shell and PowerShell scripts. This method requires you to log on to each ECS instance to apply fixes manually. It is suitable for testing or updating a small number of instances. The scripts are identical to those used in Method 1.

  • Method 4: Manually check network interface cards. This method is suitable for a small number of instances.

Method 1: Batch fix using Cloud Assistant

In this example, Cloud Assistant is used to check and automatically repair an ECS instance. Make sure that your instance has the Cloud Assistant Agent installed. The Cloud Assistant Agent is pre-installed by default on ECS instances that are created after December 1, 2017. For more information, see Cloud Assistant Agent Install Cloud Assistant Agent.

  1. Create a Cloud Assistant command. For detailed instructions, see Create a Cloud Assistant command.

  2. Download the appropriate Shell or PowerShell script and paste its content into the Command Content field in the ECS console.

  3. Select the target ECS instances and run the command. For detailed instructions, see Run a command.

  4. Confirm that the command was executed successfully. For detailed instructions, see View the command result and status. The following examples show the command output for CentOS and Windows instances.

    [INFO] [2019-04-28 11:13:00] start check and fix
    [INFO] [2019-04-28 11:13:00] log file /tmp/dhcp_fix_20190428-11:13:00.log
    [INFO] [2019-04-28 11:13:00] start checking eth0
    [INFO] [2019-04-28 11:13:00] eth0 state is up
    [INFO] [2019-04-28 11:13:00] ip a show dev eth0
    [INFO] [2019-04-28 11:13:00] eth0 valid_lft 315359644
    [INFO] [2019-04-28 11:13:00] no need fix, dhclient eth0 is running
    [1;32;40m[SUCCESS] [0m [2019-04-28 11:13:00] check and fix success
    [1;32;40m[SUCCESS] [0m [2019-04-28 11:13:00] return code: 0
    [1;33;40m[WARN] [0m [2019-04-28 11:14:17] need fixing eth0
    [INFO] [2019-04-28 11:14:17] start fixing eth0
    [INFO] [2019-04-28 11:14:17] ip a show dev eth0
    [INFO] [2019-04-28 11:14:17] ifup eth0
    RTNETLINK answers: File exists
    [INFO] [2019-04-28 11:14:19] ip a show dev eth0
    [INFO] [2019-04-28 11:14:19] ok, dhclient eth0 is running now
    [1;32;40m[SUCCESS] [0m [2019-04-28 11:14:19] check and fix success
    [1;32;40m[SUCCESS] [0m [2019-04-28 11:14:19] return code: 0
    No ip will expire in recent 500 days. Then no need fix.
    Nic info: \\E2ETesthxxx...xxxterConfiguration.Index=3
    Found one ip will expire in 500 days. We need fixing it!!!
    Fix it now...
    Nic info: \\E2ETesthxxx...xxxpterConfiguration.Index=3
    fix success.
    ]]]]]]]]]]

Method 2: Batch fix using a Python SDK script

This method uses a Python script based on the Cloud Assistant API to check and automatically fix all affected instances within an Alibaba Cloud region. For ECS SDK installation instructions, see the installation guide in the Alibaba Cloud GitHub repository.

Prerequisites

Run the following command to install the required Python SDK dependencies on your local machine or an ECS instance.

pip install alibabacloud_ecs20140526

Procedure

  1. Download the autofix_dhclient.py file to your ECS instance.

  2. Run the following command to execute the script.

    sudo python autofix_dhclient.py <AccessKeyID> <AccessKeySecret> <region-id>
    Note

    You must replace <AccessKeyID>, <AccessKeySecret>, and <region-id> in the command.

    • AccessKey ID: The AccessKey ID of your Alibaba Cloud account or RAM user.

    • AccessKey Secret: The AccessKey Secret of your Alibaba Cloud account or RAM user.

    • region ID: The region ID where your instance is located. For a list of region IDs, see Regions and zones.

Results

The following is an example of the script output.

Performing the scan and this will take some time, please wait...
Scan done.
Instance Status details:
+----------------------------+----------------+---------------+---------------+
|        InstanceID          | Cloud Assistant|    NeedFix    |   FixResult   |
+----------------------------+----------------+---------------+---------------+
|  i-uf639pxxxye4ldb         |   Installed    |      No       |   NoChange    |
+----------------------------+----------------+---------------+---------------+
|  i-uf69mdxxxk6sahw         |   Installed    |      Yes      |   Success     |
+----------------------------+----------------+---------------+---------------+
Summary:
================================
Total instances scanned: 2
Fixed: 1
Unknown: 0
Failed: 0

The output fields are described as follows:

  • Cloud Assistant: This check determines whether the Cloud Assistant Agent is installed on your instance.

    • Installed: The Cloud Assistant Agent is installed.

    • Not Installed: The Cloud Assistant Agent is missing. You can Install Cloud Assistant Agent and then run the script again.

  • NeedFix: This check determines whether the dhclient process or the DHCP Client service requires a fix.

    • Yes: A fix is required. The script automatically completes the task.

    • No: No fix is required.

    • Unknown: The script could not determine the status. You must perform the check manually.

  • FixResult: This field shows the result of the fix.

    • Success: The dhclient process or the DHCP Client service was successfully fixed.

    • Failed: The fix failed.

    • NoChange: No fix was required.

    • Unknown: The script could not determine the result. You must perform the check manually.

Method 3: Fix using Shell or PowerShell scripts

This method requires you to log on to each affected instance and run a script manually. It is suitable for a small number of instances.

Procedure for CentOS instances

  1. Log on to the ECS instance. For more information, see Connection methods.

  2. Download the linux_fix_dhclient.sh script to any directory.

  3. Switch to the directory where the script is located and run the script as the root user.

    sudo bash linux_fix_dhclient.sh
    Note
    • A return code of "0" indicates that the script successfully completed the check and fix.

    • Any other return code indicates that the fix failed.

Procedure for Windows instances

  1. Log on to the ECS instance. For more information, see Connection methods.

  2. Download the win_fix_dhclient.ps1 script to any directory.

  3. Open PowerShell with administrative privileges and run the following command.

    powershell -executionpolicy bypass -file C:\win_fix_dhclient.ps1
    Note

    Note:

    • You need to replace C:\win_fix_dhclient.ps1 with the actual file path.

    • The output "No ip will expire in recent 500 days. Then no need fix." indicates that the DHCP Client service is running normally and no fix is required.

    • The output "Found one ip will expire in 500 days. We need fixing it!!! Fix it now... Fix success." indicates that the DHCP Client service was not running correctly and the script has fixed the issue.

    • Any other output indicates that the fix failed.

Method 4: Manually check network interface cards

This method requires you to manually check and fix the dhclient process (for CentOS instances) or the IP address lease expiration time (for Windows instances) on each network interface card.

Procedure for CentOS instances

  1. Log on to the ECS instance. For more information, see Connection methods.

  2. Run the following command to check all network interface cards on the instance.

    ls -al /sys/class/net/
  3. Run the following command to check whether the eth0 network interface card uses DHCP to obtain its IP address.

    cat /etc/sysconfig/network-scripts/ifcfg-eth0

    The system displays output similar to the following. BOOTPROTO=dhcp indicates that the network interface card uses DHCP to assign an IP address. If an IP address is not assigned by using DHCP, go to Step 7.

    [root@xxx ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    [root@xxx ~]#  grep 'BOOTPROTO=dhcp' /etc/sysconfig/network-scripts/ifcfg-eth0
    BOOTPROTO=dhcp
  4. Run the following command to check the status of the dhclient process for the eth0 network interface card.

    ps aux | grep dhclient | grep eth0
    • An empty output indicates that the dhclient process is not running correctly.

    • If the output is similar to the following, the process is running normally. In this case, proceed to step 7.

      root 15340 0.0 0.3 113372 12788 ? Ss 14:16 0:00 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--eth0.lease -pf /var/run/dhclient-eth0.pid -H izuf****************** eth0
  5. Run the following command to restart the dhclient process.

    ifup eth0
    Note

    This example uses eth0. Replace eth0 with the actual identifier of your network interface card.

  6. Check the status of the dhclient process again to confirm it is running.

  7. Repeat steps 3 through 6 to check and fix the dhclient process for all remaining network interface cards.

Procedure for Windows instances

  1. Log on to the ECS instance. For more information, see Connection methods.

  2. Open Command Prompt (CMD) as an administrator.

  3. Run the following command to check whether DHCP Enabled is set to Yes for the network interface card described as Red Hat VirtIO Ethernet Adaptor and to view its Lease Expires time.

    ipconfig /all
    Note

    The Red Hat VirtIO Ethernet Adaptor serves as the primary network interface card or secondary elastic network interface for the ECS instance. Custom configurations such as VPN or loopback adapters are not affected. Network interface cards that do not have the DHCP service enabled are also not affected.

  4. If the lease expires within a year, run the following command to renew it.

    ipconfig /renew
  5. Run the ipconfig /all command. A lease expiration time within ten years indicates that the fix is complete.

Applies to

  • ECS