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 cards 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 in accordance with the PCI address order — 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 was deleted beforehand, the remaining network cards on the PCI bus will shift to occupy the available 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 be linked to a different network, which may result in a loss of network connectivity with the cloud server.

note

For example, a cloud server had three ports. You deleted the eth0 port, and then shut down and started the cloud server. The eth0 interface name and its PCI address will apply to the port that was added next in chronological order. The eth1 interface name and its PCI address will apply to the next port. Thus, the network settings configuration linked to the eth0 and eth1 names will work with different networks.

If cloud-init is configured in the server OS and network settings are defined through it, network settings will be updated automatically when the server is started or unfrozen, but network interface names will not be updated in scripts and manual configurations. If cloud-init and the network are configured statically via configuration files (/etc/network/interfaces, ifcfg-*, and others), connectivity will be broken.

If the port order has changed, you can restore it. You can also bind the interface name to a MAC address. In this case, the port order will not shift when deleting cloud server ports or shutting down and starting the server.

The PCI port order does not change:

Restore port order

  1. Check the port settings.

  2. Configure 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. Disable all ports whose ordinal numbers in the interface name (e.g., ethX) are higher than the deleted one.

  3. Connect the ports — first the port that should receive a lower number, then the others in order. 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 the 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 the parameter to the configuration file:

    network: {config: disabled}
  4. Exit the nano text editor while 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> — the MAC address of the network interface;
    • <interface_name> — the name of the network interface;
    • <ip_address> — the IP address of the cloud server that corresponds to the interface, with the subnet mask specified, for example 192.168.0.5/29;
    • <destination_subnet> — for static routes: the CIDR of the destination subnets to which traffic will be directed, for example 172.16.0.8/29.
    • <gateway> — the subnet gateway.
  7. Exit the nano text editor while 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