How To Use Floating IPs on DigitalOcean
How To Use Floating IPs on DigitalOcean
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Use Floating IPs on DigitalOcean

UpdatedApril 18, 2018 215.6k views Networking DigitalOcean High Availability Load Balancing Product Documentation

Introduction

A DigitalOcean Floating IP is a publicly-accessible static IP address that you can assign to a Droplet. It provides an additional static address you can use to access a Droplet without replacing or changing the Droplet's original public IP.

Floating IPs can be instantly remapped from one Droplet to another in the same datacenter. This functionality is available via both the DigitalOcean Control Panel and the DigitalOcean API. You can use the API for automatic reassignment, like a failover mechanism as part of a high availability server infrastructure.

When Should I Use Floating IPs?

The instant remapping capability of Floating IPs allows you to add redundancy to the entry point, or gateway, to your servers. This is a key component in a high availability server infrastructure, which is a setup with no single points of failure. A complete HA setup requires redundancy at every layer of your infrastructure, including your application and database servers.

DigitalOcean Floating IPs At a Glance

  • Cost: Free when assigned to a Droplet. $.006/hour when unassigned.
  • Regional availability: All regions.
  • Limits:
    • Floating IPs are created in specific datacenters and can only be assigned to Droplets within the same datacenter.
    • By default you can reserve three Floating IPs per account. If you reach this limit, you can request more through the Control Panel interface.
  • Additional information:
    • A Droplet must have an anchor IP before a Floating IP can be assigned to it. Droplets created after October 20, 2015 automatically have an anchor IP, and you can create an anchor IP on older Droplets.

Managing DigitalOcean Floating IPs

To manage your Floating IPs via the DigitalOcean Control Panel, click the Networking link in the main navigation, then choose Floating IPs. When you have no Floating IPs, you'll be invited to choose a Droplet and assign one:

No Floating IPs

To reserve and assign a Floating IP to one of your Droplets, locate it using the Search for a Droplet, then click the Assign Floating IP button.

Floating IPs are free to use as long as they are attached to a Droplet. Due to limited IPv4 availability, we charge $0.006 per hour for floating IPs that have been reserved but not assigned to a Droplet.

Note: If you assign a Floating IP to a Droplet that was created before October 20, 2015, you will be presented with a modal message including instructions for enabling Floating IPs with older Droplets.

Once you have at least one address assigned, you can reserve additional Floating IP addresses in specific datacenters without assigning them to Droplets by following the click here link in the header text.

The floating IP Addresses are listed in the Floating IPs table:

Floating IP Assigned

For each floating IP, the following details are provided:

  • Address: The Floating IP address, which is how it can be accessed and also how it is internally identified.
  • Datacenter: The datacenter in which the Floating IP was created. A Floating IP can only be assigned to Droplets within the same datacenter.
  • Droplet: The Droplet that the Floating IP is assigned to. Requests sent to the Floating IP address will be directed to this Droplet. This can also be set to "Unassigned", which means the Floating IP is reserved but will not pass network traffic to any Droplet.

In addition, each floating IP has a More menu.

Floating IP More menu

From the More menu, you can choose to:

  • Reassign the Floating IP to a different Droplet within the same datacenter.
  • Unassign the Floating IP. Once it is unassigned, you will be charged until it is deleted or reassigned.
  • Delete the Floating IP from your account.

Droplet Anchor IPs

Network traffic between a Floating IP and a Droplet flows through an anchor IP, which is an IP address aliased to the Droplet's public network interface (eth0). As such, a Droplet must have an anchor IP before you can assign a Floating IP to it. Droplets created after October 20, 2015 automatically have an anchor IP, and you can add an anchor IP to older Droplets to use a Floating IP with them.

An anchor IP is only accessible to the Droplet that it belongs to and the Floating IP that is assigned to the Droplet. You should bind any public services that you want to make highly available through a Floating IP to the anchor IP.

For example, if you are using a Floating IP in an active/passive load balancer setup, you should bind your load balancer services to their respective Droplet anchor IPs so they can only be accessed via the Floating IP address. This prevents your users from using the public IP addresses of your Droplets to bypass your Floating IP.

Getting Anchor and Floating IP Information

To retrieve your Droplet's anchor IP, you can use something like ip addr show eth0, but the easiest way is using the Droplet Metadata service. One way to do this is running the following command on the Droplet:

  • curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address

You can get other information about the anchor IP, like its netmask or gateway, by replacing the final /address in the command above with /netmask or /gateway respectively

A Droplet can also see if it has a Floating IP assigned to itself by using Metadata. One way to do this is by running the following command on the Droplet, which will return a true or false response:

  • curl -s http://169.254.169.254/metadata/v1/floating_ip/ipv4/active

If a Floating IP is assigned, the Droplet can similarly retrieve the address of the Floating IP:

  • curl -s http://169.254.169.254/metadata/v1/floating_ip/ipv4/ip_address

This information can be very useful when implementing an HA server setup.

See the API Metadata documentation for more details.

What's Next?

While you can manage your Floating IPs using the Control Panel, the same functionality is also available in the DigitalOcean API with the added benefit of allowing you to programmatically make changes.

Here are some additional resources on managing Floating IPs with the DO API:

However, a Floating IP alone does not automatically provide high availability. For a setup to be highly available, you need to implement a failover mechanism, which automates the process of detecting failures of the active server and reassigning the Floating IP to a passive server.

Active/passive Diagram

Here are several tutorials that will walk you through the creation of various active/passive high availability setups. Each tutorial uses a different software solution to achieve HA, so choose the one that is the best fit for your needs.

69 Comments

Creative Commons License