Binding and Configuring CVMs

Last updated: 2020-10-13 09:32:15

    This document describes how to bind a Linux and Windows CVM.

    Binding a CVM

    1. Log in to the VPC console.
    2. Choose IP and ENI > ENI in the left sidebar to go to the ENI list page.
    3. Locate the ENI you want to configure and bind to a CVM, and click Bind CVM in the Operation column.

      Note:

      • ENI can only be bound to CVMs in the same availability zone.
      • ENI cannot be bound to BM (Bare Metal) 2.0.
    4. In the pop-up window, select the CVM to be bound with the ENI and click OK.

      Configuring a CVM

      Configuring a Linux CVM

      This document provides instructions on how to configure ENI on two common server images: CentOS and Ubuntu.

    Configuring ENI on a CentOS CVM

    Configuring ENI on a Ubuntu CVM

    Configuring ENI on a CentOS CVM

    Note:

    The following operations use CentOS 7 or later versions as an example.

    1. Log in to the CVM as the administrator and run the following command to locate the ENI to be configured (IP not shown). As shown in the figure, the ENI to be configured is eth1.

      ip addr

    2. Run the following command to access the /etc/sysconfig/network-scripts/ folder.

      cd /etc/sysconfig/network-scripts/
    3. Create a configuration file such as ifcfg-eth1 for the new ENI.

      1. Run the following command.
        cp ifcfg-eth0 ifcfg-eth1
      2. Run the following command to modify the configuration file.
        vim ifcfg-eth1
      3. Press i to switch to the editing mode and modify the configuration file as follows:

        Note:

        For the methods to view the IP address and subnet mask of the ENI, see the Appendix.

           DEVICE='eth1' # Enter the actual ENI name obtained in step 1.
           NM_CONTROLLED='yes'
           ONBOOT='yes'
           IPADDR='192.168.1.62'  # Enter the actual IP address of the ENI.
           NETMASK='255.255.255.192'  # Enter the actual subnet mask.
           #GATEWAY='192.168.1.1'  # Enter the actual gateway. Since the eth0 file has defined the gateway, do not enter the gateway here to avoid conflict.
        After modification:
      4. Press Esc when you get to the last line of vim, enter wq!, and then press Enter to save and close the configuration file.
    4. Run the following command to restart the network service.

      systemctl restart network
    5. Check and verify the IP configuration.

      1. Run the following command to check the IP address.
        ip addr
      2. Confirm that the secondary ENI and its IP are visible, as shown below:

        If the IP address is incorrectly configured, perform the following checks:
        1. Verify the configuration file. Reconfigure the file if needed.
        2. Confirm whether the network service has restarted. You can run the following command to restart the network for the configuration to take effect.
          systemctl restart network
    6. Configure the routing policy based on actual needs.
      After the preceding configuration, the Linux image still sends packets from the primary ENI by default. In this case, you can configure policy-based routing to specify the ENI through which packets are sent and returned.

      1. Create two route tables.
        echo "10 t1" >> /etc/iproute2/rt_tables
        echo "20 t2" >> /etc/iproute2/rt_tables 

        Note:

        Replace “10” and “20” with the actual route ID, and replace “t1” and “t2” with the actual route table names.

      2. Add default routes for both route tables.
        ip route add default dev eth0 via 192.168.1.1 table 10
        ip route add default dev eth1 via 192.168.1.1 table 20 

        Note:

        The IPs in the above two commands should be replaced with the IP addresses of the subnet gateway of primary ENI, and that of the secondary ENI. For details on gateways, see Viewing the gateway.

      3. Configure policy-based routes.
        ip rule add from 192.168.1.5 table 10
        ip rule add from 192.168.1.62 table 20 

        Note:

        • The IPs in the above two commands should be replaced with the IP addresses of the primary ENI and that of the secondary ENI. Enter the actual route ID customized in step 6.1 to replace “10” and “20”.
        • After completing the configuration, you can ping the private address of a CVM that is in the same subnet. If the pinging succeeds, the configuration is correct. If no other CVM exists, you can bind the private IP address of the secondary ENI to a public IP address and then ping the public IP address.
        • The routes need to be reconfigured after network restart.

    Configuring ENI on a Ubuntu CVM

    Note:

    The following operations use Ubuntu 18.04 as an example.

    1. Log in to the CVM as the administrator and run the following command to locate the ENI to be configured (IP not shown). As shown in the figure, the ENI to be configured is eth1.

      ip addr

    2. Run the following command to access the /etc/network/ folder.

      cd /etc/network/
    3. Modify the configuration file “interfaces”.

      1. Run the following command to switch to the “root” account and modify the configuration file.

        sudo su
        vim interfaces
      2. Press i to switch to the editing mode and add the following content to the configuration file.

        Note:


        For the methods to view the IP address and subnet mask of the ENI, see the Appendix.

        auto eth1 # Enter the actual ENI name obtained in step 1.
        iface eth1 inet static # Enter the actual ENI name obtained in step 1.
        address 172.21.48.3 # Enter the actual IP address of the ENI.
        netmask 255.255.240.0 # Enter the actual subnet mask.
      3. Press Esc when you get to the last line of vim, enter wq!, and then press Enter to save and close the configuration file.

    4. Restart the ENI eth1.

      1. Run the following commands to switch to the “root” account and install ifupdown.

        sudo su
        apt install ifupdown
      2. Turn off the ENI eth1.

        ifdown eth1
      3. Start the ENI eth1.

        ifup eth1
    5. Check and verify IP configuration.

      1. Run the following command to check the IP address.
        ip addr
      2. Confirm that the secondary ENI and its IP are visible, as shown below:

        If the IP address is incorrectly configured, perform the following checks:
        1. Verify the configuration file. Reconfigure the file if needed.
        2. Confirm whether the ENI has restarted. You can run the following commands to restart ENI for the configuration to take effect.
          ifdown eth1
          ifup eth1
    6. Configure the routing policy based on your actual needs.
      After the preceding configuration, the Linux image still sends packets from the primary ENI by default. In this case, you can configure policy-based routing to specify the ENI through which packets are sent and returned.

      1. Run the following commands to create two route tables.

        echo "10 t1" >> /etc/iproute2/rt_tables
        echo "20 t2" >> /etc/iproute2/rt_tables

        Note:

        Replace “10” and “20” with the actual route ID, and replace “t1” and “t2” with the actual route table names.

      2. Run the following commands to add default routes for both route tables.

        ip route add default dev eth0 via 172.21.48.1 table 10
        ip route add default dev eth1 via 172.21.48.1 table 20

        Note:

        The IPs in the above two commands should be replaced with the IP addresses of the subnet gateway of primary ENI, and that of the secondary ENI. For details on gateways, see Viewing the Gateway.

      3. Run the following commands to configure policy-based routing.

        ip rule add from 172.21.48.11 table 10
        ip rule add from 172.21.48.3 table 20 

        Note:

        • The IPs in the above two commands should be replaced with the IP addresses of the primary ENI and that of the secondary ENI. Enter the actual route ID customized in step 6.1 to replace “10” and “20”.
        • After completing the configuration, you can ping the private address of a CVM that is in the same subnet. If the pinging succeeds, the configuration is correct. If no other CVM exists, you can bind the private IP address of the secondary ENI to a public IP address and then ping the public IP address.
        • The routes need to be reconfigured after network restart.

    Configuring a Windows CVM

    Note:

    The following operations use Windows 2012 as an example.

    • Case 1: if CVM is provided with DHCP, you can view its secondary ENI and IP by following steps below without any further configuration:
      1. Log in to the CVM, and select Control Panel -> Network and Internet -> Network and Sharing Center to check the secondary ENI that has been automatically obtained.
      2. Click the “Ethernet 2” secondary ENI to view its information.
      3. In the Ethernet 2 Status pop-up window, click Properties.
      4. In the Ethernet 2 Properties pop-up window, double-click Internet Protocol Version 4 (TCP/IPv4).
      5. In the Internet Protocol Version 4 (TCP/IPv4) pop-up window, you can see Obtain an IP address automatically is selected, so there is no need to enter one.
      6. Return to the Ethernet 2 Status pop-up window and click Details. DHCP is enabled and the IP automatically obtained is displayed.
    • Case 2: if CVM is not provided with DHCP, you need to configure the private IP by following the steps below:
      1. Log in to the Tencent Cloud console and [bind the ENI to a CVM]#.E7.BB.91.E5.AE.9A.E4.BA.91.E6.9C.8D.E5.8A.A1.E5.99.A8).
      2. Log in to the CVM and select Control Panel -> Network and Internet -> Network and Sharing Center.
      3. Click to edit the “Ethernet 2” secondary ENI.
      4. In the Ethernet 2 Status pop-up window, click Properties.
      5. In the Ethernet 2 Properties pop-up window, double-click Internet Protocol Version 4 (TCP/IPv4).
      6. In the Internet Protocol Version 4 (TCP/IPv4) pop-up window, enter the actual IP and click OK.
      7. In the Ethernet 2 Properties pop-up window, click OK to complete the configuration.
      8. In the Ethernet 2 Status pop-up window, click Details. DHCP is disabled and the IP manually entered is displayed.
      9. Ping the private address of a CVM that is in the same subnet. If the pinging succeeds, the configuration is correct. If no other CVM exists, you can bind the private IP address of the secondary ENI to a public IP address and then ping the public IP address.

    Appendix

    Viewing the IP address of an ENI

    1. Log in to the VPC console.
    2. Choose IP and ENI > ENI in the left sidebar to go to the ENI list page.
    3. Click the ID of the target ENI to go to its details page.
    4. Select the IPv4 Address Management tab to view the IP address of the ENI, which is the private IP.

    Viewing the subnet mask of an ENI

    1. Log in to the VPC console.
    2. Choose IP and ENI > ENI in the left sidebar to go to the ENI list page.
    3. Click the ID of the target ENI to go to its details page, where you can view the subnet mask of the ENI.
      As shown in the following figure, the CIDR bits of the subnet is /20, which means that the subnet mask of the ENI is 255.255.240.0.

      The relationship between the CIDR bits and the subnet mask is described in the following table:
      CIDR Bits Subnet Mask
      /28 255.255.255.240
      /27 255.255.255.224
      /26 255.255.255.192
      /25 255.255.255.128
      /24 255.255.255.0
      /23 255.255.254.0
      /22 255.255.252.0
      /21 255.255.248.0
      /20 255.255.240.0
      /19 255.255.224.0
      /18 255.255.192.0
      /17 255.255.128.0
      /16 255.255.0.0

    Viewing the gateway

    If you haven’t made any changes, the gateway is the first IP address in the subnet IP range. For example, if the subnet IP range is 192.168.0.0/24, the gateway is 192.168.0.1.
    If you are not sure about the subnet IP range of the ENI, please follow the steps below:

    1. Log in to the VPC console.
    2. Choose IP and ENI > ENI in the left sidebar to go to the ENI list page.
    3. Click the ID of the target ENI to go to its details page, where you can view the subnet where the ENI resides. As shown in the figure below, the first IP address in the subnet IP range is 10.200.16.17.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help