Restore port order on a cloud server after shutdown or unfreezing
When ports are added to a cloud server, virtual network interface cards (NICs) are created for them and connected to the server's PCI bus. Slots on the PCI bus (PCI addresses) are assigned in chronological order: the earlier a port is connected, the lower its PCI address. Network interface names are assigned to ports according to the order of PCI addresses—for example, first eth0, then eth1, and so on.
When a server is shut down and started or frozen and unfrozen, network cards re-occupy slots on the PCI bus and receive PCI addresses.
If one of the server ports is deleted beforehand, the remaining network cards on the PCI bus will shift to occupy the vacant PCI address and interface name. Interface names will be reassigned in order: interfaces added after the deleted one will shift by one name. If interface names are used in network configuration files, the port will end up bound to a different network, and connectivity with the cloud server may be lost.
For example, there were three ports on a cloud server. You deleted the eth0 port and then turned the cloud server off and on. The interface name eth0 and its PCI address will apply to the port that was added next chronologically. The interface name eth1 and its PCI address will apply to the next port. Thus, the network settings configuration bound to the names eth0 and eth1 will work with other networks.
If cloud-init is configured in the server OS and network settings are specified through it, when the server is powered on or unfrozen, network settings will be updated automatically, but network interface names will not be updated in scripts and manual settings. If cloud-init is not used and the network is configured statically via configuration files (/etc/network/interfaces, ifcfg-*, and others), connectivity will be disrupted.
If the port order has changed, you can restore it. You can also bind the interface name to the MAC address. Then, when deleting cloud server ports and turning it off and on, the port order will not shift.
The PCI port order does not change:
- during live migration of a running cloud server to another one;
- soft reboot from the Control panel or from the OS.
Restore port order
1. Check the port settings
-
Check that MAC addresses and interface names match:
ip link show -
Check the port locations on the PCI bus:
lspci | grep Ethernet -
Check that the interface name and PCI location match for each interface:
ethtool -i <interface_name> | grep bus-infoSpecify
<interface_name>— the name of the network interface. -
Compare the obtained MAC addresses with the settings in
/etc/netplan/50-cloud-init.yamlor a similar network configuration file.
2. Configure the port order
During configuration, you will need to disconnect and connect server ports or shut down the server. This will result in a brief loss of network connectivity.
Manually
Via reboot
-
Disconnect all ports whose sequence numbers in the interface name (for example,
ethX) are greater than the deleted one. -
Connect the ports —first the port that should receive a lower number, then the rest in order. The new ports will receive lower numbers.
-
If the OS uses a configuration file that is updated manually, update the IP addresses, gateways, and other network parameters in accordance with the new MAC addresses.
Bind the interface name to a MAC address
To prevent network interface names from shifting relative to the configured IP addresses, you can fix them in the cloud server's network settings.
-
If
cloud-initis installed in the OS, create a configuration file99-disable-network-config.cfg:nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg -
Disable network management in
cloud-init. To do this, add a parameter to the configuration file:network: {config: disabled} -
Exit the
nanotext editor saving changes: press Ctrl+X, and then Y+Enter. -
Open the network configuration file:
nano /etc/netplan/config.yaml -
Change the network settings:
network:version: 2ethernets:<interface_name>:match:macaddress: "<mac_address>"set-name: "<interface_name>"addresses:- <ip_address>routes:- to: <destination_subnet>via: <gateway>...Specify:
<mac_address>– MAC address of the network interface;<interface_name>— network interface name;<ip_address>— IP address of the cloud server that corresponds to the interface, specified with a subnet mask, for example,192.168.0.5/29;<destination_subnet>— for static routes: CIDR of destination subnets where traffic will be routed, for example,172.16.0.8/29.<gateway>— subnet gateway.
-
Exit the
nanotext editor saving changes: press Ctrl+X, and then Y+Enter. -
Check the file syntax:
sudo netplan try -
Apply the settings:
sudo netplan apply -
Check the settings by displaying information about the network interfaces:
ip link show