Skip to main content

Example of configuring a second public floating IP address on a cloud server

Configuration goal

Configure a second public floating IP address on a cloud server to access the server via two public IP addresses.

What is needed for configuration

In the setup example, we used a cloud server created from a pre-made image of Ubuntu 24.04 LTS 64-bit.

The server is in the private subnet 192.168.0.0/24 with the default gateway 192.168.0.1. The private IP address of the cloud server is 192.168.0.2.

The server's private subnet is connected to a cloud router with internet access. The private IP address of the cloud router matches the gateway of the private subnet.

One public floating IP address 203.0.113.10 is connected to the cloud server.

Configuration result

A second port in the private subnet 192.168.0.0/24 with the IP address 192.168.0.3 has been added to the cloud server. A second public floating IP address 198.51.100.13 is connected to this port. The server accepts incoming traffic on both public floating IP addresses: the first 203.0.113.10 and the second 198.51.100.13.

Configuration steps

  1. Add a port to the private subnet.
  2. Create a public floating IP address.
  3. Connect the public floating IP address to the port in the private subnet.
  4. Edit the cloud server network configuration file.
  5. Optional: check access to and from the internet.

1. Add a port to the private subnet

  1. In the control panel, in the top menu, click Products and select Cloud Servers.
  2. Go to Network → Private networks tab.
  3. Open the network page → Ports tab.
  4. Click Add port.
  5. Select a subnet, in the example, 192.168.0.0/24.
  6. Enter the new private IP address of the port, in the example, 192.168.0.3.
  7. Select the cloud server to which you need to add a port.
  8. Click Add.

2. Create a public floating IP address

Create one public floating IP address in the same location as the cloud server.

  1. In the control panel, in the top menu, click Products and select Cloud Servers.
  2. Go to Network → Public Floating IPs tab.
  3. Click Create IP address.
  4. Select the location where the public floating IP address will be created.
  5. Specify the number of public floating IP addresses.
  6. Click Create.

3. Connect the public floating IP address to the port in the private subnet

  1. In the control panel, in the top menu, click Products and select Cloud Servers.
  2. Go to Network → Private networks tab.
  3. Open the network page → Ports tab.
  4. In the cloud server port card, click Public IP.
  5. Select the public floating IP address you created in step 2, in the example, 198.51.100.13.
  6. Click Attach.

4. Edit the cloud server network configuration file

For the server to accept traffic on both public floating IP addresses, a separate routing table with routes and routing rules must be configured for each network interface. A route defines the gateway for sending traffic, and a routing rule specifies which table to use for sending traffic from a specific private IP address.

  1. Connect to the server using the first public floating IP address, in the example, 203.0.113.10.

  2. If a cloud server is created from an image with cloud-init, when the server restarts, cloud-init automatically applies the network settings specified in the control panel on the server page under the Ports tab. The changes you manually made to the server's network settings will not be saved.

    To disable applying settings from the control panel upon server reboot, disable network management via cloud-init:

    echo "network: {config: disabled}" >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
  3. Find the MAC address of the port you added in step 1. To do this, display information about the server's network interfaces:

    ip link show
  4. Open the netplan utility configuration file with the vi text editor:

    vi /etc/netplan/50-cloud-init.yaml
  5. Edit the netplan utility configuration file:

    5.1. At the end of the block with the first network interface data, add routes:

    routes:
    - to: 0.0.0.0/0
    via: 192.168.0.1
    - to: 192.168.0.0/24
    table: 102
    - to: 0.0.0.0/0
    via: 192.168.0.1
    table: 102
    routing-policy:
    - from: 192.168.0.2/32
    table: 102

    Where:

    • 0.0.0.0/0 — default subnet for sending internet traffic;
    • 192.168.0.1 — gateway of the cloud server's private subnet;
    • 192.168.0.0/24 — subnet of the cloud server with the subnet mask /24;
    • 102 — routing table identifier for the first interface, a unique number from 1 to 252;
    • 192.168.0.2/32 — private IP address of the cloud server with the subnet mask /32.

    5.2. After the block with the first network interface data, add the second network interface and routes for it:

    eth1:
    match:
    macaddress: 00:00:5e:00:53:01
    set-name: eth1
    addresses:
    - 192.168.0.3/24
    routes:
    - to: 192.168.0.0/24
    table: 103
    - to: 0.0.0.0/0
    via: 192.168.0.1
    table: 103
    routing-policy:
    - from: 192.168.0.3/32
    table: 103

    Where:

    • 00:00:5e:00:53:01 — MAC address of the port obtained in step 3;
    • 192.168.0.3/24 — private IP address of the cloud server with the subnet mask /24;
    • 192.168.0.0/24 — subnet of the cloud server with the subnet mask /24;
    • 103 — routing table identifier for the second interface, a unique number from 1 to 252;
    • 0.0.0.0/0 — default subnet for sending internet traffic;
    • 192.168.0.1 — gateway of the cloud server's private subnet;
    • 192.168.0.3/32 — private IP address of the cloud server with the subnet mask /32.
    Example of the netplan utility configuration file
    network:
    version: 2
    renderer: networkd
    ethernets:
    # Первый сетевой интерфейс с приватным IP-адресом 192.168.0.2
    eth0:
    match:
    macaddress: 00:00:5e:00:53:00
    set-name: eth0
    addresses:
    - 192.168.0.2/24
    nameservers:
    addresses:
    - 188.93.16.19
    - 188.93.17.19
    routes:
    # Маршрут по умолчанию
    - to: 0.0.0.0/0
    via: 192.168.0.1
    # Маршруты для таблицы маршрутизации 102
    - to: 192.168.0.0/24
    table: 102
    - to: 0.0.0.0/0
    via: 192.168.0.1
    table: 102
    # Исходящий трафик с 192.168.0.2 идет через таблицу маршрутизации 102
    routing-policy:
    - from: 192.168.0.2/32
    table: 102
    # Второй сетевой интерфейс с приватным IP-адресом 192.168.0.3
    eth1:
    match:
    macaddress: 00:00:5e:00:53:01
    set-name: eth1
    addresses:
    - 192.168.0.3/24
    # Маршруты для таблицы маршрутизации 103
    routes:
    - to: 192.168.0.0/24
    table: 103
    - to: 0.0.0.0/0
    via: 192.168.0.1
    table: 103
    # Исходящий трафик с 192.168.0.3 идет через таблицу маршрутизации 103
    routing-policy:
    - from: 192.168.0.3/32
    table: 103
  6. Check the file syntax:

    sudo netplan try
  7. Apply the settings:

    sudo netplan apply

5. Optional: check access to and from the internet

  1. Open the CLI.

  2. Check the server availability via the new public floating IP address:

    ping 198.51.100.13

    Here, 198.51.100.13 is the public floating IP address you created in step 2.

  3. Connect to the server using either of the server's two public floating IP addresses.

  4. From the server, check the availability of any public IP address, for example:

    ping 8.8.8.8