[Yandex Cloud documentation](../../index.md) > [Yandex BareMetal](../index.md) > [Tutorials](index.md) > Manually assigning a public IP address to a BareMetal server

# Manually assigning a public IP address to a BareMetal server

There is no [DHCP server](../concepts/dhcp.md#dhcp-public-subnet) in the [dedicated public subnet](../concepts/public-network.md#public-subnet) of [BareMetal servers](../concepts/servers.md). Therefore, on the network interface of the server connected to such a subnet, you should manually set a static public IP address from the subnet address range, plus specify the default gateway address and DNS servers.

The information about the range of IP addresses available in a public subnet and default gateway is provided in the **Network interfaces** section on the server information page and on the public subnet information page.

{% note info %}

The steps described in this guide also apply to the [ephemeral public subnet](../concepts/public-network.md#ephemeral-public-subnet) if its DHCP server was off when the server was rented. The ephemeral public subnet is always `/31` in size and consists of these two addresses: the first one is the default gateway address, and the second one is the server's public IP address. For more information, see [DHCP in an ephemeral public subnet](../concepts/dhcp.md#dhcp-ephemeral-public-subnet).

For Windows servers, you have to manually assign a public IP address in any ephemeral /31 public subnet, even if its DHCP server is on. This is because the Windows DHCP client cannot issue addresses in /31 subnets.

{% endnote %}

To learn more about networks in Yandex BareMetal, see [Network](../concepts/network.md).

In this guide, you will learn how to manually configure a public IP address on the network interface of a BareMetal server connected to a dedicated public subnet. This example uses servers running Ubuntu 24.04 LTS, AlmaLinux 9, and Windows Server 2022. If using another OS, you will follow the same steps, but the way you configure network interfaces may differ. For network interface configuration steps in other operating systems, refer to the relevant OS guides.

To assign a public IP address to a BareMetal server manually:

1. [Get your cloud ready](#before-you-begin).
1. [Order a dedicated public subnet](#create-public-subnet).
1. [Rent a BareMetal server](#rent-server).
1. [Obtain the public subnet parameters](#get-subnet-params).
1. [Connect to the server via the KVM console](#connect-via-kvm).
1. [Identify the public network interface](#identify-interface).
1. [Assign a static public IP address to the network interface](#assign-ip).
1. [Test network connectivity](#validate-connectivity).

See also [How to cancel a server rent](#clear-out).

## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

### Required paid resources {#paid-resources}

The cost of the proposed solution includes:

* Fee for renting a BareMetal server.
* Fee for renting a Yandex BareMetal dedicated public subnet.

For more information, see [Yandex BareMetal pricing](../pricing.md).

{% note warning %}

The minimum rent period for a dedicated public subnet is one month from the order date. You cannot delete such a subnet during the first month after ordering it.

{% endnote %}

## Order a dedicated public subnet {#create-public-subnet}

Order a [dedicated public subnet](../concepts/public-network.md#public-subnet) of size `/29` in the `ru-central1-m3` server pool:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are going to create your infrastructure.
  1. [Navigate](../../console/operations/select-service.md#select-service) to **BareMetal**.
  1. In the left-hand panel, select ![globe](../../_assets/console-icons/globe.svg) **Public addresses and subnets**.
  1. At the top right, click **Order a public subnet**.
  1. In the **Availability zone** field, select the [availability zone](../../overview/concepts/geo-scope.md) where the subnet will be available.
  1. In the **Pool** field, select the `ru-central1-m3` server pool.
  1. In the subnet size field, select `/29`.
  1. In the **Name** field, enter the subnet name: `my-public-subnet`.
  1. Click **Order**.

{% endlist %}

For more information on renting a public subnet, see [this section](../operations/reserve-public-subnet.md).

## Rent a BareMetal server {#rent-server}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **BareMetal**.
  1. Click **Lease server** and, in the window that opens, select `Stock configurations` and a suitable BareMetal server [configuration](../concepts/server-configurations.md) in the `ru-central1-m3` server pool.

      Do it by selecting the `ru-central1-m3` server pool in the filter on the right side of the window, under **Pool**.

      To select the suitable server configuration, click the section with its name in the central part of the screen.

      {% note tip %}
      
      You can reduce the cost of renting a server in some configurations by ordering server [assembly](../concepts/server-custom-configurations.md#assembly).
      
      To use the discount, hover over **Cheaper with assembly** ![circle-info.svg](../../_assets/console-icons/circle-info.svg) under the configuration at hand and click ![person-nut-hex.svg](../../_assets/console-icons/person-nut-hex.svg) **Go to assembly** in the pop-up window.
      
      When ordering a server with assembly, follow the steps below to configure the server properties. In this case, the server will not be available immediately, but only after the assembly is completed (within four calendar days), and at a lower price.
      
      {% endnote %}

  1. In the server configuration window that opens:

      1. In the **Lease duration** field, select the [lease period](../concepts/servers.md#server-lease): `1 day`, `1 month`, `3 months`, `6 months`, or `1 year`.
         
         When this period expires, server lease will automatically be renewed for the same period. You cannot terminate the lease during the specified lease period, but you can [refuse](../operations/servers/server-lease-cancel.md) to extend the server lease further.
      1. Under **Image**, select the image of the operating system you will be configuring the network interface in (`Ubuntu 24.04`, `AlmaLinux 9`, or `Windows Server 2022`).
      1. Optionally, under **Disk**, configure [disk](../concepts/disks/disk-types.md) partitioning:
         
         1. Click **Configure disk layout**.
         1. Specify partition settings. To create a new partition, click ![icon](../../_assets/console-icons/plus.svg) **Add partition**.
         
             To configure [RAID](../concepts/disks/raid.md) arrays and disk partitions by yourself, click **Remove RAID**.
         1. Click **Save**.
      1. Under **Network interfaces**:
          1. In the **Public address** field, select `From a dedicated subnet`.
          1. In the public subnet selection field that appears, specify the previously created `my-public-subnet`.

      1. Under **Access**:

          1. In the **Password** field, select one of the following options to create a root password:
          
              * To generate a new root password, select `New password` and click **Generate**.
          
                  {% note warning %}
                  
                  This option requires you to maintain password security. Save the password you generated in a secure location. Yandex Cloud does not store it, and you will not be able to retrieve it once the server is deployed.
                  
                  {% endnote %}
          
              * To use the root password saved in a Yandex Lockbox [secret](../../lockbox/concepts/secret.md), select `Lockbox secret`.
          
                  In the **Name**, **Version**, and **Key** fields, select the secret containing your password, its version, and its key, respectively.
                  
                  If you do not have a Yandex Lockbox secret, click **Create** to create it.
          
                  Choose the `Custom` secret type to specify a custom password or `Generated` to generate password automatically.
          
          1. In the **Public SSH key** field, select the SSH key saved in your [organization user](../../organization/concepts/membership.md) profile.
          
              If there are no SSH keys in your profile or you want to add a new key:
              
              1. Click **Add key**.
              1. Enter a name for the SSH key.
              1. Select one of the following:
              
                  * `Enter manually`: Paste the contents of the public SSH key. You need to [create](../../compute/operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair on your own.
                  * `Load from file`: Upload the public part of the SSH key. You need to create an SSH key pair on your own.
                  * `Generate key`: Automatically create an SSH key pair.
                  
                    When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the `/home/<user_name>/.ssh` directory. In Windows, unpack the archive to the `C:\Users\<user_name>/.ssh` directory. You do not need additionally enter the public key in the management console.
              
              1. Click **Add**.
              
              The system will add the SSH key to your organization user profile. If the organization has [disabled](../../organization/operations/os-login-access.md) the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.

      1. Under **Server information**, in the **Name** field, enter the server name: `my-server`.
      1. Click **Lease server**.

{% endlist %}

{% note info %}

Server setup and OS installation may take up to 45 minutes. The server will have the `Provisioning` status during this time. After OS installation is complete, the server status will change to `Ready`.

{% endnote %}

## Obtain the public subnet parameters {#get-subnet-params}

Before configuring the network interface, find out the parameters of the dedicated public subnet the server is connected to: CIDR, default gateway address, and range of available public IP addresses.

1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
1. [Navigate](../../console/operations/select-service.md#select-service) to **BareMetal**.
1. In the left-hand panel, select ![globe](../../_assets/console-icons/globe.svg) **Public addresses and subnets** and open the `my-public-subnet` information page.
1. Write down the CIDR values, default gateway address, and range of available public IP addresses.

   For a subnet of size `/29` (eight IP addresses in CIDR):

   * The first IP address in the range is the subnet address.
   * The second IP address in the range is the default gateway address.
   * From the third to second-last one are addresses available for server network interfaces.
   * The last IP address in the range is the [broadcast](https://en.wikipedia.org/wiki/Broadcast_address) (`broadcast`) address.

   For example, if the subnet CIDR is `198.51.100.104/29`:

   * Subnet IP address: `198.51.100.104`.
   * Default gateway IP address: `198.51.100.105`.
   * Available addresses: From `198.51.100.106` to `198.51.100.110`.
   * Broadcast address: `198.51.100.111`.

   These values ​​will be used in example commands further on in this guide. Replace them with the values you got for your subnet.

## Connect to the server via the KVM console {#connect-via-kvm}

Before you configure a public IP address, the server is not accessible from the Internet, so you will not be able to connect to it via [SSH](../../compute/operations/vm-connect/ssh.md) or [RDP](../../compute/operations/vm-connect/rdp.md). To connect to the server, use the KVM console.

1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
1. [Navigate](../../console/operations/select-service.md#select-service) to **BareMetal**.
1. Next to `my-server`, click ![image](../../_assets/console-icons/ellipsis.svg) and select **KVM console**.

    A window with a KVM console terminal will open.

    If the terminal does not appear, try [restarting](../operations/servers/server-stop-and-start.md#restart) the server.

1. Authenticate to the server using the administrator password saved when renting the server (`root` for Linux, `Administrator` for Windows).

    {% note tip %}
    
    To paste clipboard text to the KVM console, use the **Paste text here** field in the upper right corner.
    
    {% endnote %}

    If you did not save the administrator password, you can create a new one as per [this guide](../operations/servers/reset-password.md) or [reinstall](../operations/servers/reinstall-os-from-marketplace.md) the server OS.

For more on connecting to a server via the KVM console, see [this section](../operations/servers/server-kvm.md).

## Identify the public network interface {#identify-interface}

To figure out which of the server's network interfaces is connected to the public network, match the interface name against the MAC address listed in the [management console](https://console.yandex.cloud) on the server info page under **Network interfaces**

Write down the MAC address of the public network interface: you will need it for configuration.

{% list tabs group=operating_system %}

- Ubuntu/Debian/AlmaLinux {#linux}

  In the KVM console terminal, run this command:

  ```bash
  ip a
  ```

  Result:

  ```text
  ...
  2: etx1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
      link/ether 00:25:90:c8:03:f8 brd ff:ff:ff:ff:ff:ff
      altname enp2s0f0
      inet6 fe80::225:90ff:fec8:3f8/64 scope link
          valid_lft forever preferred_lft forever
  3: etx2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
      link/ether 00:25:90:c8:03:f9 brd ff:ff:ff:ff:ff:ff
      altname enp2s0f1
      inet6 fe80::225:90ff:fec8:3f9/64 scope link
          valid_lft forever preferred_lft forever
  ...
  ```

  In this example, the public MAC address from the management console is `00:25:90:c8:03:f9`, so the server's public network interface is `eth2`.

- Windows Server {#windows}

  In PowerShell, run:

  ```powershell
  Get-NetAdapter | Format-Table Name, InterfaceDescription, MacAddress, Status
  ```

  Result:

  ```text
  Name       InterfaceDescription                          MacAddress         Status
  ----       --------------------                          ----------         ------
  Ethernet   Mellanox ConnectX-4 Lx Adapter #1             00-25-90-C8-03-F8  Up
  Ethernet 2 Mellanox ConnectX-4 Lx Adapter #2             00-25-90-C8-03-F9  Up
  ```

  In this example, the public MAC address from the management console is `00:25:90:c8:03:f9`, so the server's public network interface is `Ethernet 2`.

{% endlist %}

{% note warning %}

If the rented server supports [MC-LAG](../concepts/mc-lag.md) and is installed from a [custom image](../concepts/images.md#user-images), the physical network interfaces are not automatically combined into aggregation groups. In which case we recommend to start by [configuring an aggregation group](../operations/servers/set-up-mc-lag.md) for a pair of public interfaces and then assign a static public IP address to the bond interface. In the bond interface settings, you should specify the MAC address of one of the physical interfaces of the aggregation group as the MAC address.

{% endnote %}

## Assign a static public IP address to the network interface {#assign-ip}

{% list tabs group=operating_system %}

- Ubuntu/Debian (Netplan) {#ubuntu}

  1. In the KVM console terminal, learn the name of the [Netplan](https://netplan.io/) configuration file:

      ```bash
      ls /etc/netplan/
      ```

      Result:

      ```text
      50-cloud-init.yaml
      ```
  1. Open the configuration file:

      ```bash
      nano /etc/netplan/50-cloud-init.yaml
      ```
  1. Update the public network interface settings:

      ```yaml
      network:
        version: 2
        ethernets:
          ... # This example shows only the public interface configuration.
          etx2:
            match:
              macaddress: "00:25:90:c8:03:f9"
            dhcp4: false # Disable DHCP on the interface
            set-name: "etx2"
            addresses: # Set a static public IP address and subnet mask
              - 198.51.100.106/29
            routes: # Set the default route through the public subnet gateway
              - to: default
                via: 198.51.100.105
            nameservers: # Set DNS servers
              addresses: [77.88.8.8, 77.88.8.1]
      ```

      Where:

      * `match.macaddress`: MAC address of the public network interface.
      * `dhcp4`: `false` disables DHCP on the interface.
      * `addresses`: Public IP address from the range of available subnet addresses, with the subnet mask in CIDR format.
      * `routes.to: default` and `via`: Default route through the public subnet gateway address.
      * `nameservers.addresses`: DNS server addresses.

      To save the changes and exit the text editor, press **Ctrl + X** and confirm saving changes to the `50-cloud-init.yaml` file.
  1. Make sure the configuration is correct:

      ```bash
      netplan try
      ```

      If the configuration is free of errors, the utility will temporarily apply it and prompt you to confirm the changes. Confirm the changes by pressing **ENTER**.
  1. Apply the new configuration:

      ```bash
      netplan apply
      ```

- AlmaLinux/RHEL/CentOS (NetworkManager) {#almalinux}

  To configure the network interface, use `nmcli`. You can also use the `nmtui` graphical utility, which provides an interactive text interface to go with NetworkManager.

  1. View the list of network connections in the KVM console terminal:

      ```bash
      nmcli connection show
      ```

      Result:

      ```text
      NAME         UUID                                  TYPE      DEVICE
      System etx1  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  etx1
      System etx2  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e04  ethernet  etx2
      ```

      Find the connection name for the public network interface. In this example, `System etx2`.
  1. Set a static public IP address, default gateway, and DNS servers for the connection:

      ```bash
      nmcli connection modify "System etx2" \
        ipv4.method manual \
        ipv4.addresses 198.51.100.106/29 \
        ipv4.gateway 198.51.100.105 \
        ipv4.dns "77.88.8.8 77.88.8.1" \
        connection.autoconnect yes
      ```

      Where:

      * `ipv4.method manual`: Disables DHCP and switches the connection to static configuration mode.
      * `ipv4.addresses`: Public IP address from the range of available subnet addresses, with the subnet mask in CIDR format.
      * `ipv4.gateway`: Public subnet gateway address.
      * `ipv4.dns`: DNS server addresses separated by spaces.
      * `connection.autoconnect yes`: Automatically activates the connection on system boot.
  1. Activate the connection:

      ```bash
      nmcli connection up "System etx2"
      ```

- Windows Server (GUI) {#windows-gui}

  1. In the KVM console, go **Start** → **Control Panel** → **Network and Internet** → **Network and Sharing Center**.
  1. In the left-hand panel, select **Change adapter settings**.
  1. In the list that opens, find the network adapter matching the public network interface, e.g., `Ethernet 2`, right-click it and select **Properties**.
  1. In the list of connection components, select **Internet Protocol Version 4 (TCP/IPv4)** and click **Properties**.
  1. Select **Use the following IP address** and fill out the fields:

      * **IP address**: Public IP address from the range of available subnet addresses, e.g., `198.51.100.106`.
      * **Subnet mask**: Subnet mask matching the CIDR notation, e.g., `/29`: `255.255.255.248`.
      * **Default gateway**: Public subnet gateway address, e.g., `198.51.100.105`.
  1. Select **Use the following DNS server addresses** and fill out the fields:

      * **Preferred DNS server**: `77.88.8.8`.
      * **Alternate DNS server**: `77.88.8.1`.
  1. Click **OK** in both windows to save the settings.

- Windows Server (PowerShell) {#windows-cli}

  In the PowerShell terminal in the KVM console:

  1. Remove the existing IPv4 configuration on the public network interface if you got it over DHCP:

      ```powershell
      Set-NetIPInterface -InterfaceAlias "Ethernet 2" -Dhcp Disabled
      Remove-NetIPAddress -InterfaceAlias "Ethernet 2" -AddressFamily IPv4 -Confirm:$false
      Remove-NetRoute -InterfaceAlias "Ethernet 2" -AddressFamily IPv4 -Confirm:$false
      ```
  1. Set a static public IP address and default gateway:

      ```powershell
      New-NetIPAddress -InterfaceAlias "Ethernet 2" `
        -IPAddress 198.51.100.106 `
        -PrefixLength 29 `
        -DefaultGateway 198.51.100.105
      ```

      Where:

      * `-InterfaceAlias`: Name of the public network interface.
      * `-IPAddress`: Public IP address from the range of available subnet addresses.
      * `-PrefixLength`: Subnet mask prefix length (for `/29`: `29`).
      * `-DefaultGateway`: Public subnet gateway address.
  1. Set DNS servers for the interface:

      ```powershell
      Set-DnsClientServerAddress -InterfaceAlias "Ethernet 2" `
        -ServerAddresses ("77.88.8.8","77.88.8.1")
      ```

{% endlist %}

## Test network connectivity {#validate-connectivity}

Make sure the network interface got a public IP address and the server has access to the internet.

{% list tabs group=operating_system %}

- Ubuntu/Debian/AlmaLinux {#linux}

  1. Check that the specified IP address has been assigned to the network interface:

      ```bash
      ip a | grep etx2
      ```

      Result:

      ```text
      3: etx2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
          inet 198.51.100.106/29 brd 198.51.100.111 scope global etx2
      ```
  1. Check the route table:

      ```bash
      ip r
      ```

      Result:

      ```text
      default via 198.51.100.105 dev etx2 proto static
      198.51.100.104/29 dev etx2 proto kernel scope link src 198.51.100.106
      ```
  1. Check the DNS settings:

      ```bash
      resolvectl status
      ```
  1. Check internet connectivity:

      ```bash
      ping ya.ru -c 5
      ```

      Result:

      ```text
      PING ya.ru (77.88.55.88) 56(84) bytes of data.
      64 bytes from ya.ru (77.88.55.88): icmp_seq=1 ttl=55 time=3.45 ms
      64 bytes from ya.ru (77.88.55.88): icmp_seq=2 ttl=55 time=3.22 ms
      ...

      --- ya.ru ping statistics ---
      5 packets transmitted, 5 received, 0% packet loss, time 4006ms
      rtt min/avg/max/mdev = 3.215/3.337/3.452/0.085 ms
      ```

- Windows Server {#windows}

  1. In PowerShell, check that the specified IP address has been assigned to the network interface:

      ```powershell
      Get-NetIPAddress -InterfaceAlias "Ethernet 2" -AddressFamily IPv4
      ```
  1. Check the route table:

      ```powershell
      Get-NetRoute -InterfaceAlias "Ethernet 2" -AddressFamily IPv4
      ```
  1. Check the DNS settings:

      ```powershell
      Get-DnsClientServerAddress -InterfaceAlias "Ethernet 2"
      ```
  1. Check internet connectivity:

      ```powershell
      Test-NetConnection ya.ru -InformationLevel Detailed
      ```

{% endlist %}

Once a public IP address is assigned, you can connect to the server from the internet via that IP address using [SSH](../../compute/operations/vm-connect/ssh.md) (for Linux) or [RDP](../../compute/operations/vm-connect/rdp.md) (for Windows).

## How to cancel a rent {#clear-out}

You cannot delete a BareMetal server or a dedicated public subnet. Instead, you can choose not to renew their rent.

To stop paying for the resources you created:

1. [Cancel](../operations/servers/server-lease-cancel.md) rent renewal for the BareMetal server you created earlier.
1. After the minimum rent period (one month from the order date) has expired, delete the dedicated public subnet.

#### See also {#see-also}

* [Public network](../concepts/public-network.md)
* [DHCP in a Yandex BareMetal network](../concepts/dhcp.md)
* [Ordering a dedicated public subnet](../operations/reserve-public-subnet.md)
* [Configuring the MC-LAG aggregation group](../operations/servers/set-up-mc-lag.md)
* [Establishing network connectivity in a Yandex BareMetal private subnet](bms-simple-subnet.md)