Skip to main content

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.

note

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:

Restore port order

  1. Check port settings.

  2. Set up the port order.

1. Check the port settings

  1. Connect to the cloud server.

  2. Check that MAC addresses and interface names match:

    ip link show
  3. Check the port locations on the PCI bus:

    lspci | grep Ethernet
  4. Check that the interface name and PCI location match for each interface:

    ethtool -i <interface_name> | grep bus-info

    Specify <interface_name> — the name of the network interface.

  5. Compare the obtained MAC addresses with the settings in /etc/netplan/50-cloud-init.yaml or a similar network configuration file.

2. Configure the port order

warning

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.

  1. Connect to the cloud server.

  2. Disconnect all ports whose sequence numbers in the interface name (for example, ethX) are greater than the deleted one.

  3. Connect the ports —first the port that should receive a lower number, then the rest in order. The new ports will receive lower numbers.

  4. 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.

  5. Check port settings.

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.

  1. Connect to the cloud server.

  2. If cloud-init is installed in the OS, create a configuration file 99-disable-network-config.cfg:

    nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
  3. Disable network management in cloud-init. To do this, add a parameter to the configuration file:

    network: {config: disabled}
  4. Exit the nano text editor saving changes: press Ctrl+X, and then Y+Enter.

  5. Open the network configuration file:

    nano /etc/netplan/config.yaml
  6. Change the network settings:

    network:
    version: 2
    ethernets:
    <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.
  7. Exit the nano text editor saving changes: press Ctrl+X, and then Y+Enter.

  8. Check the file syntax:

    sudo netplan try
  9. Apply the settings:

    sudo netplan apply
  10. Check the settings by displaying information about the network interfaces:

    ip link show