How to Create Reserved IPs

A DigitalOcean Reserved IP address is a publicly-accessible static IP address that you can assign to a Droplet and then reassign to another Droplet later, as needed. You can implement a failover mechanism with reserved IPs to build a high availability infrastructure.


Create a Reserved IP Using the CLI

The Reserved IP creation command requires you to assign the IP address to a Droplet upon creation using the Droplet’s ID. You can retrieve a list of Droplets and their IDs using the doctl compute droplet list command.

How to create a Reserved IP using the DigitalOcean CLI

To create a Reserved IP via the command-line, follow these steps:

  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token, and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

                  doctl auth init
                
  4. Finally, create a Reserved IP with doctl compute reserved-ip create. The basic usage looks like this, but you'll want to read the usage docs for more details:

                  doctl compute reserved-ip create [flags]
                

    The following example creates a reserved IP address in the nyc1 region and assigns it to a Droplet with the ID 386734086

                   doctl compute reserved-ip create --region nyc1 --droplet-id 386734086
                

Create a Reserved IP Using the API

The Reserved IP creation call requires you to assign the IP address to a Droplet upon creation using the Droplet’s ID. You can retrieve a list of Droplets and their IDs using the /v2/droplets endpoint.

How to create a Reserved IP using the DigitalOcean API

To create a Reserved IP using the DigitalOcean API, follow these steps:

  1. Create a personal access token, and save it for use with the API.

  2. Send a POST request to https://api.digitalocean.com/v2/reserved_ips

    cURL

    To create a Reserved IP with cURL, call:

    
                    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"droplet_id": 123456}' \
      "https://api.digitalocean.com/v2/reserved_ips" 

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To create a Reserved IP with Godo, use the following code:

    
                    import (
        "context"
        "os"
    
        "github.com/digitalocean/godo"
    )
    
    func main() {
        token := os.Getenv("DIGITALOCEAN_TOKEN")
    
        client := godo.NewFromToken(token)
        ctx := context.TODO()
    
        createRequest := &godo.ReservedIPCreateRequest{
            DropletID: 123456,
    
        }
    }

    Ruby

    Ruby developers can use DropletKit, the official DigitalOcean V2 API client for Ruby. To create a Reserved IP with DropletKit, use the following code:

    
                    require 'droplet_kit'
    token = ENV['DIGITALOCEAN_TOKEN']
    client = DropletKit::Client.new(access_token: token)
    
    reserved_ip = DropletKit::ReservedIp.new(droplet_id: 123456)
    client.reserved_ips.create(reserved_ip) 

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "droplet_id": 2457247
    }
    
    resp = client.reserved_ips.create(body=req)

Create a Reserved IP Using the Control Panel

To create a reserved IP from the control panel, click Create in the top right, then click Reserved IP.

Create menu

This takes you to the Reserved IPs page. When you have no reserved IPs, this page invites you to choose a Droplet and assign one.

To reserve and assign a reserved IP to one of your Droplets, locate the Droplet using the Search for a Droplet text box, then click Assign Reserved IP.

Note
If you try to assign a reserved IP to a Droplet created before 20 October 2015, a window will open with instructions on how to enable reserved IPs on older Droplets.

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