Assign a BYOIP IP Address Using Automation
Use the standard reserved IP assign actions to assign BYOIP IP addresses. Substitute a valid address from your prefix for any <reserved-ip> placeholders. The first and second IP address of the BYOIP subnet are reserved.
How to Assign a BYOIP Address Using the DigitalOcean CLI
- Install
doctl, the official DigitalOcean CLI.
- Create a personal access token and save it for use with
doctl.
- Use the token to grant
doctl access to your DigitalOcean account.
- Finally, run
doctl compute reserved-ip-action assign. Basic usage looks like this, but you can read the usage docs for more details:
doctl compute reserved-ip-action assign <reserved-ip> <droplet-id> [flags]
The following example assigns the reserved IP address 203.0.113.25 to a Droplet with the ID 386734086:
doctl compute reserved-ip-action assign 203.0.113.25 386734086
How to Assign a BYOIP Address Using the DigitalOcean API
- Create a personal access token and save it for use with the API.
- Send a POST request to
https://api.digitalocean.com/v2/reserved_ips/{reserved_ip}/actions.
cURL
Using cURL:
# Assign a Reserved IP to a Droplet
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"type":"assign","droplet_id":8219222}' \
"https://api.digitalocean.com/v2/reserved_ips/45.55.96.47/actions"
# Unassign a Reserved IP
# curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"type":"unassign"}' \
"https://api.digitalocean.com/v2/reserved_ips/45.55.96.47/actions"
Go
Using Godo, the official DigitalOcean API client for Go:
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
// Assign a Reserved IP to a Droplet
action, _, err := client.ReservedIPActions.Assign(ctx, "45.55.96.47", 8219222)
// Unassign a Reserved IP
action, _, err := client.ReservedIPActions.Unassign(ctx, "45.55.96.47")
}
Ruby
Using DropletKit, the official DigitalOcean API client for Ruby:
require 'droplet_kit'
token = ENV['DIGITALOCEAN_TOKEN']
client = DropletKit::Client.new(access_token: token)
# Assign a Reserved IP to a Droplet
client.reserved_ip_actions.assign(ip: '45.55.96.47', droplet_id: 8219222)
# Unassign a Reserved IP
# client.reserved_ip_actions.unassign(ip: '45.55.96.47')
Python
Using PyDo, the official DigitalOcean API client for Python:
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
req={
"type": "unassign"
}
resp = client.reserved_ips_actions.post(reserved_ip="49.32.13.21", body=req)
Assign a BYOIP IP Address Using the Control Panel
To assign a BYOIP IP address from the control panel, in the main menu, click Networking, and then click Reserved IPs to see the list of your reserved IPs and BYOIP prefixes.
Find the prefix you’d like to use , and then click Assign to Droplet to open the Assign window.
In the Assign window, type a valid IP address from the prefix, and then select the Droplet to assign it to. The first and second IP address of the BYOIP subnet are reserved.
Afterwards, click Assign IP Address to complete the process.