This document describes how to bind a Linux and Windows CVM.
Note:
- ENI can only be bound to CVMs in the same availability zone.
- ENI cannot be bound to BM (Bare Metal) 2.0.
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.
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
Run the following command to access the /etc/sysconfig/network-scripts/
folder.
cd /etc/sysconfig/network-scripts/
Create a configuration file such as ifcfg-eth1
for the new ENI.
cp ifcfg-eth0 ifcfg-eth1
vim ifcfg-eth1
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:Run the following command to restart the network service.
systemctl restart network
Check and verify the IP configuration.
ip addr
systemctl restart network
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.
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.
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.
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.
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
Run the following command to access the /etc/network/
folder.
cd /etc/network/
Modify the configuration file “interfaces”.
Run the following command to switch to the “root” account and modify the configuration file.
sudo su
vim interfaces
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.
Press Esc when you get to the last line of vim, enter wq!, and then press Enter to save and close the configuration file.
Restart the ENI eth1.
Run the following commands to switch to the “root” account and install ifupdown.
sudo su
apt install ifupdown
Turn off the ENI eth1.
ifdown eth1
Start the ENI eth1.
ifup eth1
Check and verify IP configuration.
ip addr
ifdown eth1
ifup eth1
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.
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.
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.
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.
Note:
The following operations use Windows 2012 as an example.
255.255.240.0
.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 |
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:
10.200.16.17
.
Was this page helpful?