All Products
Search
Document Center

NAT Gateway:CreateForwardEntry

Last Updated:Oct 26, 2026

Creates a DNAT entry in a DNAT table.

Operation description

Each DNAT entry consists of five components: ExternalIp, ExternalPort, IpProtocol, InternalIp, and InternalPort. After you add a DNAT entry, the NAT gateway forwards packets of the specified protocol received on ExternalIp:ExternalPort to InternalIp:InternalPort, and routes the response packets back to the original source.

When you call this operation to add a DNAT entry, take note of the following items:

  • CreateForwardEntry is an asynchronous operation. The system returns a DNAT entry ID, but the DNAT entry is not yet added. The system is still adding the entry in the background. You can call DescribeForwardTableEntries to query the status of the DNAT entry:

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

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

  • The combination of the ExternalIp, ExternalPort, and IpProtocol fields in all DNAT entries must be unique. You cannot forward messages of the same protocol from the same source IP address and port to multiple destination ECS instances.

  • The combination of the InternalIp, InternalPort, and IpProtocol fields in all DNAT entries must also be unique.

  • The IP addresses specified by the ExternalIp and InternalIp fields in a DNAT entry cannot be the same. If your business requires the two IP addresses to be the same, contact your account manager.

  • You can add up to 100 DNAT entries to a DNAT table.

  • An IP address for which IP mapping is configured in a DNAT entry (an EIP used by an Internet NAT gateway or a NAT IP address used by a VPC NAT gateway) cannot be used by other DNAT or SNAT entries.

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:CreateForwardEntry

create

*ForwardTable

acs:vpc:{#regionId}:{#accountId}:forwardtable/{#ForwardTableId}

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID of the NAT gateway.

You can call DescribeRegions to query region IDs.

cn-hangzhou

ForwardTableId

string

Yes

The ID of the DNAT table.

ftb-bp1mbjubq34hlcqpa****

ExternalIp

string

Yes

  • When you configure a DNAT entry for an Internet NAT gateway, specify an elastic IP address (EIP) that is used to provide public network access.

  • When you configure a DNAT entry for a VPC NAT gateway, specify a NAT IP address that is used to provide access from external networks.

116.28.XX.XX

ExternalPort

string

Yes

  • When you configure a DNAT entry for an Internet NAT gateway, specify the external port or port range for port forwarding.

    • The port range must be from 1 to 65535.

    • To forward traffic within a port range, separate the start port and end port with a forward slash (/). Example: 10/20.

    • If ExternalPort is set to a port range, InternalPort must also be set to a port range with the same number of ports. For example, if ExternalPort is set to 10/20, InternalPort must be set to 80/90.

  • When you configure a DNAT entry for a VPC NAT gateway, specify the port on the NAT IP address that is accessed by external networks. Valid values: 1 to 65535.

8080

InternalIp

string

Yes

  • When you configure a DNAT entry for an Internet NAT gateway, specify the private IP address of the ECS instance that needs to communicate over the Internet. The private IP address must meet the following requirements:

    • It must belong to the CIDR block of the VPC where the NAT gateway is deployed.

    • It must be used by an ECS instance, and the ECS instance must not be associated with an EIP. Otherwise, the DNAT entry does not take effect.

  • When you configure a DNAT entry for a VPC NAT gateway, specify the private IP address that needs to communicate by using the DNAT rule.

192.168.XX.XX

InternalPort

string

Yes

  • When you configure a DNAT entry for an Internet NAT gateway, specify the internal port or port range for port forwarding. Valid values: 1 to 65535.

  • When you configure a DNAT entry for a VPC NAT gateway, specify the destination port of the ECS instance to be mapped. Valid values: 1 to 65535.

80

IpProtocol

string

Yes

The protocol type. Valid values:

  • TCP: forwards TCP packets.

  • UDP: forwards UDP packets.

  • Any: forwards packets of all protocols. If IpProtocol is set to Any, ExternalPort and InternalPort must also be set to Any to implement DNAT IP mapping.

TCP

ForwardEntryName

string

No

The name of the DNAT rule.

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://.

ForwardEntry-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 ensure that it is unique among different requests. The client token 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.

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

PortBreak

boolean

No

Specifies whether to enable port breaking. Valid values:

  • true: enables port breaking.

  • false (default): disables port breaking.

Note

If a DNAT entry and an SNAT entry use the same public IP address and you need to configure a port number greater than 1024, you must set PortBreak to true.

false

DryRun

boolean

No

Specifies whether to perform a dry run for this request. Valid values:

  • true: performs a dry run without creating the DNAT 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 dry run, a 2xx HTTP status code is returned and the DNAT entry is created.

false

Response elements

Element

Type

Description

Example

object

ForwardEntryId

string

The ID of the DNAT entry.

fwd-119smw5tkasdf****

RequestId

string

The request ID.

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

Examples

Success response

JSON format

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

Error codes

HTTP status code

Error code

Error message

Description

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. You cannot specify %s and %s at the same time.
400 DuplicatedParam.InternalPort The param of %s is duplicated. Duplicate or occupied InternalPort parameter
400 DuplicatedParam.ExternalPort The param of %s is duplicated. The DNAT public network port has been used repeatedly.
400 OperationFailed.AnyPortConfig Operation failed because any port correspondence any protocol The operation failed. There is a conflict with another entry, any port or any protocol type.
400 OperationUnsupported.ForwardEntry Duplicated destination ip port is unsupported. You cannot specify duplicate destination IP addresses or destination ports.
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. The status of NatIp is incorrect.
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. The DNAT entry to be deleted is in an invalid state.
400 Duplicated.DestinationPort The specified param DestinationPort is duplicated.
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 QuotaExceeded.ForwardEntrySessionManytoOne The dnat session quota is exceed. The number of DNAT sessions exceeds the upper limit.
400 TaskConflict The operation is too frequent, please wait a moment and try again. Your requests are too frequent. Try again later.
400 OperationFailed.DnatPortRangeLimit The maximum number of port ranges that can be specified is exceeded. The maximum number of port ranges that can be specified is exceeded.
400 IncorrectStatus.NATGW NATGW status is invalid. The NAT gateway is in an invalid state.
400 OperationFailed.ForwardEntryNotAllowSrcIpEqualDstIp The source IP of forward entry is not allowed to equal destination IP. The public IP address of the DNAT entry is not allowed to be equal to the private IP address.
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

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.