---
title: How to Use a BYOIP Address with a NAT Gateway
description: Assign one of your own BYOIP addresses as the public egress IP when you create a NAT gateway.
product: Networking
url: https://docs.digitalocean.com/products/networking/vpc/how-to/use-byoip-nat-gateway/
last_updated: "2026-09-03"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# How to Use a BYOIP Address with a NAT Gateway

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)](https://docs.digitalocean.com/products/networking/reserved-ips/how-to/provision-byoip/index.html.md) 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](https://docs.digitalocean.com/products/networking/reserved-ips/how-to/provision-byoip/index.html.md).
- 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`](https://docs.digitalocean.com/reference/doctl/reference/compute/vpc-nat-gateway/create/index.html.md) command:

```shell
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:

```shell
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](https://docs.digitalocean.com/reference/api/reference/vpc-nat-gateways/index.html.md#vpcnatgateways_create). The following example payload creates a NAT gateway that uses a BYOIP address:

```json
{
  "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](https://docs.digitalocean.com/products/networking/vpc/how-to/create-nat-gateway/index.html.md#create-a-nat-gateway-using-the-control-panel). 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.