全部产品
Search
文档中心

NAT 网关:CreateForwardEntry - 在DNAT列表中添加DNAT条目

更新时间:Aug 28, 2026

调用CreateForwardEntry接口在DNAT列表中添加DNAT条目。

接口说明

每条 DNAT 条目由五部分组成,包括 ExternalIp、ExternalPort、IpProtocol、InternalIp 和 InternalPort。添加 DNAT 条目后,NAT 网关会将ExternalIp:ExternalPort上收到的指定协议的报文转发给InternalIp:InternalPort,并将回复消息原路返回。

调用本接口添加 DNAT 条目时,请注意:

  • CreateForwardEntry 接口属于异步接口,即系统会先返回一个 DNAT 条目 ID,但该 DNAT 条目并未添加完成,系统后台的添加任务仍在进行。您可以调用 DescribeForwardTableEntries 查询 DNAT 条目的状态:

    • 当 DNAT 条目处于 Pending 状态时,表示 DNAT 条目正在添加中,在该状态下,您只能执行查询操作,不能执行其他操作。

    • 当 DNAT 条目处于 Available 状态时,表示 DNAT 条目添加完成。

  • 所有 DNAT 条目的 ExternalIp、ExternalPort 和 IpProtocol 三个字段组成的组合必须互不重复,即不允许将同一个源 IP、同一个端口、同一个协议的消息转发到多个目标 ECS 实例。

  • 所有 DNAT 条目的 InternalIp、InternalPort 和 IpProtocol 三个字段组成的组合也必须互不重复。

  • 所有 DNAT 条目的 ExternalIp 和 InternalIp 两个字段的 IP 地址不能相同,如果业务需要两个 IP 地址相同, 请联系商务经理。

  • 一个 DNAT 表最多可添加 100 条 DNAT 条目。

  • DNAT 条目中配置了 IP 映射方式的 IP(公网 NAT 网关使用的 EIP 或 VPC NAT 网关使用的 NAT IP 地址)不能再被其他 DNAT 条目或 SNAT 条目使用。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

调试

授权信息

当前API暂无授权信息透出。

请求参数

名称

类型

必填

描述

示例值

RegionId

string

是

NAT 网关所在的地域 ID。

您可以通过调用 DescribeRegions 接口获取地域 ID。

cn-hangzhou

ForwardTableId

string

是

DNAT 列表的 ID。

ftb-bp1mbjubq34hlcqpa****

ExternalIp

string

是

  • 当为公网 NAT 网关配置 DNAT 条目时,提供公网访问的弹性公网 IP 地址。

  • 当为 VPC NAT 网关配置 DNAT 条目时,提供外部网络访问的 NAT IP 地址。

116.28.XX.XX

ExternalPort

string

是

  • 当为公网 NAT 网关配置 DNAT 条目时, 需要进行端口转发的外部端口或端口段。

    • 输入的端口范围需要在 1~65535 之间。

    • 如果需要在端口段内转发,请在输入时以正斜线(/)隔开起始端口,例如10/20。

    • 如果 ExternalPort 设置为端口段,则 InternalPort 也需要设置为端口段,且端口段的端口个数相同,例如 ExternalPort 设置为10/20,InternalPort 设置为80/90。

  • 当为 VPC NAT 网关配置 DNAT 条目时,NAT IP 地址被外部网络访问的端口,取值范围:1~65535。

8080

InternalIp

string

是

  • 当为公网 NAT 网关配置 DNAT 条目时,需要进行公网通信的 ECS 实例的私网 IP 地址,该私网 IP 地址需满足以下条件:

    • 必须属于 NAT 网关所在的 VPC 的网段。

    • 必须被一个 ECS 实例使用且该实例没有绑定 EIP 时,DNAT 条目才生效。

  • 当为 VPC NAT 网关配置 DNAT 条目时,需要通过 DNAT 规则进行通信的私网 IP 地址。

192.168.XX.XX

InternalPort

string

是

  • 当为公网 NAT 网关配置 DNAT 条目时,需要进行端口转发的内部端口或端口段,取值范围:1~65535。

  • 当为 VPC NAT 网关配置 DNAT 条目时,需要映射的目标 ECS 实例端口,取值范围:1~65535。

80

IpProtocol

string

是

协议类型,取值:

  • TCP:转发 TCP 协议的报文。

  • UDP:转发 UDP 协议的报文。

  • Any:转发所有协议的报文。如果 IpProtocol 配置为 Any,则 ExternalPort 和 InternalPort 也必须配置为 Any,实现 DNAT IP 映射。

TCP

ForwardEntryName

string

否

DNAT 规则的名称。

长度为 2~128 个字符,必须以大小写字母或中文开头,但不能以http://或https://开头。

ForwardEntry-1

ClientToken

string

否

客户端 Token,用于保证请求的幂等性。

从您的客户端生成一个参数值,确保不同请求间该参数值唯一。ClientToken 只支持 ASCII 字符。

说明

若您未指定,则系统自动使用 API 请求的 RequestId 作为 ClientToken 标识。每次 API 请求的 RequestId 可能不一样。

0c593ea1-3bea-11e9-b96b-88e9fe6****

PortBreak

boolean

否

是否开启端口突破,取值:

  • true:开启端口突破。

  • false(默认值):不开启端口突破。

说明

当 DNAT 条目和 SNAT 条目使用同一个公网 IP 地址时,如果您需要配置大于 1024 的端口号,您需要指定 PortBreak 为 true。

false

DryRun

boolean

否

是否只预检此次请求,取值:

  • true:发送检查请求,不会创建 DNAT 条目。检查项包括 AccessKey 是否有效、RAM 用户的授权情况和是否填写了必需参数。如果检查不通过,则返回对应错误。如果检查通过,会返回错误码DryRunOperation。

  • false(默认值):发送正常请求,通过检查后返回 2xx HTTP 状态码并创建 DNAT 条目。

false

返回参数

名称

类型

描述

示例值

object

ForwardEntryId

string

DNAT 条目的 ID。

fwd-119smw5tkasdf****

RequestId

string

请求 ID。

A4AEE536-A97A-40EB-9EBE-53A6948A6928

示例

正常返回示例

JSON格式

{
  "ForwardEntryId": "fwd-119smw5tkasdf****",
  "RequestId": "A4AEE536-A97A-40EB-9EBE-53A6948A6928"
}

错误码

HTTP status code

错误码

错误信息

描述

400 UnsupportedFeature.PrivateLinkEnabled The feature of PrivateLinkEnabled is not supported.
400 UnsupportedFeature.PortSegment The feature of PortSegment is not supported.
400 ExclusiveParam.%sAnd%s The param of %s and %s are mutually exclusive. 参数 %s 和 %s 相互排斥。
400 DuplicatedParam.InternalPort The param of %s is duplicated. InternalPort参数重复或已被占用
400 DuplicatedParam.ExternalPort The param of %s is duplicated. DNAT公网端口%s已被重复占用。
400 OperationFailed.AnyPortConfig Operation failed because any port correspondence any protocol 操作失败. 与其他条目有冲突, 存在任何端口或任何协议类型.
400 OperationUnsupported.ForwardEntry Duplicated destination ip port is unsupported. 不支持重复的目标IP端口。
400 InvalidIp.NotInNatgw The specified Ip not belong to natgateway.
400 QuotaExceeded.ForwardEntry The quota of %s is exceeded, usage %s/%s.
400 IncorrectStatus.NatIp The status of %s [%s] is incorrect. NatIp当前状态不正确。
400 Forbidden.IpHasBeenUsedInSnat The source ip can't be used. Because it has been used in snat.
400 InvalidExternalIp.Malformed The specified ExternalIp is not a valid IP address.
400 InvalidInternalIp.Malformed The specified InternalIp is not a valid IP address.
400 InvalidExternalPort.Malformed The specified ExternalPort is not a valid port.
400 InvalidInternalPort.Malformed The specified InternalPort is not a valid port.
400 Forbidden.DestnationIpOutOfVpcCIDR The specified Internal Ip is Out of VPC CIDR.
400 Forbidden.DestinationIpOutOfVswitchCIDR The specified Internal Ip is Out of VSwitch CIDR.
400 InvalidProtocal.ValueNotSupported The specified IpProtocol does not support.
400 IncorretForwardEntryStatus Some Forward entry status blocked this operation..
400 ForwardEntry.Duplicated The specified ExternalIp, IpProtocol, ExternalPort,InternalIp, InternalPort is duplicated
400 Forbidden.ExternalIp.UsedInSnatTable The specified ExternalIp is already used in SnatTable
400 Forbindden The specified Instance already bind eip
400 Forbidden.InternalIpOutOfVpcCIDR The specified Internal Ip is Out of VPC CIDR.
400 Invalid.natgwNotExist The specified natgateway not exist.
400 MissingParameter Missing mandatory parameter
400 AnyPort.PortMustBeZero any port port must be zero.
400 InvalidParameter.Name.Malformed The specified Name is not valid.
400 IncorrectStatus.ForwardEntry The status of %s [%s] is incorrect. 要删除的DNAT条目实例状态不对
400 Duplicated.DestinationPort The specified param DestinationPort is duplicated.
400 OperationUnsupported.EipInBinding Create snat entry with eip in associating status is unsupported. 创建snat不可以使用绑定中的eip
400 QuotaExceeded.ForwardEntrySessionManytoOne The dnat session quota is exceed. dnat session 多对一的配额超限。
400 TaskConflict The operation is too frequent, please wait a moment and try again. 操作过于频繁,请稍等一会再重试
400 OperationFailed.DnatPortRangeLimit The maximum number of port ranges that can be specified is exceeded. 端口段数量超限。
400 IncorrectStatus.NATGW NATGW status is invalid. NAT网关的状态不正确。
400 OperationFailed.ForwardEntryNotAllowSrcIpEqualDstIp The source IP of forward entry is not allowed to equal destination IP. DNAT条目不允许公网IP地址等于私网IP地址
500 System.Error ERROR SYSTEM ERROR.
500 InternalError The request processing has failed due to some unknown error.
404 ResourceNotFound.NatIp The specified resource of %s is not found.
404 InvalidRegionId.NotFound The specified RegionId does not exist in our records.
404 InvalidForwardTableId.NotFound Specified forward table does not exist.
404 InvalidExternalIp.NotFound Specified External Ip address does not found on the VRouter

访问错误中心查看更多错误码。

变更历史

更多信息,参考变更详情。