全部產品
Search
文件中心

NAT Gateway:CreateNatGateway - 建立NAT Gateway

更新時間:Apr 30, 2026

調用CreateNatGateway介面建立增強型公網NAT Gateway或VPC NAT Gateway。

介面說明

在調用本介面時,請瞭解以下內容:

  • 首次建立 NAT Gateway時,系統會自動建立一個名稱為 AliyunServiceRoleForNatgw 的服務關聯角色,並且為該角色添加名稱為 AliyunServiceRolePolicyForNatgw 的權限原則,授予 NAT Gateway擁有訪問其他雲資源的許可權。更多資訊,請參見服務關聯角色

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

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

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

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

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

調試

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

調試

授權資訊

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

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

NAT Gateway所在的地區 ID。

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

cn-hangzhou

VpcId

string

需要建立 NAT Gateway的 VPC 的 ID。

vpc-bp1di7uewzmtvfuq8****

Name

string

NAT Gateway的名稱。

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

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

fortest

Description

string

NAT Gateway的描述。

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

testnat

ClientToken

string

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

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

說明

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

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

Spec

string

訂用帳戶公網 NAT Gateway已停止新購,該參數不再使用。

無效參數

InstanceChargeType

string

NAT Gateway的付費模式,取值:

PostPaid(預設值):隨用隨付。

更多資訊,請參見公網 NAT Gateway計費VPC NAT Gateway計費

PostPaid

PricingCycle

string

訂用帳戶公網 NAT Gateway已停止新購,該參數不再使用。

無效參數

Duration

string

訂用帳戶公網 NAT Gateway已停止新購,該參數不再使用。

無效參數

AutoPay

boolean

訂用帳戶公網 NAT Gateway已停止新購,該參數不再使用。

無效參數

VSwitchId

string

NAT Gateway所屬的交換器的 ID。

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

  • 如果您要在存量交換器中建立 NAT Gateway,請確保交換器所屬的可用性區域支援建立 NAT Gateway,且交換器有可用的 IP。

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

說明

您可以通過 ListEnhanhcedNatGatewayAvailableZones 介面查詢 NAT Gateway的資源可用性區域,通過 DescribeVSwitches 介面查詢交換器中的可用 IP 數。

vsw-bp1e3se98n9fq8hle****

NatType

string

NAT Gateway的類型,取值:Enhanced,增強型 NAT Gateway。

Enhanced

InternetChargeType

string

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

PayByLcu

NetworkType

string

建立的 NAT Gateway類型,取值:

  • internet:公網 NAT Gateway。

  • intranet:VPC NAT Gateway。

internet

SecurityProtectionEnabled deprecated

boolean

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

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

false

IcmpReplyEnabled

boolean

是否開啟 ICMP 代回。取值:

  • true(預設值):開啟。

  • false:不開啟。

true

PrivateLinkEnabled

boolean

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

  • true:開啟私網串連。

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

false

EipBindMode

string

NAT Gateway的 EIP 繫結模式,取值:

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

  • NAT:EIP 普通模式,相容 IPv4 網關。
    說明

    NAT Gateway的 EIP 繫結模式為 EIP 普通模式時,EIP 將佔用 NAT Gateway所在交換器的一個私網 IP,請確保 NAT Gateway所在交換器內私網 IP 位址充足,如果 NAT Gateway所在的交換器沒有可用的空閑私網地址時,將無法綁定新的 EIP。NAT Gateway的 EIP 繫結模式為 EIP 普通模式時,NAT Gateway支援綁定的 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 Gateway的訪問模式。

MULTI_BINDED

ModeValue

string

訪問模式取值:

  • route:路由模式。

  • tunnel:隧道模式。

說明

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

route

TunnelType

string

隧道模式類型:

  • geneve: Geneve 類型。

說明

當訪問模式為隧道模式時此值有效。

geneve

NatIp

string

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

192.168.0.2

Ipv4Prefix

string

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

192.168.0.0/28

AvailabilityMode

string

返回參數

名稱

類型

描述

樣本值

object

返回資料結構體。

NatGatewayId

string

建立的 NAT Gateway的執行個體 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 Gateway已經不再進行售賣,請選擇按CU使用量計費的NAT Gateway
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. 操作太頻繁,請稍後重試
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 Gateway不屬於同一個VPC。
400 OperationFailed.EnhancedUserIsUnAuthorized Operation failed because the user is not authorized to create an enhanced NAT gateway. 操作失敗因為使用者未授權建立增強型NAT Gateway。
400 OperationUnsupported.PrePaidPyByLcu The operation failed because the subscription NAT gateway does not support the pay-by-LCU billing method. 預付費的NAT Gateway執行個體不支援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 Gateway。
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.
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. 資源Ipv4Prefix不存在。
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不合法,必須為/28網段
400 IllegalParam.NatIp The param of %s is illegal. 參數NatIp不合法。
400 OperationUnsupported.EnhancedRegion Region not support. 當前地區暫時不支援
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. 因不支援隨用隨付地區引起操作失敗
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. 目前使用者不允許建立單az 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 Gateway未開服, 或底層資產庫存不足。
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 Gateway。

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

變更歷史

更多資訊,參考變更詳情