全部產品
Search
文件中心

NAT Gateway:CreateForwardEntry - 在DNAT列表中添加DNAT條目

更新時間:Apr 27, 2026

調用CreateForwardEntry介面在DNAT列表中添加DNAT條目。

介面說明

每條 DNAT 條目由五部分組成,包括 ExternalIpExternalPortIpProtocolInternalIpInternalPort。添加 DNAT 條目後,NAT Gateway會將ExternalIp:ExternalPort上收到的指定協議的報文轉寄給InternalIp:InternalPort,並將回複訊息原路返回。

調用本介面添加 DNAT 條目時,請注意:

  • CreateForwardEntry 介面屬於非同步介面,即系統會先返回一個 DNAT 條目 ID,但該 DNAT 條目並未添加完成,系統背景新增工作仍在進行。您可以調用 DescribeForwardTableEntries 查詢 DNAT 條目的狀態:

    • 當 DNAT 條目處於 Pending 狀態時,表示 DNAT 條目正在添加中,在該狀態下,您只能執行查詢操作,不能執行其他動作。

    • 當 DNAT 條目處於 Available 狀態時,表示 DNAT 條目添加完成。

  • 所有 DNAT 條目的 ExternalIpExternalPortIpProtocol 三個欄位組成的組合必須互不重複,即不允許將同一個源 IP、同一個連接埠、同一個協議的訊息轉寄到多個目標 ECS 執行個體。

  • 所有 DNAT 條目的 InternalIpInternalPortIpProtocol 三個欄位組成的組合也必須互不重複。

  • 所有 DNAT 條目的 ExternalIpInternalIp 兩個欄位的 IP 位址不能相同,如果業務需要兩個 IP 位址相同, 請聯絡商務經理。

  • 一個 DNAT 表最多可添加 100 條 DNAT 條目。

  • DNAT 條目中配置了 IP 映射方式的 IP(公網 NAT Gateway使用的 EIP 或 VPC NAT Gateway使用的 NAT IP 位址)不能再被其他 DNAT 條目或 SNAT 條目使用。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

當前API暫無授權資訊透出。

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

NAT Gateway所在的地區 ID。

您可以通過調用 DescribeRegions 介面擷取地區 ID。

cn-hangzhou

ForwardTableId

string

DNAT 列表的 ID。

ftb-bp1mbjubq34hlcqpa****

ExternalIp

string

  • 當為公網 NAT Gateway配置 DNAT 條目時,提供公網訪問的彈性公網 IP 位址。

  • 當為 VPC NAT Gateway配置 DNAT 條目時,提供外部網路訪問的 NAT IP 位址。

116.28.XX.XX

ExternalPort

string

  • 當為公網 NAT Gateway配置 DNAT 條目時, 需要進行連接埠轉寄的外部連接埠或連接埠段。

    • 輸入的連接埠範圍需要在 1~65535 之間。

    • 如果需要在連接埠段內轉寄,請在輸入時以正斜線(/)隔開開始端點口,例如10/20

    • 如果 ExternalPort 設定為連接埠段,則 InternalPort 也需要設定為連接埠段,且連接埠段的連接埠個數相同,例如 ExternalPort 設定為10/20InternalPort 設定為80/90

  • 當為 VPC NAT Gateway配置 DNAT 條目時,NAT IP 位址被外部網路訪問的連接埠,取值範圍:1~65535

8080

InternalIp

string

  • 當為公網 NAT Gateway配置 DNAT 條目時,需要進行公網通訊的 ECS 執行個體的私網 IP 位址,該私網 IP 位址需滿足以下條件:

    • 必須屬於 NAT Gateway所在的 VPC 的網段。

    • 必須被一個 ECS 執行個體使用且該執行個體沒有綁定 EIP 時,DNAT 條目才生效。

  • 當為 VPC NAT Gateway配置 DNAT 條目時,需要通過 DNAT 規則進行通訊的私網 IP 位址。

192.168.XX.XX

InternalPort

string

  • 當為公網 NAT Gateway配置 DNAT 條目時,需要進行連接埠轉寄的內部連接埠或連接埠段,取值範圍:1~65535

  • 當為 VPC NAT Gateway配置 DNAT 條目時,需要映射的目標 ECS 執行個體連接埠,取值範圍:1~65535

80

IpProtocol

string

協議類型,取值:

  • TCP:轉寄 TCP 協議的報文。

  • UDP:轉寄 UDP 協議的報文。

  • Any:轉寄所有協議的報文。如果 IpProtocol 配置為 Any,則 ExternalPortInternalPort 也必須配置為 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 的連接埠號碼,您需要指定 PortBreaktrue

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 Gateway的狀態不正確。
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

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情