全部產品
Search
文件中心

NAT Gateway:CreateNatGateway

更新時間:Oct 15, 2026

呼叫CreateNatGateway介面建立增強型公網NAT閘道器或VPC NAT閘道器。

介面說明

在呼叫本介面時,請了解以下內容:

  • 首次建立 NAT 閘道器時,系統會自動建立一個名稱為 AliyunServiceRoleForNatgw 的服務關聯角色,並且為該角色新增名稱為 AliyunServiceRolePolicyForNatgw 的權限原則,授予 NAT 閘道器擁有存取其他雲端資源的權限。更多資訊,請參見服務關聯角色。

  • 增強型公網 NAT 閘道器建立後,系統會在 VPC 的路由表中自動新增一條目標網段為 0.0.0.0/0,下一跳為 NAT 閘道器的路由項目,用於將流量路由到 NAT 閘道器。

  • CreateNatGateway 介面屬於非同步介面,即系統會先返回一個 NAT 閘道器(公網 NAT 閘道器或 VPC NAT 閘道器)執行個體 ID,但該 NAT 閘道器執行個體並未建立完成,系統背景的建立任務仍在進行。您可以呼叫 DescribeNatGateways 查詢 NAT 閘道器的狀態。

    • 當 NAT 閘道器處於 Creating 狀態時,表示 NAT 閘道器正在建立中,在該狀態下,您只能執行查詢操作,不能執行其他操作。

    • 當 NAT 閘道器處於 Available 狀態時,表示 NAT 閘道器建立完成。

NAT 閘道器建立一般需要 1~3 分鐘,請您耐心等待。

調試

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

調試

授權資訊

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

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

是

NAT 閘道器所在的地域 ID。

您可以透過呼叫 DescribeRegions 介面取得地域 ID。

cn-hangzhou

VpcId

string

是

需要建立 NAT 閘道器的 VPC 的 ID。

vpc-bp1di7uewzmtvfuq8****

Name

string

否

NAT 閘道器的名稱。

名稱長度為 2~128 個字元,以大小寫字母或中文開頭,可包含數字、底線(_)和短橫線(-)。

如果沒有指定該參數,系統會為 NAT 閘道器建立預設的名稱。

fortest

Description

string

否

NAT 閘道器的描述。

描述可以為空;或填寫 2~256 個字元,不能以http://或https://開頭。

testnat

ClientToken

string

否

用戶端 Token,用於保證請求的冪等性。

由用戶端產生該參數值,要保證在不同請求間唯一。

說明

若您未指定,則系統自動使用 API 請求的 RequestId 作為 ClientToken 標識。每次 API 請求的 RequestId 可能不一樣。

5A2CFF0E-5718-45B5-9D4D-70B3FF3898

Spec

string

否

包年包月公網 NAT 閘道器已停止新購,該參數不再使用。

無效參數

InstanceChargeType

string

否

NAT 閘道器的付費模式,取值:

PostPaid(預設值):按量付費。

更多資訊,請參見公網 NAT 閘道器計費和VPC NAT 閘道器計費。

PostPaid

PricingCycle

string

否

包年包月公網 NAT 閘道器已停止新購,該參數不再使用。

無效參數

Duration

string

否

包年包月公網 NAT 閘道器已停止新購,該參數不再使用。

無效參數

AutoPay

boolean

否

包年包月公網 NAT 閘道器已停止新購,該參數不再使用。

重要 該參數已棄用。

false

VSwitchId

string

否

NAT 閘道器所屬的交換器的 ID。

建立 NAT 閘道器時,您必須指定 NAT 閘道器所屬的交換器,系統會為 NAT 閘道器分配一個交換器內的空閒私網 IP 位址。

  • 如果您要在現有交換器中建立 NAT 閘道器,請確保交換器所屬的可用區支援建立 NAT 閘道器,且交換器有可用的 IP。

  • 如果您還未建立交換器,請先在支援建立 NAT 閘道器的可用區建立交換器,然後再指定 NAT 閘道器所屬的交換器。

說明

您可以透過 ListEnhanhcedNatGatewayAvailableZones 介面查詢 NAT 閘道器的資源可用區,透過 DescribeVSwitches 介面查詢交換器中的可用 IP 數。

vsw-bp1e3se98n9fq8hle****

NatType

string

否

NAT 閘道器的類型,取值:Enhanced,增強型 NAT 閘道器。

Enhanced

InternetChargeType

string

否

NAT 閘道器的計費類型,取值:PayByLcu,表示按使用量計費。

PayByLcu

NetworkType

string

否

建立的 NAT 閘道器類型,取值:

  • internet:公網 NAT 閘道器。

  • intranet:VPC NAT 閘道器。

internet

SecurityProtectionEnabled deprecated

boolean

否

是否開啟防火牆功能,取值:

  • false(預設值):不開啟。
    重要 該參數已棄用。

false

IcmpReplyEnabled

boolean

否

是否開啟 ICMP 代回。取值:

  • true(預設值):開啟。

  • false:不開啟。

true

PrivateLinkEnabled

boolean

否

是否開啟私網連線。取值:

  • true:開啟私網連線。

  • false(預設值):不開啟私網連線。

false

EipBindMode

string

否

NAT 閘道器的 EIP 綁定模式,取值:

  • MULTI_BINDED(預設值):多 EIP 網卡可見模式。

  • NAT:EIP 普通模式,相容 IPv4 閘道器。
    說明

    NAT 閘道器的 EIP 綁定模式為 EIP 普通模式時,EIP 將佔用 NAT 閘道器所在交換器的一個私網 IP,請確保 NAT 閘道器所在交換器內私網 IP 位址充足,如果 NAT 閘道器所在的交換器沒有可用的空閒私網位址時,將無法綁定新的 EIP。NAT 閘道器的 EIP 綁定模式為 EIP 普通模式時,NAT 閘道器支援綁定的 EIP 數量上限為 50 個。

MULTI_BINDED

Tag

array<object>

否

標籤清單。

MULTI_BINDED

object

否

Key

string

否

標籤鍵。API 呼叫時使用 Tag.N.Key 的形式,N 的取值範圍:1~20。一旦傳入該值,則不允許為空字串。最多支援 128 個字元,不能以 aliyun 或 acs:開頭,不能包含 http://或 https://。

TestKey

Value

string

否

標籤值。API 呼叫時使用 Tag.N.Value 的形式,N 的取值範圍:1~20。一旦傳入該值,則不允許為空字串。最多支援 128 個字元,不能以 aliyun 或 acs:開頭,不能包含 http://或 https://。

TestValue

AccessMode

object

否

反向存取 VPC NAT 閘道器的存取模式。

MULTI_BINDED

ModeValue

string

否

存取模式取值:

  • route:路由模式。

  • tunnel:隧道模式。

說明

當此欄位取值時,PrivateLinkEnabled 欄位,必須為:true。

route

TunnelType

string

否

隧道模式類型:

  • geneve: Geneve 類型。

說明

當存取模式為隧道模式時此值有效。

geneve

NatIp

string

否

NAT 閘道器佔用的私網 IP 位址。請使用 NAT 所在交換器網段中未分配的 IP,當為空時會隨機分配 IP 位址。

說明

只對 VPC NAT 閘道器生效。

192.168.0.2

Ipv4Prefix

string

否

建立 IP 首碼位址段,用於批次建立 NAT IP。請使用 NAT 所在交換器中未分配的預留網段。

說明

只對 VPC NAT 閘道器生效。

192.168.0.0/28

AvailabilityMode

string

否

NAT 閘道器的容災類型:

  • CrossAZ:跨可用區容災。

  • SingleAZ:單可用區容災。

CrossAZ

返回參數

名稱

類型

描述

樣本值

object

返回資料結構體。

NatGatewayId

string

建立的 NAT 閘道器的執行個體 ID。

ngw-112za33e4****

RequestId

string

請求 ID。

2315DEB7-5E92-423A-91F7-4C1EC9AD97C3

ForwardTableIds

object

ForwardTableId

array

DNAT 清單。

string

DNAT 清單。

ftb-11tc6xgmv****

SnatTableIds

object

SnatTableId

array

SNAT 清單。

string

SNAT 清單。

stb-SnatTableIds****

FullNatTableIds

object

FullNatTableId

array

FULLNAT 清單。

string

FULLNAT 清單。

fulltb-gw88z7hhlv43rmb26****

樣本

正常返回樣本

JSON格式

{
  "NatGatewayId": "ngw-112za33e4****",
  "RequestId": "2315DEB7-5E92-423A-91F7-4C1EC9AD97C3",
  "ForwardTableIds": {
    "ForwardTableId": [
      "ftb-11tc6xgmv****"
    ]
  },
  "SnatTableIds": {
    "SnatTableId": [
      "stb-SnatTableIds****"
    ]
  },
  "FullNatTableIds": {
    "FullNatTableId": [
      "fulltb-gw88z7hhlv43rmb26****"
    ]
  }
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 Forbidden.NatPayBySpec Pay-by-specification NAT is no longer supported. Newly purchased pay-as-you-go NAT gateways only support the pay-by-CU metering method. 按規格計費的 NAT 閘道器已經不再進行販售,請選擇按 CU 使用量計費的 NAT 閘道器。
400 DependencyViolation.FullNatEntry The specified resource of %s depends on %s, so the operation cannot be completed.
400 UnsupportedFeature.InternetChargeType The feature of InternetChargeType is not supported.
400 InvalidVPCStatus vpc incorrect status.
400 InvalidNatGatewayName.MalFormed NatGateway name is not valid.
400 InvalidNatGatewayDescription.MalFormed NatGateway description is not valid.
400 MissingParameter.BandwidthPackage only support one BandwidthPackage be created with NatGateway.
400 OperationDenied The user cannot allow to create natgw, please call PD to authorize
400 RouterEntryConflict.Duplicated A route entry already exists, which CIDR is '0.0.0.0/0'
400 MissingParameter Miss mandatory parameter.
400 QuotaExceeded.BandwidthPackageIps The specified ipCount exceeded quota. IP 數量超過上限,可以在配額管理頁面申請增加配額。
400 AllocateIpFailed Alloc bandwidthPackage ips failed, maybe no available ip.
400 InvalidParameter.Name.Malformed The specified Name is not valid.
400 InvalidParameter.Description.Malformed The specified Description is not valid.
400 ZONE_NO_AVAILABLE_IP The Zone have no available ip.
400 ParameterIllegal ipCount,bandwidth parameter invalid
400 InvalidParameter.BandwidthPackage.n.ISP.ValueNotSupport The specified ISP of BandwidthPackage is not valid.
400 InvalidNatGatewayId.NotFound The NatGatewayId not exist.
400 VpcStatusError The Vpc is creating .
400 InvalidParameter.Spec.ValueNotSupported The specified Spec is not valid.
400 TaskConflict The operation is too frequent, TaskConflict. EIP操作太頻繁。
400 COMMODITY.INVALID_COMPONENT The instance component is invalid. 指定的執行個體元件無效,請您檢查該執行個體元件是否正確。
400 CreateNatGateway.RouteConflict.DynamicRoute Route conflict exists in routing table.
400 OperationUnsupported.MultiNatGateway More than one natGateway per vpc is unsupported.
400 Forbidden.CheckEntryRuleQuota Route entry quota rule check error.
400 OperationFailed.UnpaidBillsExist The account has unpaid bills. Please pay your overdue bill first. 此帳戶有未付款的訂單。
400 IncorrectStatus.RouteEntry Specified routeEntry status error.
400 OperationFailed.RiskControl Risk control check failed. 我們偵測到您的付款方式存在安全風險。請透過電子郵件或主控台訊息中的連結繼續驗證,並在驗證後重新提交訂單。
400 OperationFailed.TokenVerfiy Token verify failed.
400 IllegalParam.Name The specified Name is invalid, shorter than 2 characters.
400 OperationFailed.EnhancedQuotaExceed Enhanced nat gateway per vpc quota is exceeded 操作失敗,因為目前 VPC 下的增強型 NAT 閘道器數量超過限制。
400 NoPermission.CreateServiceLinkedRole You are not authorized to create service linked role
400 OperationFailed.EnhancedInventoryNotEnough Operation failed because inventory is not enough.
400 OperationFailed.VswNotBelongToVpc Operation failed because the specified VSwitch is not bound to the same VPC with NAT gateway. 操作失敗,因為交換器和 NAT 閘道器不屬於同一個 VPC。
400 OperationFailed.EnhancedUserIsUnAuthorized Operation failed because the user is not authorized to create an enhanced NAT gateway. 操作失敗,因為使用者未授權建立增強型 NAT 閘道器。
400 OperationUnsupported.PrePaidPyByLcu The operation failed because the subscription NAT gateway does not support the pay-by-LCU billing method. 預付費的NAT閘道器執行個體不支援PayByLcu的計費方式。
400 OperationFailed.NormalInventoryNotEnough Standard NAT gateways are no longer offered. You can create enhanced NAT gateways and set the correct natType.
400 OperationFailed.VSwitchNoAvailableIp Operation failed because the specified vswitch does not have availabe ip.
400 UnsupportedFeature.IcmpReplyEnabled The feature of IcmpReplyEnabled is not supported. ICMP 代答啟用功能修改不支援。
400 UnsupportedFeature.SecurityProtectionEnabled The feature of SecurityProtectionEnabled is not supported.
400 OperationFailed.RegionConvert Operation failed because do not find region info.
400 UnsupportedFeature.VpcNat The feature of VpcNat is not supported.
400 InvalidVSWITCHID.NotFound The specified resource of %s is not found.
400 Forbidden.OperateShareResource Operate share resource is forbidden.
400 IncorrectStatus.VSWITCH The status of VSWITCH is incorrect. 虛擬交換器狀態異常。
400 OperationFailed.VpcNatGatewayInventoryNotEnough The operation is failed because of inventory is not enough.
400 OperationFailed.VpcNatGatewayCheckInventory The operation is failed because of check inventory result is unexpected
400 ExclusiveParam.%sAnd%s The param of %s and %s are mutually exclusive. 參數 %s 和 %s 相互排斥。
400 SecurityGroupType.NotSupported The specified security group type is not supported. 安全性群組已經被託管,無法使用。
400 SecurityGroup.NotExist The specified security group is not exist. 安全性群組不存在於此 VPC。
400 OperationFailed.ContainForbiddenLabel There is a label that prohibits ordering, please contact your distributor for processing. 存在禁止下單的標籤,請聯絡您的經銷商處理。
400 OperationDenied.PrePaidInstance The operation is not allowed because prepaid instance is no longer supported. 預付執行個體不再支援購買。
400 UnsupportedFeature.Geneve The feature of Geneve is not supported. 目前不支援建立 Geneve 模式的 NAT 閘道器。
400 OperationFailed.NoAvailableResource The Zone have no available resource. 區域沒有可用資源。
400 ExclusiveParam.AccessModeValueAndAccessTunnelType The specified param AccessModeValue and AccessTunnelType are mutually exclusive. 指定的輸入參數AccessMode.ModeValue和AccessMode.TunnelType存在衝突。
400 ExclusiveParam.PrivateLinkModeAndAccessMode The specified param PrivateLinkMode and AccessMode are mutually exclusive. 指定的輸入參數PrivateLinkMode和AccessMode存在衝突。
400 ExclusiveParam.PrivateLinkEnabledAndAccessMode The specified paramPrivateLinkEnabled and AccessMode are mutually exclusive. 指定的輸入參數PrivateLinkEnabled和AccessMode存在衝突。
400 UnsupportedFeature.AccessModeValue The feature of AccessMode.ModeValue(%s) is not supported. VPC NAT的AccessMode.ModeValue屬性不支援此操作。
400 IllegalParam.AccessTunnelType The request parameter AccessMode.TunnelType is illegal. 請求參數中AccessMode.TunnelType參數不合法。
400 IllegalParam.AccessModeValue The request parameter AccessMode.ModeValue is illegal. 請求參數中AccessMode.ModeValue參數不合法。
400 OperationFailed.VSwitchStatusError The vSwitch is creating . 交換器正在建立中。
400 UnsupportedFeature.PrivateLinkMode The feature of %s is not supported. 暫不支援反向存取特性。
400 OperationFailed.EcsNetworkInterfaceQuotaNotSatisfy ECS network interface quota is not satisfy. ECS彈性網卡配額不符合要求。
400 OperationFailed.NoNameAuthentication You have not passed the real name authentication and do not meet the purchase conditions. Please log in to the user center for real-name authentication. 您尚未通過實名認證,不符合購買條件。請登入使用者中心進行實名認證。
400 Mismatch.NatIpAndNatIpCidr The %s and %s are mismatched. %s 和 %s 不匹配。
400 Mismatch.Ipv4PrefixAndNatIpCidr The %s and %s are mismatched. The Ipv4Prefix and NatIpCidr are mismatched.
400 ResourceAlreadyExist.NatIp The specified resource of NatIp has already exist. 設定的NatIp已存在。
400 Mismatch.Ipv4PrefixAndCidrReservations The %s and %s are mismatched. Ipv4Prefix和交換器預留網段不匹配。
400 ResourceAlreadyAssociated.Ipv4Prefix %s is already associated. Ipv4Prefix已經被分配。
400 ResourceNotEnough.Ipv4Prefix The resource of %s is not enough. Ipv4Prefix資源不足。
400 ResourceNotFound.Ipv4Prefix The resource of s% is not found.
400 ResourceAlreadyAssociated.NatIp The resource of %s was already associated. NatIp資源已經被分配。
400 ResourceNotEnough.NatIp The specified resource of NatIp is not enough. Insufficient IP addresses in the specified CIDR block.
400 ResourceNotFound.NatIp The specified resource of %s is not found. NatIp資源找不到。
400 IllegalParam.Ipv4Prefix The param of %s is illegal, must be /28 network segment. 參數Ipv4Prefix不合法。
400 IllegalParam.NatIp The param of %s is illegal. 參數NatIp不合法。
400 OperationUnsupported.EnhancedRegion Region not support. 目前地域不支援增強型 NAT 閘道器。
400 IncorrectStatus.RouteTableStatus The route table status is invaild. Please try again later. 指定的路由表未處於穩定狀態。
400 OperationUnsupported.User The current user does not support this operation. 目前使用者不支援此操作。
400 OperationUnsupported.EnhancedCURegion Operation failed because of this region not unsupported. 目前地域不支援 CU 計費的增強型 NAT 閘道器。
400 OrderError.NoAvailablePaymentMethod Order payment parameter is not available. 訂單錯誤,付費類型參數不可用。
400 OrderError.BasicInfoUncompleted Order basic parameter is not completed. 訂單錯誤,基礎參數資訊未完成。
400 OperationUnsupported.Region Operation unsupport this region parameter. 此操作不支援地域參數。
400 InvalidParameter.SingleZone Operation failed because current user not support create single zone nat. 目前使用者不允許建立單一可用區 NAT。
500 OrderError.NatGateway The Account failed to create order.
500 OperationFailed.AccessTunnelId AccessTunnelId param do operation failed. VPC NAT產生隧道ID失敗,請稍後重試。
500 OperationFailed.EnhancedCheckInventory The NAT gateway in the current zone is not in service, or the resource inventory is insufficient. 目前可用區NAT閘道器未開服,或底層資源庫存不足。
404 InvalidRegionId.NotFound The specified RegionId does not exist in our records.
404 InvalidVpcId.NotFound Specified value of VpcId is not found in our record. 該VPC不存在,請您檢查輸入的VPC是否正確。
404 InvalidZoneId.NotFound Specified value of ZoneId is not exists.
404 VPC_ONLY_CAN_CREATE_ONE_NAT_GATEWAY NatGateway in one vpc support only one.
404 OperationFailed.CrateEntryTimeOut Operation failed because create custom routeEntry timeout.
404 Forbidden.CreateSpecialSpecNatGateway You are not authorized to create special spec nat gateway.
404 UnsupportedZoneForFwNat The zone is unsupported for FW NAT. 該可用區不支援防護型 NAT 閘道器。

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

變更歷史

更多資訊,參考變更詳情。