You may need to manually configure Elastic Network Interfaces (ENIs) for some images used by your instances so that the attached ENIs can be identified by the operating systems. This topic describes how to configure an ENI.

Prerequisites

An ENI is attached to an ECS instance. For more information about how to attach an ENI to an ECS instance, see Attach an ENI.

Background information

You do not need to configure ENIs for the following versions of images used by your instances:
  • CentOS 7.3 64-bit
  • CentOS 6.8 64-bit
  • Windows Server 2008 R2 and later

If your instances are running images that are not included in the preceding list, you must manually configure ENIs for the images.

Procedure

  1. Follow operations in the Preparations section to view and record information of an ENI.
  2. Choose one of the following methods to configure ENIs based on your instance operating systems:
  3. Configure a route for an ENI

Preparations

You must query the attributes of each ENI, including the primary private IP address, subnet mask, default route, and MAC address. You must also pay attention to the relationship between the ENI name and the MAC address in subsequent configurations.

  1. Remotely connect to an ECS instance. For more information, see Overview.
  2. Query the attributes of each ENI, including the primary private IP address, subnet mask, default route, and MAC address.
    • Method 1: Query the attributes in the ECS console.
      1. Log on to the ECS console.
      2. In the left-side navigation pane, choose Network & Security > ENIs.
      3. On the Network Interfaces page, find the target ENIs, and view their Primary Private IP Address and Type/MAC Address(All).
    • Method 2: Run the curl command to query the attributes from the instance metadata. For more information, see Metadata.
      [root@LocalHost ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/
      00:16:3e:12:e7:**/
      00:16:3e:12:16:**/
      [root@LocalHost ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/00:16:3e:12:e7:**/netmask
      255.255.255.0
      [root@LocalHost ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/00:16:3e:12:e7:**/primary-ip-address
      10.0.0.20
      [root@LocalHost ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/00:16:3e:12:e7:**/gateway
      10.0.0.253
    • Method 3: Call the DescribeNetworkInterfaces operation to query the attributes.
    In this example, the responses are as follows:
    eth1 10.0.0.20/24 10.0.0.253 00:16:3e:12:e7:**
    eth2 10.0.0.21/24 10.0.0.253 00:16:3e:12:16:**

Configure ENIs for instances running Aliyun Linux 2

  1. Open the configuration file of an ENI.
    This section uses eth1 as an example.
    vi /etc/systemd/network/60-eth1.network
  2. Press the I key to enter the edit mode and add the configuration information to the ENI configuration file.
    You can choose one of the following configuration information sets based on your actual needs.
    • Scenario 1: Allocate a dynamic IP address for the ENI through DHCP.

      Example:

      [Match]
      Name=eth1 # This indicates the newly configured ENI.
      
      [Network]
      DHCP=yes
      
      [DHCP]
      UseDNS=yes
    • Scenario 2: Allocate a static IP address for the ENI.

      Example:

      [Match]
      Name=eth1 # This indicates the newly configured ENI.
      
      [Network]
      Address=192.168. **. **/24 # This indicates the allocated static IP address and subnet mask.
    Press the Esc key, enter :wq, and then press the Enter key to save and exit the edit mode.
  3. Check the ENI configuration file and confirm the modification.
    cat /etc/systemd/network/60-eth1.network
  4. Run the following command to restart the network service:
    systemctl restart systemd-networkd

Configure ENIs for instances running CentOS or Red Hat

Method 1: Automatically configure ENIs for some instances running CentOS by using multi-nic-util. multi-nic-util supports only images later than CentOS 6.8 or CentOS 7.3.

  1. Download the multi-nic-util tool.
    wget https://image-offline.oss-cn-hangzhou.aliyuncs.com/multi-nic-util/multi-nic-util-0.6.tgz
  2. Decompress the package and install the multi-nic-util tool.
    tar -zxvf multi-nic-util-0.6.tgz
    cd multi-nic-util-0.6
    bash install.sh
  3. Restart the ENI.
    systemctl restart eni.service

Method 2: Manually configure ENIs for instances running CentOS or Red Hat.

  1. Open the configuration file of an ENI.
    This section uses eth1 as an example.
    vi /etc/sysconfig/network-scripts/ifcfg-eth1
  2. Press the I key to enter the edit mode and add the configuration information to the ENI configuration file.
    Example:
    DEVICE=eth1  # This indicates the newly configured ENI.
    BOOTPROTO=dhcp
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=yes
    PEERDNS=no
    IPV6INIT=no
    PERSISTENT_DHCLIENT=yes
    HWADDR=00:16:3e:12:e7:**  # You must use the queried MAC address of the ENI.
    DEFROUTE=no  # This indicates that the ENI is not the default route. To prevent the active default route of the ECS instance from being changed when ENIs configured by ifup are started, do not set eth1 to the default route.
    Press the Esc key, enter :wq, and then press the Enter key to save and exit the edit mode.
  3. Check the ENI configuration file and confirm the modification.
    cat /etc/sysconfig/network-scripts/ifcfg-eth1
  4. Run the service network restart or systemctl restart network command to restart the network service.

Configure ENIs for instances running Ubuntu or Debian

You can perform the following operations on instances running Ubuntu 14.04, Ubuntu 16.04, and Debian:

  1. Open the configuration file of an ENI.
    vi /etc/network/interfaces
  2. Press the I key to enter the edit mode and add the configuration information to the ENI configuration file.
    This section uses eth1 as an example.
    auto eth0
    iface eth0 inet dhcp
    
    auto eth1  # This indicates the newly configured ENI.
    iface eth1 inet dhcp
    Press the Esc key, enter :wq, and then press the Enter key to save and exit the edit mode.
  3. Check the ENI configuration file and confirm the modification.
    cat /etc/network/interfaces
  4. Run the service networking restart or systemctl restart networking command to restart the network service.

You can perform the following operations on instances running Ubuntu 18.04:

  1. Create and edit the configuration file of an ENI.
    This section uses eth1 as an example.
    vi /etc/netplan/eth1-netcfg.yaml
  2. Press the I key to enter the edit mode and add the configuration information to the ENI configuration file.
    This section uses eth1 as an example.
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth1:
          dhcp4: yes
          dhcp6: no
    Press the Esc key, enter :wq, and then press the Enter key to save and exit the edit mode.
    Note Take note of the following points when you edit the configuration file:
    • The configuration file is in the YAML format. Therefore, you must follow the YAML syntax rules when you configure the file.
    • You cannot use tabs for indentation in YAML files. Use the space instead.
    • We recommend that you copy /etc/netplan/99-netcfg.yaml in the default configuration file to avoid format issues.
  3. Check the ENI configuration file and confirm the modification.
    cat /etc/netplan/eth1-netcfg.yaml
  4. Run the netplan apply command to validate the configuration.

Configure ENIs for instances running SUSE or openSUSE

  1. Open the configuration file of an ENI.
    This section uses eth1 as an example.
    vi /etc/sysconfig/network/ifcfg-eth1
  2. Press the I key to enter the edit mode and add the configuration information to the ENI configuration file.
    BOOTPROTO='dhcp4'
    STARTMODE='auto'
    USERCONTROL='no'
    Press the Esc key, enter :wq, and then press the Enter key to save and exit the edit mode.
  3. Check the ENI configuration file and confirm the modification.
    cat /etc/sysconfig/network/ifcfg-eth1
  4. Run the service network restart or systemctl restart network command to restart the network service.

Configure a route for an ENI

  1. Start an ENI.
    1. Run the ifup [ENI name] command to start the dhclient process, and initiate a DHCP request.
      ifup eth1
      ifup eth2
    2. Check the allocation of IP addresses. The result must be the same as the ENI information that you queried in the "Preparations" section.
      [root@ecshost~ ]# ip a
      1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
      2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:16:3e:0e:16:** brd ff:ff:ff:ff:ff:ff
      inet 10.0.0.19/24 brd 10.0.0.255 scope global dynamic eth0
      valid_lft 31506157sec preferred_lft 31506157sec
      3: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:16:3e:12:e7:** brd ff:ff:ff:ff:ff:ff
      inet 10.0.0.20/24 brd 10.0.0.255 scope global dynamic eth1
      valid_lft 31525994sec preferred_lft 31525994sec
      4: eth2:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:16:3e:12:16:** brd ff:ff:ff:ff:ff:ff
      inet 10.0.0.21/24 brd 10.0.0.255 scope global dynamic eth2
      valid_lft 31526009sec preferred_lft 31526009sec
  2. Set the metric parameter of the default route for each ENI in the routing table as needed.
    1. Set the metric parameter.
      ip -4 route add default via 10.0.0.253 dev eth1 metric 1001
      ip -4 route add default via 10.0.0.253 dev eth2 metric 1002
      The preceding commands set metric of eth1 and eth2 as follows:
      eth1: gw: 10.0.0.253 metric: 1001
      eth2: gw: 10.0.0.253 metric: 1002
    2. Check whether the configuration succeeds. Pay attention to whether information of the Gateway and Metric columns is the same as the configured information.
      [root@ecshost~ ]# route -n
      Kernel IP routing table
      Destination Gateway Genmask Flags Metric Ref Use Iface
      0.0.0.0 10.0.0.253 0.0.0.0 UG 0 0 0 eth0
      0.0.0.0 10.0.0.253 0.0.0.0 UG 1001 0 0 eth1
      0.0.0.0 10.0.0.253 0.0.0.0 UG 1002 0 0 eth2
      10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
      10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
      10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
      169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
      169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
      169.254.0.0 0.0.0.0 255.255.0.0 U 1004 0 0 eth2
  3. Create a routing table.
    1. Create a routing table.
      ip -4 route add default via 10.0.0.253 dev eth1 table 1001
      ip -4 route add default via 10.0.0.253 dev eth2 table 1002
      Note We recommend that you keep the name of a routing table the same as the metric value of the default route. This example uses 1001 and 1002.
    2. Check whether the routing table is created.
      [root@ecshost~ ]# ip route list table 1001
      default via 10.0.0.253 dev eth1
      [root@ecshost~ ]# ip route list table 1002
      default via 10.0.0.253 dev eth2
  4. Configure a policy-based route.
    1. Create a policy-based route.
      ip -4 rule add from 10.0.0.20 lookup 1001
      ip -4 rule add from 10.0.0.21 lookup 1002
    2. View routing rules.
      [root@ecshost~ ]# ip rule list
      0: from all lookup local
      32764: from 10.0.0.21 lookup 1002
      32765: from 10.0.0.20 lookup 1001
      32766: from all lookup main
      32767: from all lookup default

What to do next

After the ENI is configured, you can perform the following operations: