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

Prerequisites

You have attached an ENI to an ECS instance. For more information on how to attach an ENI to an ECS instance, see Attach an ENI.

Background information

If your instance is running one of the following images, you do not need to manually configure their ENIs:
  • CentOS 7.3 64-bit
  • CentOS 6.8 64-bit
  • Windows Server 2008 R2 or later

If your instance is running an image not included in the preceding list, you must manually configure the ENI for the image.

Automatic configuration

If your instance is running a CentOS image, you can download and install the multi-nic-util tool to automatically configure the ENI. This tool supports only images later than CentOS 6.8 and CentOS 7.3.

  1. Remotely connect to an ECS instance. For more information about detailed steps, see Overview.
  2. Run the following command to download the multi-nic-util tool:
    wget https://image-offline.oss-cn-hangzhou.aliyuncs.com/multi-nic-util/multi-nic-util-0.6.tgz
  3. Run the following commands to 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
  4. Run the following command to restart the ENI service:
    systemctl restart eni.service

Manual configuration

This section takes an instance running CentOS 7.2 64-bit as an example to describe how to manually configure ENIs attached to a Linux instance.

  1. Remotely connect to an ECS instance. For more information about detailed steps, see Overview.
  2. Query the attributes of each ENI, including the primary private IP address, subnet mask, default route, and MAC address.
    Examples:
    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:**
    • Call the DescribeNetworkInterfaces operation to query the preceding attributes of the ENIs.
    • Perform the following steps in the ECS console to query the attributes of the ENIs:
      1. Log on to the ECS console.
      2. In the left-side navigation pane, choose Network & Security > ENI.
      3. On the Network Interfaces page, find the target ENIs and view their primary private IP addresses and MAC addresses in the Primary Private IP Address and Type/MAC Address(All) columns.
    • Obtain the attributes of ENIs from instance metadata. For more information, see Metadata.
      [root@LocalHost ~]# curl http://100.100.100.200/latest/meta-data/mac
      00:16:3e:12:e7:**
      [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
  3. Run the cat /etc/sysconfig/network-scripts/ifcfg-[ENI name] command to view the configuration file of each ENI.
    Note
    • To facilitate configuration, take note of the correlation between the ENI name in the operating system and the MAC address.
    • To prevent the active default route of the ECS instance from being changed when ENIs configured by (ifup) are started, do not set the ENI interface to the default route. DEFROUTE=no means the ENI interface is not the default route.
    Example:
    # cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    BOOTPROTO=dhcp
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=yes
    PEERDNS=no
    IPV6INIT=no
    PERSISTENT_DHCLIENT=yes
    HWADDR=00:16:3e:12:e7:**
    DEFROUTE=no
  4. Perform the following steps to start ENIs:
    1. Run the ifup [ENI name in the OS] command to start the dhclient process, and initiate a DHCP request.
      Examples:
      # ifup eth1
      # ifup eth2
    2. After a response is received, run the ip a command to check the IP addresses of the ENIs, which must be the same as the IP addresses of the ENIs displayed in the ECS console.
      Example:
      # 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
  5. Set the default metric parameter for each ENI in the routing table.
    In this example, set the metric parameters for eth1 and eth2:
    eth1: gw: 10.0.0.253 metric: 1001
    eth2: gw: 10.0.0.253 metric: 1002
    1. Run the following commands to set the metric parameters:
      # 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
    2. Run the route -n command to check whether the metric parameters have been set.
      # 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
  6. Perform the following steps to create a routing table:
    Note We recommend that you use the metric value as the routing table name.
    1. Run the following commands to 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
    2. Run the following commands to check whether the routing table has been created:
      # ip route list table 1001
      default via 10.0.0.253 dev eth1
      # ip route list table 1002
      default via 10.0.0.253 dev eth2
  7. Configure a policy-based routing.
    1. Run the following commands to create a policy-based routing.
      # ip -4 rule add from 10.0.0.20 lookup 1001
      # ip -4 rule add from 10.0.0.21 lookup 1002
    2. Run the ip rule list command to view the routing rules.
      # 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 you configure the ENI, you can perform the following operations: