Elastic Network Interface Card
Baidu AI Cloud ENIC can be freely migrated among multiple CVM servers. You can realize the available network scheme by binding multiple ENICs on the CVM server. Furthermore, you can bind multiple private IPs on ENIC, and each private IP can bind an EIP. After you configure the IP, different traffic can flow out from ENIC with different source IPs by configuring the application strategy, which realizes the single server multi-IP deployment.
At present, ENIC is in the open beta test stage. If you want to use ENIC, you can apply for the open beta test.
There are two types of ENI for CVM servers:
- Primary ENI: Native ENI on the virtual machine instance (eth0), which is automatically generated and configured during the creation of virtual machine instance. The primary ENI can not be plugged/unplugged or migrated, and it is consistent with the lifecycle of CVM servers.
- ENIC: It is created for users separately and mounted on the virtual machine instance, and users can mount ENIC during the creation, shutdown, or operation of a virtual machine. After users mount and configure ENIC, different traffic can be routed from different ENICs by configuring the system routing.
Product Restrictions:
- The BCC instance and ENIC must be of the same availability zone and same VPC, but they may be of different subnets and mount different security groups.
- The BCC instance with enhanced network performance does not support ENIC.
- Mounting multiple ENICs to an instance can not improve the private bandwidth performance of the instance.
- The BCC primary ENI is not of ENIC and is not in the list of ENICs. The primary ENI is configured on the "BCC Details" page.
- Each VPC can support up to 10 ENICs.
- There are 1-20 IPs on a single ENI.
- Number of ENICs mounted to CVM server = min (number of server cores, 8).
- Number of configurable IPs on ENI binding to CVM server:
MEM | Number of IPs |
---|---|
1G | 2 |
2-8G | 8 |
12-32G | 16 |
More than 32 G | 20 |
Create an ENIC
- Select the created VPC instance on the "VPC Instance List" page and then click to enter "Details" page.
- Select "ENIC" in the navigation bar, and then click the "Create ENIC" button.
- Fill in the following configuration information:
Configuration Item | Note |
---|---|
Current region | It supports Beijing, Baoding, Guangzhou, Suzhou, Wuhan and Hong Kong, which can be switched through the area in the upper left corner. |
NIC Name | Custom ENIC name |
Subnet | Subnet of ENIC |
Security Group | Security group that ENIC binds, which is within 1-10. |
IP | A primary IP is automatically assigned by default. You can add the secondary IP by yourself. |
Description | Edit the ENIC-related description information. |
- Click "OK" to create an ENIC successfully.
Mount an ENIC
- Select the created VPC instance on the "VPC Instance List" page, and then click to enter "Details" page.
- Select "ENI" in the navigation bar, and then click to enter the "ENI" page.
- Click "Mount ENIC" in ENIC to pop up the "Mount ENIC" dialog, and then select "ENIC" to mount.
- Click "OK" to mount an ENIC successfully.
Note:
- The CVM server image can not automatically identify ENIC temporarily. After the CVM server is mounted, you need to configure ENIC so that it can be identified.
- Before the CVM server mounts ENIC, you need to create an ENIC instance in VPC.
- If you want to uninstall ENIC after the mount of CVM server, click "Uninstall ENIC" on the page to uninstall the ENIC successfully.
- When the CVM server is released, ENIC is not released correspondingly.
Configure an ENIC
According to different images used by your instance, some images need to be manually configured with ENICs, so that the ENIC bound to the instance is identified by the system.
Background Information
Precondition
- At present, the BCC public image is installed with NetworkManager by default. NetworkManager affects the network settings, especially the routing table. Log in to the virtual machine and disable NetworkManager before the ENIC is bound.
Command to Disable NetworkManager
Distribution | Disable Command |
---|---|
CentOS 6 | service NetworkManager stop chkconfig NetworkManager off |
Ubuntu 14 (network-manager to uninstall) | service network-manager stop apt-get --purge remove -y network-manager |
Debian 7 | service network-manager stop update-rc.d -f network-manager remove |
CentOS 7 / Ubuntu 16 / Debian8 / Debian9 | systemctl stop NetworkManager systemctl disable NetworkManage |
ENIC Configuration Tools
- After the disable command is run and ENIC is bound to the BCC instance, you need to configure ENIC as follows according to the image version to make it take effect.
- You need to manually configure the Windows system.
CentOS:bcc_elastic_net_centos.sh
Ubuntu: (ubuntu18.04 not supported temporarily) bcc_elastic_net_ubuntu.sh
Debian:bcc_elastic_net_debian.sh
The configuration tools create a static routing. After you restart the network or instance, you do not need to set the routing again.
Run Configuration Tools
- Enter the created BCC server and add the executable privilege for configuration tools.
- [After the ENIC mounting](#Mount ENIC), run the configuration tools.
- When you change the IP or unbind and rebind ENI, you need to run the configuration tools again.
As shown below:
----------------------------------
Disable NetworkManager.
Begin to config network...
create/recreate network config file [OK]
Begin to create route table...
add 192.168.32.212 to route table: rt_ens3 [OK]
add 192.168.32.228 to route table: rt_ens3 [OK]
add 192.168.32.209 to route table: rt_ens6 [OK]
add 192.168.32.210 to route table: rt_ens6 [OK]
add 192.168.32.211 to route table: rt_ens6 [OK]
add 192.168.32.226 to route table: rt_ens7 [OK]
add 192.168.32.227 to route table: rt_ens7 [OK]
add 192.168.32.229 to route table: rt_ens7 [OK]
Restart network... [OK]
----------------------------------
After the successful configuration, you can check whether the IP is enabled through the command ip addr. The following takes centosas an example.
[root@instance-h1q92lvr ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast state UP qlen 1000
link/ether fa:16:3e:7d:2d:ad brd ff:ff:ff:ff:ff:ff
inet 192.168.32.212/20 brd 192.168.47.255 scope global eth0
inet 192.168.32.228/20 brd 192.168.47.255 scope global secondary eth0:1
inet6 fe80::f816:3eff:fe7d:2dad/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast state UP qlen 1000
link/ether fa:16:3e:a6:69:8f brd ff:ff:ff:ff:ff:ff
inet 192.168.32.209/20 brd 192.168.47.255 scope global eth1
inet 192.168.32.210/20 brd 192.168.47.255 scope global secondary eth1:1
inet 192.168.32.211/20 brd 192.168.47.255 scope global secondary eth1:2
inet6 fe80::f816:3eff:fea6:698f/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast state UP qlen 1000
link/ether fa:16:3e:93:e5:44 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.226/20 brd 192.168.47.255 scope global eth2
inet 192.168.32.227/20 brd 192.168.47.255 scope global secondary eth2:1
inet 192.168.32.229/20 brd 192.168.47.255 scope global secondary eth2:2
inet6 fe80::f816:3eff:fe93:e544/64 scope link
valid_lft forever preferred_lft forever
Configure an ENIC in Windows System
Preparation for Configuration
Before you configure ENIC for your Windows system instance, you need to bind ENIC to the instance. You can assign one or more secondary private IPs to an ENIC as required. It can improve the usage rate of Windows system instance and realize the traffic transfer in case of load failure by using multiple private IPs.
Configuration Method
The following takes Windows Server 2012R2 as an example to describe the configuration process of secondary IP in the Windows system.
- Open "Network and Sharing Center", and then select "Change Adapter Settings".
- Select an ENIC on the pop-up page, and then right click "Attribute".
- Select "TCP/IPV4", and then click "Attribute".
- Select "Use Following IP" in the pop-up dialog. At this time, you need to fill in the IP, subnet mask and DNS servers. You can obtain such information by entering the command ipconfig /all in the command line. After you enter the command or it displays a lot of information, record the IPv4 address, subnet mask, default gateway and DNS servers.
- And then return to the pop-up dialog to configure the static IP. Fill in the obtained IP, subnet mask, default gateway and DNS server address in turn as shown in the figure below, and then click "OK". The network is disconnected for several seconds during the settings, which is a normal phenomenon.
- After the successful configuration of static IP, you also need to add the secondary IP continuouly if you add the secondary IP on the console.
- Click "Advanced" in the "Internet Protocol Version 4 TCP/IP Property" dialog, and then click "Add" in the pop-up dialog to add the secondary IP on the console.
- To verify that the secondary IP is added to the operating system, you can enter the command config /all from the command line to view whether the added IP already exists.
Configure an ENIC in CentOS System
Preparation for Configuration
-
To prevent cloud-init from resetting your custom network configuration, disable the network configuration in cloud-init, and edit /etc/cloud/cloud.cfg, and then add the following content.
network: {config: disabled}
- The BCC instance is installed with NetworkManager. For NetworkManager may change the routing settings, you need to disable NetworkManager.
-
CentOS 7 disables NetworkManager.
systemctl stop NetworkManager systemctl disable NetworkManager
-
CentOS 6 disables NetworkManager.
service NetworkManager stop chkconfig NetworkManager off
Configure an ENIC
- Obtain the network interface name (ENIC name).
-
After the BCC instance adds an ENIC, you can obtain the ENIC name through the following command.
ls /sys/class/net
-
Output results (example)
eth0 eth1 eht2 lo
- The default primary ENI name of BCC instance is eth0 or ens3. The default primary ENI name of some BCC instances is ens3. The ENIC added is eth1 and eth2 in above results.
-
The following takes eth1 as an example to create the configuration file for ENIC.
vim /etc/sysconfig/network-scripts/ifcfg-eth1
Add the following content:
DEVICE=eth1
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PEERDNS=no
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
HWADDR=fa:16:3e:6a:14:b5
DEFROUTE=no
Notice:
- The MAC address of ENIC needs to be written into the configuration file.You can view the MAC address of ENIC through the command cat /sys/class/net/[ENIC name]/address.
- To prevent from changing the default routing, you need to add the DEFROUTE=no option to the configuration file of ENIC.
If there are multiple IPs on ENIC, you need to add the secondary IP on ENIC to the configuration file.
DEVICE=eth1
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PEERDNS=no
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
HWADDR=fa:16:3e:6a:14:b5
DEFROUTE=no
IPADDR1=192.168.32.210
PREFIX1=24
IPADDR2=192.168.32.211
PREFIX2=24
-
Restart the network.
systemctl restart network / service network restart
Configure a Routing
To ensure that the data can pass through the correct network interface (ENIC), you must create a routing table and rule for ENIC.
- Create a routing table
Edit /etc/iproute2/rt_tables to create a routing table for each ENIC.
10 rt_eth1
20 rt_eth2
- Set a routing rule (taking eth1 as an example)
Run the following command at the terminal:
ip route add default via 192.168.32.1 dev eth1 table rt_eth1
ip route add 192.168.32.209 dev eth1 table rt_eth1
ip route add 192.168.32.210 dev eth1 table rt_eth1
ip route add 192.168.32.211 dev eth1 table rt_eth1
ip rule add from 192.168.32.209 lookup rt_eth1
ip rule add from 192.168.32.210 lookup rt_eth1
ip rule add from 192.168.32.211 lookup rt_eth1
Note:
- 192.168.32.209 / 210 / 211 is the IP of ENIC.
- 192.168.32.1 is the default gateway of ENIC.
After the successful setting, you can view the routing of each IP on ENIC through the command ip route show table rt_eth1.
- Create static routing files for ENIC (taking eth1 as an example)
Create the static routing and rule files for ENIC. When the BCC instance starts or restarts the network, it saves the routing and rules, and you do not need to add them manually.
Create the route-eth1 static routing file vim /etc/sysconfig/network-scripts/route-eth1, and add the following content:
default via 192.168.32.1 dev eth1 table rt_eth1
192.168.32.209 dev eth1 table rt_eth1
192.168.32.210 dev eth1 table rt_eth1
192.168.32.211 dev eth1 table rt_eth1
Create or edit the rule-eth1 rule files vim /etc/sysconfig/network-scripts/rule-eth1, and add the following content:
from 192.168.32.209 lookup rt_eth1
from 192.168.32.210 lookup rt_eth1
from 192.168.32.211 lookup rt_eth1
Configure an ENIC in Ubuntu/Debian System
Preparation for Configuration
-
To prevent cloud-init from resetting your custom network configuration, disable the network configuration in cloud-init, and edit /etc/cloud/cloud.cfg, and then add the following content:
network: {config: disabled}
- The BCC instance is installed with NetworkManager. For NetworkManager may change the routing settings, you need to disable NetworkManager and ensure that NetworkManager is still in the Disabled status after the system restarts.
-
Ubuntu14 needs to uninstall NetworkManager.
service network-manager stop apt-get --purge remove -y network-manager
-
CentOS 6 disables NetworkManager.
systemctl stop NetworkManager systemctl disable NetworkManager
Configure an ENIC
- Obtain the network interface name (ENIC name).
After the BCC instance adds an ENIC, you can obtain the ENIC name through the following command.
ls /sys/class/net
Output results (example)
eth0 eth1 eht2 lo
The default primary ENI name of BCC instance is eth0 or ens3. The default primary ENI name of some BCC instances is ens3. The ENIC added is eth1 and eth2 in above results.
- Edit /etc/network/interfaces
Edit the network interface file /etc/network/interfaces to change it into the following content:
auto lo
iface lo inet loopback
source /etc/network/interfaces.d/*
For the BCC Ubuntu16 instance, edit /etc/network/interfaces.d/50-cloud-init.cfg to change it into the following content:
auto ens3
iface ens3 inet dhcp
Furthermore, change the file name to ens3.cfg.
mv /etc/network/interfaces.d/50-cloud-init.cfg /etc/network/interfaces.d/ens3.cfg
- The following takes eth1 as an example to create the configuration file for ENIC.
Create an eth1.cfg file under the directory /etc/network/interfaces.d/.
vim /etc/network/interfaces.d/eth1.cfg
Add the following content:
auto eth1
iface eth1 inet dhcp
hwaddress=fa:16:3e:6a:14:b5
Notice:
- The MAC address of ENIC needs to be written into the configuration file. You can view the MAC address of ENIC through the command cat /sys/class/net/[ENIC name]/address.
If there are multiple IPs on ENIC, you need to add the secondary IP on ENIC to the configuration file.
auto eth1
iface eth1 inet dhcp
hwaddress=fa:16:3e:6a:14:b5
iface eth1 inet static
address 192.168.32.210
netmask 255.255.240.0
iface eth1 inet static
address 192.168.32.211
netmask 255.255.240.0
- Create a file restrict-default-route to prevent from overwritting the default routing.
vim /etc/dhcp/dhclient-enter-hooks.d/restrict-default-route, add the following content:
case ${interface} in
eth0) # ubuntu16/debian9为ens3
;;
*)
unset new_routers
;;
esac
- Restart the network.
-
Ubuntu14
ifdown eth1 && ifup eth1
-
Ubuntu16
systemctl restart networking
Configure a Routing
To ensure that the data can pass through the correct network interface (ENIC), you must create a routing table and rule for ENIC.
- Create a routing table
Edit /etc/iproute2/rt_tables to create a routing table for each ENIC.
10 rt_eth1
20 rt_eth2
- Set the routing rules (taking eth1 as an example).
Run the following command at the terminal:
ip route add default via 192.168.32.1 dev eth1 table rt_eth1
ip route add 192.168.32.209 dev eth1 table rt_eth1
ip route add 192.168.32.210 dev eth1 table rt_eth1
ip route add 192.168.32.211 dev eth1 table rt_eth1
ip rule add from 192.168.32.209 lookup rt_eth1
ip rule add from 192.168.32.210 lookup rt_eth1
ip rule add from 192.168.32.211 lookup rt_eth1
Note:
- 192.168.32.209 / 210 / 211 is the IP of ENIC.
- 192.168.32.1 is the default gateway of ENIC.
After the successful setting, you can view the routing of each IP on ENIC through the command ip route show table rt_eth1.
- Create the static routing file for ENIC (taking eth1 as an example).
Edit /etc/network/interfaces.d/eth1.cfg.
auto eth1
iface eth1 inet dhcp
hwaddress=fa:16:3e:6a:14:b5
iface eth1 inet static
address 192.168.32.210
netmask 255.255.240.0
iface eth1 inet static
address 192.168.32.211
netmask 255.255.240.0
# default gateway for eth1
up ip route add default via 192.168.32.1 dev eth1 table rt_eth0
# route for every IP
up ip route add 192.168.32.210 dev eth1 table rt_eth0
up ip route add 192.168.32.211 dev eth1 table rt_eth0
# policy rule for every IP
up ip rule add from 192.168.32.210 lookup rt_eth0
up ip rule add from 192.168.32.210 lookup rt_eth0