All Products
Search
Document Center

:DHCP configuration check and repair for local network interface controller of Linux instances

Last Updated:Oct 21, 2024

Introduction

By default, ECS instances use Dynamic Host Configuration Protocol (Dynamic Host Configuration Protocol) to automatically assign IP addresses to Elastic Network Interface and obtain the lease expiration time. Normally, the dhclient process of your Linux instance updates the lease expiration time to the DHCP server regularly to ensure the availability of the instance IP address. The DHCP service may be abnormal for Linux instances in the following situations and cause instance network disconnection:

  • Network interface controller configuration file error

  • The dhclient process for network interface controller is not running.

This article describes how to check the DHCP configuration of the local network interface controller and how to fix the exception.

Background

Note

Alibaba Cloud reminds you that:

  • Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.

  • You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.

  • If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.

  1. Remotely connect to the Linux instance. For more information about how to log on remotely, see Connect to a Linux instance by using a password or key.

    Note

    If you cannot log on to a Linux instance by using SSH, see Connect to an instance by using VNC.

  2. To avoid data security risks caused by misoperations, we recommend that you back up your ECS instance through a snapshot. For more information about how to create a snapshot, see Create a snapshot.

  3. Run the following command to check and record the existing network interface controller in the Linux instance.

    ls -al /sys/class/net/

    The system displays the following figure, in which eth0 is the network interface controller. Following is a local network interface controller, for example, if you are the ECS instances added auxiliary Elastic Network Interface network interface controller, to the actual situation of the subject.

  4. If a Linux instance so that you can only a local network interface controller, continue with the following steps to check. If multiple network interface controller on a Linux instance, follow step 5 to Step 8 to check and fix each network interface controller.

  5. Run the following command in a Linux instance to check the configuration file of the network interface controller.

    cat /etc/sysconfig/network-scripts/ifcfg-[$Eth]
    Note

    Note:[$Eth] indicates the local network interface controller name. Replace it with the network interface controller name to be checked onsite, for example, eth0.

    The system displays the following information, where BOOTPROTO=dhcp indicates that the network interface controller obtains an IP address by using DHCP.

    # Created by cloud-init on instance boot automatically, do not edit.
    # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
    # For more information, please refer to: https://www.alibabacloud.com/help/en/doc-detail/57803.htm
    #
    BOOTPROTO=dhcp
    DEVICE=[$Eth]
    ONBOOT=yes
    STARTMODE=auto
    TYPE=Ethernet
    USERCTL=no

    Handle the problem according to the following conditions:

    • The local network interface controller obtains the IP address using a non-DHCP method. Confirm the reason for changing the IP address obtaining method with the server administrator. If you do not need to use DHCP to obtain the IP address, skip this article.

    • The local network interface controller obtains the IP address through DHCP Please refer to the above-mentioned network interface controller configuration file to confirm that your Linux instances in the network interface controller configuration file does not exist spelling error on to the next step.

  6. In a Linux instance so that you can execute the following command and examine the corresponding network interface controller of dhclient process running status.

    ps aux | grep dhclient | grep [$Eth]

    Handle the problem according to the following conditions:

    • If the system returns the dhclient process corresponding to the network interface controller, the DHCP service of the network interface controller is normal.

      Note

      Note: Take the eth0 network interface controller as an example, the site is subject to the actual situation.

    • If no result is returned, the dhclient process is not running. Continue.

  7. In a Linux instance so that you can execute the following command restart corresponding network interface controller of dhclient process.

    ifup [$Eth]

  8. Re-run the following command to confirm the corresponding to the network interface controller of dhclient process running state

    ps aux | grep dhclient | grep [$Eth]

Documentation

Application scope

  • Elastic Compute Service