> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/network-services/nat-gateway/api-howtos/create-managed-nat-gateway.md).

# Create a Managed NAT Gateway

The NAT Gateway service allows instances in a private subnet to connect to the Internet or other services but prevents inbound connections from the Internet. To create a NAT gateway, use a `POST` request to specify the data center, public IP addresses, and the LANs that will route through it.

## Endpoint

`https://api.ionos.com/cloudapi/v6/datacenters/{datacenterId}/natgateways`

## Request

```bash
curl --location \
--request POST 'https://api.ionos.com/cloudapi/v6/datacenters/15f67991-0f51-4efc-a8ad-ef1fb31a480c/natgateways' \
--header 'Authorization: Bearer $IONOS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "properties": {
    "name": "Production NAT Gateway",
    "publicIps": [
      "198.51.100.25"
    ],
    "lans": [
      {
        "id": "2",
        "gatewayIps": [
          "192.168.1.5"
        ]
      }
    ]
  }
}'
```

{% tabs %}
{% tab title="Request Body Parameters" %}
The following table lists the request body parameters:

| **Body Parameters**            | **Required** | **Type** | **Description**                                                                                                                                                                                | **Example**              |
| ------------------------------ | ------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| `properties.name`              | yes          | string   | The name of the resource.                                                                                                                                                                      | `Production NAT Gateway` |
| `properties.publicIps`         | yes          | array    | A collection of public IP addresses. Use an IP address that you have reserved for this location.                                                                                               | `["198.51.100.25"]`      |
| `properties.lans`              | no           | array    | A collection of LANs connected to the NAT gateway. Include a valid subnet mask for each IP address. If you do not provide an IP address, the system generates an IP address with a /24 subnet. | See nested object below. |
| `properties.lans[].id`         | yes          | string   | The ID of the LAN connected to the NAT gateway.                                                                                                                                                | `2`                      |
| `properties.lans[].gatewayIps` | no           | array    | A collection of gateway IP addresses. The system auto-generates these if you do not provide them. These addresses must stay within the LAN's IP address range.                                 | `["192.168.1.5"]`        |
| {% endtab %}                   |              |          |                                                                                                                                                                                                |                          |

{% tab title="Request Header Parameters" %}
Include the following mandatory fields in the request header to authenticate your requests:

| **Header Parameters** | **Required** | **Type** | **Description**                                                             |
| --------------------- | ------------ | -------- | --------------------------------------------------------------------------- |
| `Authorization`       | yes          | string   | Use a Bearer token to authenticate requests through a JSON Web Token (JWT). |
| `Content-Type`        | yes          | string   | Set it to `application/json`.                                               |
| {% endtab %}          |              |          |                                                                             |
| {% endtabs %}         |              |          |                                                                             |

## Response

A **202 Accepted** response indicates that the creation of the NAT Gateway has been initiated successfully. The response body contains the `resource id` and other deployment details.

{% hint style="info" %}
**Note:** NAT Gateway creation is performed asynchronously. The resource status maintains a `BUSY` status until provisioning completes. For core Cloud API endpoints, the response includes a `Location` header with a URL to poll the request status.
{% endhint %}

```json
{
  "id": "b63911b7-5f86-48f7-8d5f-86b85e0e993e",
  "type": "natgateway",
  "href": "https://api.ionos.com/cloudapi/v6/datacenters/15f67991-0f51-4efc-a8ad-ef1fb31a480c/natgateways/b63911b7-5f86-48f7-8d5f-86b85e0e993e",
  "metadata": {
    "etag": "45480eb3fbfc31f1d916c1eaa4abdcc3",
    "createdDate": "2024-01-15T10:45:30+00:00",
    "createdBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "createdByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedDate": "2024-01-15T10:45:30+00:00",
    "lastModifiedBy": "ionos:identity:::users/87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "lastModifiedByUserId": "87f9a82e-b28d-49ed-9d04-fba2c0459cd3",
    "state": "BUSY"
  },
  "properties": {
    "name": "Production NAT Gateway",
    "publicIps": [
      "198.51.100.25"
    ],
    "lans": [
      {
        "id": 2,
        "gatewayIps": [
          "192.168.1.5"
        ]
      }
    ]
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ionos.com/cloud/network-services/nat-gateway/api-howtos/create-managed-nat-gateway.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
