How to Use a BYOIP Address with a NAT Gateway

Last verified 3 Sep 2026

A Virtual Private Cloud (VPC) is a private network interface for collections of DigitalOcean resources. VPC networks are inaccessible from the public internet and other VPC networks, and traffic on them doesn’t count against bandwidth usage. You can link VPC networks to each other using VPC peering connections.

When you create a public NAT gateway, you can assign an IP address from one of your Bring Your Own IP (BYOIP) prefixes as the gateway’s public egress IP address instead of receiving a randomly assigned DigitalOcean IP address. This lets outbound traffic from your VPC resources use an address you already own and control.

You can only set a BYOIP address when you create the NAT gateway. You cannot change the address afterward.

Prerequisites

  • An Active, advertised BYOIP prefix in the same region as the NAT gateway you want to create. To bring a prefix to DigitalOcean, see How to Provision a BYOIP Prefix.
  • An unassigned IP address from that prefix. The first and second IP addresses of a BYOIP subnet are reserved and cannot be assigned.

Use a BYOIP Address Using the CLI

To assign a BYOIP address when you create a NAT gateway using doctl version v1.165.0 or higher, pass the address to the --ip flag of the doctl compute vpc-nat-gateway create command:

doctl compute vpc-nat-gateway create \
  --name example-nat-gateway \
  --type PUBLIC \
  --region nyc3 \
  --size 1 \
  --vpcs <your-vpc-id> \
  --ip <your-byoip-address>

Replace <your-byoip-address> with an unassigned address from one of your BYOIP prefixes in the same region as the NAT gateway, and <your-vpc-id> with the ID of the VPC network to place the gateway in. The --ip flag is create-only. Omit the flag to receive a randomly assigned DigitalOcean IP address as the public egress IP.

To confirm the assignment, get the NAT gateway and check that its public egress IPv4 address matches the address you provided:

doctl compute vpc-nat-gateway get <gateway-id>

Use a BYOIP Address Using the API

To assign a BYOIP address through the API, include the address in the egresses.public_gateways array of your NAT gateway create request. The following example payload creates a NAT gateway that uses a BYOIP address:

{
  "name": "example-nat-gateway",
  "type": "PUBLIC",
  "region": "nyc3",
  "size": 1,
  "vpcs": [
    { "vpc_uuid": "<your-vpc-id>" }
  ],
  "egresses": {
    "public_gateways": [
      { "ip": "<your-byoip-address>" }
    ]
  }
}

Replace <your-byoip-address> with an unassigned address from one of your BYOIP prefixes in the same region as the NAT gateway, and <your-vpc-id> with the ID of the VPC network to place the gateway in. The egresses block is create-only. Omit it to receive a randomly assigned DigitalOcean IP address as the public egress IP.

Use a BYOIP Address Using the Control Panel

Follow the standard NAT gateway creation flow in How to Create a NAT Gateway. On the Create NAT Gateway page, complete the region, VPC, and size sections as usual.

In the IP Address section, do the following:

  1. Select Assign an address from Bring Your Own IP (BYOIP). The default option assigns a random address after the NAT gateway is created.

  2. From Select a BYOIP prefix, choose one of your BYOIP prefixes. Only Active prefixes in the NAT gateway’s region appear. If none are available, the form displays No active BYOIP prefixes are available in this region.

  3. In the IP address field, enter an unassigned address from the selected prefix, such as 203.0.113.42.

Complete the rest of the form, then click Create NAT Gateway. The NAT gateway provisions with the BYOIP address you selected as its public egress IP.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.