IBM Cloud Docs
Attaching floating IPs to a virtual network interface

Attaching floating IPs to a virtual network interface

Floating IP addresses are IP addresses that are provided by the system and are reachable from the public internet. A floating cannot be attached to a virtual network interface if that virtual network interface is attached to a share mount target.

You can attach floating IPs to a VNI with the console, CLI, API, or Terraform.

Attaching a floating IP to a virtual network interface in the console

To attach a floating IP to an existing virtual network interface, follow these steps.

  1. From your browser, open the IBM Cloud console and log in to your account.
  2. Select the Navigation menu Navigation menu icon, then click Infrastructure VPC icon > Network > Virtual network interfaces.
  3. Click the name of the virtual network interface that you want to attach a floating IP to in the Virtual network interfaces for VPC table.
  4. In the Floating IPs section, click Attach.
  5. In the Attach floating IP panel that appears, you can do one of the following:
    • Reserve a new floating IP by clicking Reserve new floating IP and completing the requested information in the panel that appears
    • Select an existing floating IP from the Floating IP addresses menu.
  6. Click Attach to attach the floating IP to your virtual network interface, or click Cancel.

Attaching a floating IP to a virtual network interface from the CLI

Before you begin, set up your CLI environment.

Then run the following command:

ibmcloud is floating-ip-reserve FLOATING_IP_NAME (--zone ZONE_NAME | --nic TARGET_INTERFACE [--in TARGET_INSTANCE | --bm TARGET_BARE_METAL_SERVER | --vni TARGET_VIRTUAL_NETWORK_INTERFACE]) [--resource-group-id RESOURCE_GROUP_ID | --resource-group-name RESOURCE_GROUP_NAME] [--output JSON] [-q, --quiet]

Where:

FLOATING_IP_NAME
ID or name of the floating IP.
--zone
ID or name of the zone.
--nic TARGET_INTERFACE
The target interface.
--in TARGET_INSTANCE
The target virtual server instance.
--bm TARGET_BARE_METAL_SERVER
The target bare metal server.
--vni TARGET_VIRTUAL_NETWORK_INTERFACE
The target virtual network interface.
--resource-group-id RESOURCE_GROUP_ID
The ID of the resource group.
--resource-group-name RESOURCE_GROUP_NAME
The name of the resource group.
--output
Specify output format, only JSON is supported. One of: JSON.
-q, --quiet
Suppress verbose output.

Command examples

  • ibmcloud is floating-ip-reserve cli-vni-ip --vni vni2
  • ibmcloud is floating-ip-reserve cli-vni-ip-1 --vni 1234-a56b7c89-d0e1-234f-678g-901h2ij3k45

Attaching a floating IP to a virtual network interface with the API

To attach a floating IP address to a virtual network interface with the API, follow these steps:

  1. Set up your API environment with the right variables.

  2. Store any additional variables to be used in the API commands; for example:

    • version (string): The API version, in format YYYY-MM-DD.
    • virtual_network_interface_id (string): The virtual network interface identifier.
    • floating_ip_id (string): The floating IP identifier.
  3. When all variables are initiated, attach the floating IP address to the virtual network interface:

    curl -X PUT \
    "$vpc_api_endpoint/v1/virtual_network_interfaces/$virtual_network_interface_id/floating_ips/$floating_ip_id?version=$version&generation=2" \
    -H "Authorization: Bearer $iam_token"
    

Attaching a floating IP to a virtual network interface with Terraform

The following example attaches a floating IP address to a virtual network interface by using Terraform:

resource "ibm_is_virtual_network_interface_floating_ip" "my_vni_floatingip" {
  virtual_network_interface = ibm_is_virtual_network_interface.my_virtual_network_interface.id
  floating_ip = ibm_is_floating_ip.my_floatingip.id
}