All Products
Search
Document Center

NAT Gateway:CreateSnatEntry

Last Updated:Oct 16, 2026

Creates an SNAT entry in an SNAT table.

Operation description

This operation adds an SNAT entry to an enhanced Internet NAT gateway or a VPC NAT gateway. The term NAT gateway in this document refers to both types of NAT gateways.

Note the following when you call this operation to add an SNAT entry:

  • CreateSnatEntry is an asynchronous operation. After you make a request, the system returns an SNAT entry ID, but the SNAT entry is not immediately added. The system continues to process the request in the background. You can call DescribeSnatTableEntries to query the status of the SNAT entry:

    • If the SNAT entry is in the Pending state, the SNAT entry is being added. In this state, you can only perform query operations.

    • If the SNAT entry is in the Available state, the SNAT entry is added.

  • The vSwitch and ECS instance specified in the SNAT entry must belong to the VPC to which the NAT gateway belongs.

  • Each vSwitch and ECS instance can belong to only one SNAT entry.

  • If a high-availability virtual IP address (HaVip) exists in the vSwitch, you cannot add an SNAT entry.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

vpc:CreateSnatEntry

create

*SnatEntry

acs:vpc:{#regionId}:{#accountId}:snattable/*

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID of the NAT gateway.

You can call the DescribeRegions operation to query region IDs.

Valid values:

  • ap-northeast-2-pop :

    ap-northeast-2-pop

cn-hangzhou

SnatTableId

string

Yes

The ID of the SNAT table.

stb-bp190wu8io1vgev****

SourceVSwitchId

string

No

The ID of the vSwitch.

  • When you add an SNAT entry to an Internet NAT gateway, this parameter specifies that all ECS instances in the vSwitch can access the Internet through the SNAT rule. If you specify multiple EIPs to configure an SNAT IPAM pool, service connections are allocated to the EIPs through a hash algorithm. Because service traffic of each connection varies, service traffic of the EIPs may be uneven. To prevent service interruptions caused by the bandwidth limit of a single EIP, add all EIPs to the same Internet Shared Bandwidth.

  • When you add an SNAT entry to a VPC NAT gateway, this parameter specifies that all ECS instances in the vSwitch can access external networks through the SNAT rule.

Note

You must specify either the SourceCIDR parameter or the SourceVSwitchId parameter.

vsw-bp1nhx2s9ui5o****

SourceCIDR

string

No

The CIDR block of the VPC, vSwitch, or ECS instance. You can also specify any CIDR block.

SNAT entries support the following granularities:

  • VPC granularity: the CIDR block of the VPC to which the NAT gateway belongs. All ECS instances in the VPC can access the Internet or external networks through the SNAT rule.

  • flow log for a vSwitch: the CIDR block of a specified vSwitch, such as 192.168.1.0/24. All ECS instances in the vSwitch can access the Internet or external networks through the SNAT rule.

  • ECS instance granularity: the IP address of a specified ECS instance, such as 192.168.1.1/32. The ECS instance can access the Internet or external networks through the SNAT rule.

  • Custom CIDR block: any specified CIDR block. All ECS instances whose IP addresses fall within the CIDR block can access the Internet or external networks through the SNAT service.

Note

You must specify either the SourceCIDR parameter or the SourceVSwitchId parameter.

10.1.1.0/24

SnatIp

string

No

When you add an SNAT entry to an Internet NAT gateway:

  • The SnatIp parameter is required.

  • This parameter specifies the EIPs in the SNAT entry. Separate multiple EIPs with commas (,).

  • If SnatIp specifies only one public IP address, the ECS instance uses the specified public IP address to access the Internet.

  • If SnatIp specifies multiple public IP addresses, the ECS instance randomly uses one of the public IP addresses in SnatIp to access the Internet.

Note

If you specify multiple EIPs to configure an SNAT IPAM pool, service connections are allocated to the EIPs through a hash algorithm. Because service traffic of each connection varies, service traffic of the EIPs may be uneven. To prevent service interruptions caused by the bandwidth limit of a single EIP, add all EIPs to the same Internet Shared Bandwidth.

When you add an SNAT entry to a VPC NAT gateway:

  • This parameter specifies the NAT IP addresses in the SNAT entry. Separate multiple NAT IP addresses with commas (,).

  • You must specify either SnatIp or NetworkInterfaceId.

47.98.XX.XX

SnatEntryName

string

No

The name of the SNAT entry.

The name must be 2 to 128 characters in length, and must start with a letter or Chinese character. It cannot start with http:// or https://.

SnatEntry-1

ClientToken

string

No

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the value, but you must make sure that the value is unique among different requests. The ClientToken parameter can contain only ASCII characters.

Note

If you do not specify this parameter, the system automatically uses the RequestId of the API request as the ClientToken. The RequestId of each API request may be different.

02fb3da4-130e-11e9-8e44****

EipAffinity

integer

No

Specifies whether to enable EIP affinity. Valid values:

  • 0 (default): disables EIP affinity.

  • 1: enables EIP affinity.

Note

After EIP affinity is enabled, if the SNAT entry is associated with multiple EIPs or NAT IP addresses, the same EIP or NAT IP address is used when the same client accesses the same destination IP address. Otherwise, the client randomly selects an EIP or NAT IP address from the associated EIPs or NAT IP addresses.

1

NetworkInterfaceId

string

No

The ID of the elastic network interface controller (NIC).

Note

The IPv4 addresses of the elastic network interface controller (NIC) are used as the SNAT addresses.

eni-gw8g131ef2dnbu3k****

DryRun

boolean

No

Specifies whether to only perform a dry run on the request. Valid values:

  • true: performs a dry run on the request without creating the SNAT entry. The system checks whether your AccessKey pair is valid, the authorization of the Resource Access Management (RAM) user, and whether the required parameters are specified. If the request fails the dry run, an error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.

  • false (default): sends a normal request. If the request passes the precheck, a 2xx HTTP status code is returned and the SNAT entry is created.

false

Response elements

Element

Type

Description

Example

object

The SNAT entry ID.

SnatEntryId

string

The ID of the SNAT entry.

snat-kmd6nv8fy****

RequestId

string

The ID of the request.

2315DEB7-5E92-423A-91F7-4C1EC9AD****

Examples

Success response

JSON format

{
  "SnatEntryId": "snat-kmd6nv8fy****",
  "RequestId": "2315DEB7-5E92-423A-91F7-4C1EC9AD****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 UnsupportedFeature.PrivateLinkEnabled The feature of PrivateLinkEnabled is not supported.
400 InvalidSourceCIDR.Malformed SourceCIDR is illegal.
400 NOT_ALLOW_USE_SOURCECIDR_OUTSIDEVPC The User not in sourcecidr_unlimited_outsidevpc white list. Cannot use SourceCidr outside VpcCidr.
400 NOT_ALLOW_USE_SOURCECIDR_AUTODEFINE The User not in sourcecidr_unlimited_insidevpc white list. Cannot use SourceCidr auto defined.
400 NOT_ALLOW_USE_SOURCECIDR_CONTAINSZERO The User not in sourcecidr_unlimited_outsidevpc_containszero white list. Cannot use SourceCidr outside VpcCidr.
400 Forbidden.IpHasBeenUsedInDnat The snat ip can't be used. Because it has been used in dnat
400 Forbidden.SourceVSwitchId.IncludeHaVip There is some HaVips under specified VSwitch The specified vSwitch is associated with HAVIPs.
400 InvalidSnatIp.Malformed The specified SnatIp is not a valid IP address.
400 SNAT_IP_POOL_COUNT_TOO_MANY The Snat pool ip too many.
400 Forbidden.SnatEntryCountLimited SNAT entry in the specified SNAT table reach its limit. The number of SNAT entries has reached the upper limit.
400 NOT_ALLOW_USE_SOURCECIDR The User not in nat_scope_unlimited white list. Cannot use SourceCidr param.
400 INVALID_PARAMETER The parameter invalid.
400 Forbidden.SourceVSwitchId.Duplicated The specified SourceCIDRis duplicated.
400 Forbidden.IpUsedInForwardTable The specified SnatIp already used in forward table
400 Forbindden The specified Instance already bind eip
400 EIP_NOT_SUPPORT_SNAT_POOL The Eip cannot support snat pool
400 EIP_NOT_IN_GATEWAY The Eip not in nat gateway
400 OperationUnsupported.CidrConflict The specified CIDR block conflicts with an existing SNAT entry. The specified CIDR block conflicts with those in existing SNAT entries.
400 InvalidNatGatewayId.NotFound The NatGateway instance not exist.
400 InvalidParameter.Name.Malformed The specified Name is not valid.
400 InvalidParameter.SnatIp Ip semgment must be subnet cidr.
400 QuotaExceeded.SnatIp Public ip number exceeds quota.
400 OperationUnsupported.EipInBinding Create snat entry with eip in associating status is unsupported. You cannot use an associated EIP when you create an SNAT entry.
400 OperationFailed.VSwitchNotInVpc The specified vswitch and natgateway are not in the same vpc.
400 QuotaExceeded.SnatEntry SNAT entry in the specified SNAT table reach it?s limit.
400 IncorrectStatus.NATGW NATGW status is invalid. The NAT gateway is in an invalid state.
400 IncorrectStatus.VSwitch The specified vSwitch status is invalid. The virtual switch status is abnormal.
400 MissingParam.SnatIp The input parameter SnatIp that is mandatory for processing this request is not supplied. You need to specify the SnatIp parameter when creating a Snat rule for public network NAT or private network NAT.
400 MissingParam.NetworkInterfaceId The input parameter NetworkInterfaceId that is mandatory for processing this request is not supplied. You need to specify NetworkInterfaceId parameters when creating a Snat rule for NAT with the private network link service enabled.
400 ParamExclusive.SnatIpAndNetworkInterfaceId SnatIp and NetworkInterfaceId is mutually exclusive when create a snat entry for nat. When you create an SNAT rule for a NAT Gateway instance, you cannot specify the SnatIp parameter and the NetworkInterfaceId parameter at the same time.
400 IllegalParam.NetworkInterfaceId The param of NetworkInterfaceId is illegal. Invalid NetworkInterfaceId value.
400 OperationUnsupported.EipNatBWPCheck The EIP is not associated with a NAT service plan. The EIP is not associated with a NAT service plan.
400 OperationUnsupported.EipNatGWCheck The operation failed because the EIP is not bound to this NAT Gateway. The operation failed because the EIP is not bound to this NAT Gateway.
400 OperationFailed.SnatIpPoolCbwpRules The operation failed because the SNAT rule IPs are added to multi bandwidth packages. The operation failed because the SNAT rule IP address pool was added to multiple bandwidth packages.
400 IncorrectStatus.SnatEntry The SNAT rule status is invalid. Please try again later. The SNAT rule is in the intermediate state, or the status is abnormal. Please try again later.
400 IncorrectStatus.NatIp NatIp status is invalid, please try again later. NatIp is in intermediate state, please try again later.
400 OperationUnsupported.EipNatIpCheck The operation failed because the EIP is not bound to this NAT gateway. The operation failed because the EIP is not bound to this NAT gateway.
400 OperationFailed.SnatIpPoolBwpRules The operation failed because the IP in Snat entryl was added to multiple NAT bandwidth packets. The operation failed because the IP in the SNAT rule IP address pool was added to multiple NAT bandwidth packets.
400 OperationFailed.SnatIpsCheck The operation fails because some IPs address in the SNAT entry are not added to common bandwidth packet. The operation fails because the IP address in the Snat rule IP address pool is not added to the shared bandwidth packet.
500 DefaultValidate.Error validte fail.
500 OperationFailed.CrateSnatEntryTimeOut Operation failed because create snatEntry timeout.
404 InvalidRegionId.NotFound The specified RegionId does not exist in our records.
404 InvalidSnatTableId.NotFound Specified SNAT table does not exist.
404 InvalidVSwitchId.NotFound The specified virtual switch does not exists.
404 InvalidSnatIp.NotFound Specified SnatIp does not found on the NAT Gateway
404 ResourceNotFound.NatGateway The NatGateway instance not exist. The NAT gateway does not exist.
404 ResourceNotFound.NatIp The NatIp instance not exist.
404 ResourceNotFound.VSwitch The specified resource of %s is not found. The specified vSwitch does not exist, please check your input is correct

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.