---
title: "Restore port order on a cloud server after shutdown or unfreezing"
sidebar_label: "Restore port order"
sidebar_position: 6
description: "How to configure port order on a cloud server after shutdown or unfreezing"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {CustomTable} from '@selectel/docux/components'
import {TabItemLabel} from '@selectel/docux/components'

# 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, `eth0` first, 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, a cloud server had three ports. You deleted port `eth0` and then powered off and powered on the cloud server. The interface name `eth0` and its PCI address will be applied to the port that was added next in the chronology. The interface name `eth1` and its PCI address will be applied to the next port. Thus, the network configuration bound to the names `eth0` and `eth1` will work with different networks.

:::

If `cloud-init` is configured in the server OS and network settings are defined through it, network settings will update automatically when the server is powered on 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](#fix-ports-order). You can also [bind the interface name to a MAC address](#match-port-to-mac). In this case, the port order will not shift when cloud server ports are deleted or when the server is powered off and on.

The PCI port order does not change:

* during live migration of a running cloud server to another one;
* [via a soft reboot](/cloud-servers/manage/reboot-server.mdx#perform-soft-reboot) from the [Control Panel](https://my.selectel.ru/) or from the OS.

## Restore port order \{#fix-ports-order}

1. [Check the port settings](#check-ports-settings).

2. [Configure the port order](#set-up-ports-order).

### 1. Check the port settings \{#check-ports-settings}

1. [Connect to the cloud server](/cloud-servers/manage/connect-to-server.mdx).

2. Check that MAC addresses and interface names match:

   ```bash
   ip link show
   ```

3. Check the port locations on the PCI bus:

   ```bash
   lspci | grep Ethernet
   ```

4. Check that the interface name and PCI location match for each interface:

   ```bash
   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 \{#set-up-ports-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.

:::

<Tabs queryString="set-up-ports-order">
  <TabItem value="manually">
    <TabItemLabel>
      Manually
    </TabItemLabel>

    1. [Connect to the cloud server](/cloud-servers/manage/connect-to-server.mdx).

    2. [Disable all ports](/cloud-servers/cloud-networks/ports.mdx#disable-port) whose ordinal numbers in the interface name (e.g., `ethX`) are higher than the deleted one.

    3. [Connect the ports](/cloud-servers/cloud-networks/ports.mdx#enable-port) — first the port that should get the 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](#check-ports-settings).
  </TabItem>

  <TabItem value="with-reboot">
    <TabItemLabel>
      Via reboot
    </TabItemLabel>

    1. [Shut down the cloud server](/cloud-servers/manage/manage-server.mdx#turn-off-server).

    2. [Start the cloud server](/cloud-servers/manage/manage-server.mdx#turn-on-server) — ports will be reorganized in the order they were added.

    3. [Check the port settings](#check-ports-settings).

    4. If necessary, [update network settings](/cloud-servers/cloud-networks/update-network-settings.mdx#configure-static-routing) on the cloud server.
  </TabItem>
</Tabs>

## Bind the interface name to a MAC address \{#match-port-to-mac}

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](/cloud-servers/manage/connect-to-server.mdx).

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

   ```bash
   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:

   ```yaml
   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:

   ```bash
   nano /etc/netplan/config.yaml
   ```

6. Change the network settings:

   ```yaml
   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:

   ```bash
   sudo netplan try
   ```

9. Apply the settings:

   ```bash
   sudo netplan apply
   ```

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

    ```bash
    ip link show
    ```

<Formbricks />
