Floating IPs

Floating IPs are permanent, project-scoped resources which bind an individual IP address from a given IP pool. They allow for well-known addresses to be allocated (explicitly or automatically) and assigned to target instances, making it easier to host services from a consistent address.

Floating IP Lifecycle

Floating IPs are created within a project, and take ownership of an IP address from an available IP pool for their lifetime. A floating IP may then be attached to an instance during its creation or using the floating_ip_attach endpoint, and detached when that same instance is destroyed or via the floating_ip_detach endpoint.

A floating IP must be detached from an instance before it can be either deleted or attached to another instance. Once deleted, the address held by a floating IP resource is released back into its original IP pool.

Creating and Attaching Floating IPs

Here are some example workflows for using floating IPs with VM instances. In the below examples we assume the default IP pool provides 192.168.32.1192.168.32.254, and that a pool named alternate-pool provides 192.168.64.64192.168.64.72.

Example 1: Create a floating IP

If neither an address or pool is specified, we are allocated the next available IP from the default pool:

oxide floating-ip create \
--project cafe \
--name rootbeer-float \
--description "A classic."

success
FloatingIp {
description: "A classic.",
id: 3ca0ccb7-d66d-4fde-a871-ab9855eaea8e,
instance_id: None,
ip: 192.168.32.1,
name: Name(
"rootbeer-float",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:32:54.348543Z,
time_modified: 2023-12-07T20:32:54.348543Z,
}

Example 2: Create a floating IP from a given pool

The above example shows how a floating IP takes the first free IP address within the default pool. We can instead choose any other pool visible from within the target project:

oxide floating-ip create \
--project cafe \
--name cola-float \
--description "A favourite." \
--pool alternate-pool

success
FloatingIp {
description: "A favourite.",
id: 0a00a6c3-4821-4bb8-af77-574468ac6651,
instance_id: None,
ip: 192.168.64.64,
name: Name(
"cola-float",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:40:44.950744Z,
time_modified: 2023-12-07T20:40:44.950744Z,
}

Example 3: Create a floating IP for a specific address

When allocating a floating IP for use by a given service, we often want to use a particular IP address. This can be specified during creation:

oxide floating-ip create \
--project myproj \
--name affogato \
--description "A reverse float." \
--address 192.168.32.32

success
FloatingIp {
description: "A reverse float.",
id: 2568f5c7-dfd2-45f0-b338-03f34750c18f,
instance_id: None,
ip: 192.168.32.32,
name: Name(
"affogato",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:47:16.894596Z,
time_modified: 2023-12-07T20:47:16.894596Z,
}
Important
If a specific IP address is not present in the default pool, you must specify the correct pool name as in Example 2. For example, if you wanted to allocate 192.168.64.71, you must also specify --pool alternate-pool.

Example 4: Create an instance bound to one or more floating IPs

Now that we have allocated some floating IPs, we are ready to attach them to an instance within our project. floating IPs can be associated with an instance when it is being created:

oxide instance create --project myproj --json-body instance-define.json

success
Instance {
description: "We serve floats!",
hostname: "menu-server",
id: 8b14cd0b-ce93-4ee5-80ae-1b8c9d871e98,
memory: ByteCount(
1073741824,
),
name: Name(
"menu",
),
ncpus: InstanceCpuCount(
2,
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
run_state: Starting,
time_created: 2023-12-08T09:40:34.440580Z,
time_modified: 2023-12-08T09:40:34.440580Z,
time_run_state_updated: 2023-12-08T09:40:51.213975Z,
}
instance-define.json
{
"name": "menu",
"description": "We serve floats!",
"hostname": "menu-server",
"memory": 1073741824,
"ncpus": 2,
"disks": [
{
"type": "attach",
"name": "alpine"
}
],
"external_ips": [
{"type": "ephemeral"},
{"type": "floating", "floating_ip": "cola-float"}
]
}

This command creates an instance with a new ephemeral IP and attaches one of the above floating IPs. Once the instance is deleted, these will be detached and the floating IP will be available for reuse.

Tip
Multiple floating IPs (and a single ephemeral IP) can be attached to a given instance. This allows a host to send and receive VPC-external traffic on several addresses. See the 'Networking' guide for the exact semantics.

Example 5: View and list floating IPs

Floating IPs can be viewed on an individual basis:

oxide floating-ip view --project cafe --floating-ip cola-float

success
FloatingIp {
description: "A favourite.",
id: 0a00a6c3-4821-4bb8-af77-574468ac6651,
instance_id: Some(
8b14cd0b-ce93-4ee5-80ae-1b8c9d871e98,
),
ip: 192.168.64.64,
name: Name(
"cola-float",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:40:44.950744Z,
time_modified: 2023-12-08T09:40:35.188495Z,
}

Similarly, we can also view all floating IPs within a project using the command:

oxide floating-ip list --project cafe

Floating IPs retrieved either way show whether they are attached to an instance by their instance_id field.

Example 6: Delete a floating IP

To release a floating IP so that it may be reused elsewhere, we can delete the resource:

oxide floating-ip delete \
--project cafe \
--floating-ip affogato

success
()
Important
A floating IP can only be deleted once it has been detached from any instances. Deleting an IP with a non-null instance_id will return an HTTP 400 Bad Request.

Example 7: Attach and detach a floating IP from an existing instance

Floating IPs may be attached and detached from any instance which is started or stopped. To attach an address to an instance:

oxide floating-ip attach \
--instance menu \
--project cafe \
--floating-ip rootbeer-float

success
FloatingIp {
description: "A classic.",
id: 3ca0ccb7-d66d-4fde-a871-ab9855eaea8e,
instance_id: Some(
8b14cd0b-ce93-4ee5-80ae-1b8c9d871e98
),
ip: 192.168.32.1,
name: Name(
"rootbeer-float",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:32:54.348543Z,
time_modified: 2024-01-24T12:31:29.000000Z,
}

And to detach a floating IP from an instance:

oxide floating-ip detach --project cafe --floating-ip cola-float

success
FloatingIp {
description: "A favourite.",
id: 0a00a6c3-4821-4bb8-af77-574468ac6651,
instance_id: None,
ip: 192.168.64.64,
name: Name(
"cola-float",
),
project_id: 99302cd1-3a45-42ff-9f3c-f32c67e3d50a,
time_created: 2023-12-07T20:40:44.950744Z,
time_modified: 2024-01-24T12:32:17.000000Z,
}

cola-float is now ready to be reassigned to another instance, if desired. Ephemeral IPs can be configured in a similar manner:

oxide instance external-ip detach-ephemeral \
--instance menu \
--project cafe

success
()

oxide instance external-ip attach-ephemeral \
--instance menu \
--project cafe

success
Ephemeral {
ip: 192.168.32.3,
}
Last updated