# CreateSnatEntry

## 1. 接口描述

本接口(CreateSnatEntry)用于创建SNAT规则。

{% hint style="info" %}
**注意事项**

* 默认一个NAT网关可以创建10条SNAT规则. 如果想扩大可以联系Console Support。
  {% endhint %}

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称             | 必选 | 类型              | 描述                                                                                                                |
| ---------------- | -- | --------------- | ----------------------------------------------------------------------------------------------------------------- |
| natGatewayId     | 是  | String          | NAT网关 ID。                                                                                                         |
| eipIds           | 否  | Array of String | <p>SNAT规则添加的弹性公网IP集合。</p><p>指定的公网IP ID必须属于NAT网关上绑定的公网弹性IP。</p><p>为空则代表与该NAT网关绑定的所有的弹性公网IP。</p>                    |
| cidr             | 否  | String          | <p>源CIDR网段。</p><p>该字段已废弃，请使用<code>sourceCidrBlocks</code>。</p>                                                    |
| sourceCidrBlocks | 否  | Array of String | <p>源CIDR地址段列表。</p><p>与<code>subnetIds</code>必须指定其中的一种。</p><p>如果使用全地址段，指定为<code>0.0.0.0/0</code>。</p>              |
| subnetIds        | 否  | Array of String | <p>指定子网ID集合。</p><p>该参数表示该子网内的实例均可以通过<code>SNAT</code>规则访问外部网络。</p><p>与<code>sourceCidrBlocks</code>必须指定其中的一种。</p> |

## 3. 响应结果

| 参数名称        | 类型     | 描述                                                       |
| ----------- | ------ | -------------------------------------------------------- |
| requestId   | String | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| snatEntryId | String | SNAT规则唯一ID。                                              |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 创建一个子网类型的SNAT。**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateSnatEntry
<Common Request Params>

Request：
{
  "natGatewayId": "<natGatewayId>",
  "subnetIds": ["<subnetId>"],
  "eipIds": ["<eipId>"]
}


Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "snatEntryId": "<snatEntryId>"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/toolkit)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/instruction/commonerrorcode)

| HTTP状态码 | 错误码                                                    | 说明                     |
| ------- | ------------------------------------------------------ | ---------------------- |
| 404     | INVALID\_NAT\_NOT\_FOUND                               | NAT网关不存在。              |
| 400     | OPERATION\_DENIED\_NAT\_STATUS                         | NAT网关状态不是RUNNING。      |
| 404     | INVALID\_EIP\_NOT\_FOUND                               | EIP不存在。                |
| 400     | OPERATION\_DENIED\_EIP\_NOT\_ASSIGNED                  | EIP状态未绑定。              |
| 400     | OPERATION\_DENIED\_EIP\_NOT\_ASSIGN\_NAT               | EIP没有与NAT网关绑定。         |
| 400     | OPERATION\_DENIED\_ANYPORT\_DNAT\_ENTRY                | DNAT规则存在ANY PORT。      |
| 400     | OPERATION\_DENIED\_SNAT\_ENTRY\_COUNT\_LIMIT           | SNAT规则数量限制。            |
| 400     | INVALID\_CIDR\_FORMAT                                  | 指定的cidr格式不正确。          |
| 404     | INVALID\_NAT\_SUBNET\_NOT\_FOUND                       | 指定的subnet在nat网关上不存在。   |
| 400     | OPERATION\_DENIED\_CIDR\_CONFLICT\_WITH\_SNAT\_ENTRY   | 指定的cidr与其它SNAT规则上存在。   |
| 400     | OPERATION\_DENIED\_NAT\_SUBNET\_CONFLICT               | NAT的Subnet配置冲突。        |
| 400     | OPERATION\_DENIED\_NAT\_ENTRY\_CONFIG\_CONFLICT        | NAT规则配置冲突。             |
| 400     | OPERATION\_DENIED\_SUBNET\_CONFLICT\_WITH\_SNAT\_ENTRY | 指定的subnet在其它SNAT规则上存在。 |


---

# Agent Instructions: 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:

```
GET https://docs.console.zenlayer.com/api-reference/cn/compute/zec/nat-gateway/createsnatentry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
