NAT

VPC VPC

  • API Reference
    • ACL-Related Interfaces
      • Add ACL rule
      • Delete ACL rules
      • Query ACL rules
      • Query ACL
      • Update ACL rules
    • API function release records
    • API Overview
    • Appendix
    • Common Headers and Error Responses
    • Dedicated Gateway-Related Interfaces
      • Bind physical dedicated line
      • Create dedicated gateway
      • Create health check for dedicated gateway
      • Query dedicated gateway details
      • Query dedicated gateway list
      • Release dedicated gateway
      • Unbind physical dedicated line
      • Update dedicated gateway
    • Elastic Network Interface-Related Interfaces
      • Add intranet IP to elastic network interface in batches
      • Add Secondary IP Address of Elastic Network Interface
      • Create elastic network interface
      • Delete elastic network interface
      • Delete Intranet IP from elastic network interface in batches
      • Delete Secondary IP Address of Elastic Network Interface
      • Elastic network interface binds to EIP
      • Elastic Network Interface Mounts Cloud Product Instance
      • Elastic network interface unbinds from EIP
      • Elastic Network Interface Unmounts Cloud Product Instance
      • Query elastic network interface list
      • Query elastic network interface status
      • Query the specified elastic network interface
      • Update elastic network interface with enterprise security group
      • Update elastic network interface with regular security group
      • Update elastic network interface
    • Gateway Bandwidth Limiting Rule Related Interfaces
      • Create gateway bandwidth limiting rules
      • Delete Gateway Bandwidth Limiting Rule
      • Modify Gateway Bandwidth Limiting Rule
      • View Gateway Bandwidth Limiting Rule
    • General Description
    • High-Availability Virtual IP Address(HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
    • Interface Overview
    • IPv6 Gateway-Related Interfaces
      • Add IPv6 egress-only policy
      • Bandwidth resizing for IPv6 gateway
      • Create IPv6 gateway bandwidth limiting policy
      • Create IPv6 gateway
      • Delete IPv6 gateway bandwidth limiting policy
      • Delete IPv6 Gateway
      • Delete the IPv6 egress-only policy
      • Query IPv6 gateway bandwidth limiting policy list
      • Query IPv6 gateway
      • Query the IPv6 egress-only policy list
      • Update IPv6 gateway bandwidth limiting policy
      • Update the IPv6 gateway release protection switch
    • NAT Gateway-Related Interfaces
      • Bind DNAT EIP to the NAT gateway
      • Bind SNAT EIP to the NAT gateway
      • Create DNAT rules in batches
      • Create DNAT rules
      • Create NAT gateway
      • Create SNAT rules in batches
      • Create SNAT rules
      • Delete DNAT rules
      • Delete SNAT rules
      • NAT Gateway Binds EIP
      • NAT gateway renewal
      • NAT Gateway Resize
      • NAT Gateway Unbinds EIP
      • Query DNAT rules
      • Query NAT gateway details
      • Query NAT gateway list
      • Query SNAT rules
      • Release NAT gateway
      • Unbind DNAT EIP from the NAT gateway
      • Unbind SNAT EIP from the NAT gateway
      • Update DNAT rules
      • Update NAT Delete Protection Switch
      • Update NAT gateway name
      • Update SNAT rules
    • Network Detection Related Interfaces
      • Create Network Probe
      • Delete network probe
      • Query network probe details
      • Query network probe list.
      • Update probe
    • Parameter Template-Related Interfaces
      • Add IP addresses to the IP address family
      • Add IP addresses to the IP address group
      • Create IP address family
      • Create IP address set
      • Delete IP address family
      • Delete IP address from IP address group
      • Delete IP address set
      • Query IP address family list
      • Query IP address group list
      • Query specified IP address family
      • Query specified IP address group
      • Remove IP address group from IP address family
      • Update IP address family
      • Update IP address set
    • Peering Connections-Related Interfaces
      • Application to process the peering connection
      • Bandwidth resizing for peering connections
      • Create peering connections
      • Disable DNS synchronization for the peering connections.
      • Enable DNS synchronization for the peering connections
      • List of peering connections to be queried.
      • Peering connection renewal
      • Release peering connections
      • Update the local API name and remarks for peering connections
      • Update the peering connection release protection switch
      • View details of peering connection
    • Route Table Related Interfaces
      • Create route rules
      • Delete route rules
      • Primary-standby switch
      • Query route table
      • Query routing rules
      • Update route rules
    • Security Group Related Interfaces
      • Enterprise security group
        • Authorize enterprise security group rules
        • Create enterprise security group
        • Delete enterprise security group rules
        • Delete enterprise security group
        • Query enterprise security group list
        • Update enterprise security group rules
      • Regular security group
        • Authorize regular security group rules
        • Create regular security group
        • Delete regular security group rules
        • Delete regular security group
        • Query regular security group list
        • Revoke regular security group rules
        • Update regular security group rules
        • View security group details
    • Service domain
    • Service Network Interface Card (SNIC)-Related Interfaces
      • Create service network interface card
      • Delete service network interface card
      • Query mountable public services
      • Query service network interface card details
      • Query service network interface card list
      • Update regular security group for service network interface card
      • Update service network interface card with enterprise security group
      • Update the service network interface card
    • Subnet-Related Interfaces
      • Create reserved network segment
      • Create subnet
      • Delete reserved network segment
      • Delete subnet
      • Query specified subnet
      • Query subnet list
      • Query the reserved network segment list
      • Update subnet
    • VPC-Related Interfaces
      • Create VPC
      • Delete VPC
      • Open VPC relay
      • Query IP Usage by Products in VPC
      • Query specified VPC
      • Query VPC intranet IP
      • Query VPC list
      • Shut down VPC relay
      • Update VPC
    • VPN-Related Interfaces
      • Bind EIP
      • Create SSL VPN server
      • Create SSL VPN users in batches
      • Create VPN tunnel
      • Create VPN
      • Delete SSL VPN server
      • Delete SSL VPN user
      • Delete VPN tunnel
      • Query SSL-VPN server
      • Query SSL-VPN user
      • Query VPN details
      • Query VPN List
      • Query VPN tunnels
      • Release VPN
      • Unbind EIP
      • Update SSL VPN server
      • Update SSL VPN user
      • Update VPN release protection switch
      • Update VPN tunnel
      • Update VPN
      • VPN gateway renewal
    • High-Availability Virtual IP Address (HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
  • FAQs
    • Common Questions Overview
    • NAT FAQs
    • Route Table FAQs
    • Service Network Interface Card(SNIC) Common Questions
    • VPC FAQs
    • VPN FAQs
    • Service Network Interface Card (SNIC) Common Questions
  • Function Release Records
  • Operation guide
    • Access control
      • ACL
      • Parameter Template
      • Security group
    • Identity and access management
    • Monitor and Operations
      • NAT Gateway Instance Diagnosis
    • Network Connection
      • Dedicated gateway
      • IPv6 gateway
      • Layer 2 Gateway
      • NAT Gateway
        • Private Network NAT(Network Address Translation) Gateway
        • Public Network NAT(Network Address Translation) Gateway
        • Private Network NAT (Network Address Translation) Gateway
        • Public Network NAT (Network Address Translation) Gateway
      • Peering Connections
      • VPN Gateway
        • GRE VPN Gateway
        • IPsec VPN Gateway
        • SSL VPN Gateway
    • Network Diagnostics
      • Flow log
      • Gateway bandwidth limiting
      • Network probe
      • Path analysis
      • Port verification
      • Traffic monitor
    • Network interface card
      • Elastic network interface
      • High-availability virtual IP address (HAVIP)
      • Service network interface card
    • Network topology
    • Route table
    • Subnet
    • Tag Management
    • Using IPv6
    • VPC
  • Product Description
    • Application scenarios
    • Product advantages
    • Product features
    • Product Introduction
    • Related concepts
    • Usage restrictions
  • Product pricing
  • SDK
    • Go-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Exception handling
      • High-availability virtual IP address (HAVIP)
      • Initialization
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
        • Enterprise security group
        • Regular security group
      • Service network interface card
      • Subnet
      • VPC
      • VPN
    • Java-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6 gateway
      • NAT
      • Network probe
      • Overview
      • Parameter Template
      • Peering Connections
      • Regular security group
      • Route
      • Service network interface card
      • Subnet
      • Version history
      • vpc
      • VPN
    • PHP-SDK
      • ACL
      • Install the SDK Package
      • NAT
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Subnet
      • Version history
      • vpc
    • Python-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Service network interface card
      • Subnet
      • Version history
      • VPC
      • VPN
  • Service Level Agreement (SLA)
    • IPv6 Gateway Service Level Agreement SLA
    • NAT(Network Address Translation) Gateway Service Level Agreement SLA
    • Peering Connections Service Level Agreement SLA
    • Service Network Interface Card(SNIC) Service Level Agreement SLA
    • VPN Gateway Service Level Agreement SLA
    • NAT (Network Address Translation) Gateway Service Level Agreement SLA
    • Service Network Interface Card (SNIC) Service Level Agreement SLA
  • Typical Practices
    • Configure Custom Service and Use Service Network Interface Card(SNIC) to Provide Service for Other VPCs
    • HAVIP Combined with Keepalived to Achieve Master-Backup Multi-Machine High Availability
    • Layer 2 Gateway Combined with Dedicated Line Access ET to Build Large Layer 2 Network Between IDC and Cloud VPC
    • Network Layer Security Description
    • Peering Connections Typical Practice
    • Security Group Configuration Practice (Advanced Level)
    • Security Group Configuration Practice (Beginner Level)
    • Typical Practice of Managing Elastic Network Interface Using Terraform
    • Typical Practice of Managing IPsec VPN Gateway Using Terraform
    • Using Keepalived in VPC to Achieve High-Availability Architecture
    • VPC Custom Route Table to Achieve Secure Traffic Mutual Access
    • Windows Using HAVIP to Configure Master-Backup Multi-Machine
    • Configure Custom Service and Use Service Network Interface Card (SNIC) to Provide Service for Other VPCs
  • VPC CLI
    • Configure BCE-CLI
    • Install BCE-CLI
    • Route Table Related Operations
    • Subnet Related Operations
    • Using VPC Service via CLI
    • Version Change Records
    • VPC Related Operations
All documents
menu
No results found, please re-enter

VPC VPC

  • API Reference
    • ACL-Related Interfaces
      • Add ACL rule
      • Delete ACL rules
      • Query ACL rules
      • Query ACL
      • Update ACL rules
    • API function release records
    • API Overview
    • Appendix
    • Common Headers and Error Responses
    • Dedicated Gateway-Related Interfaces
      • Bind physical dedicated line
      • Create dedicated gateway
      • Create health check for dedicated gateway
      • Query dedicated gateway details
      • Query dedicated gateway list
      • Release dedicated gateway
      • Unbind physical dedicated line
      • Update dedicated gateway
    • Elastic Network Interface-Related Interfaces
      • Add intranet IP to elastic network interface in batches
      • Add Secondary IP Address of Elastic Network Interface
      • Create elastic network interface
      • Delete elastic network interface
      • Delete Intranet IP from elastic network interface in batches
      • Delete Secondary IP Address of Elastic Network Interface
      • Elastic network interface binds to EIP
      • Elastic Network Interface Mounts Cloud Product Instance
      • Elastic network interface unbinds from EIP
      • Elastic Network Interface Unmounts Cloud Product Instance
      • Query elastic network interface list
      • Query elastic network interface status
      • Query the specified elastic network interface
      • Update elastic network interface with enterprise security group
      • Update elastic network interface with regular security group
      • Update elastic network interface
    • Gateway Bandwidth Limiting Rule Related Interfaces
      • Create gateway bandwidth limiting rules
      • Delete Gateway Bandwidth Limiting Rule
      • Modify Gateway Bandwidth Limiting Rule
      • View Gateway Bandwidth Limiting Rule
    • General Description
    • High-Availability Virtual IP Address(HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
    • Interface Overview
    • IPv6 Gateway-Related Interfaces
      • Add IPv6 egress-only policy
      • Bandwidth resizing for IPv6 gateway
      • Create IPv6 gateway bandwidth limiting policy
      • Create IPv6 gateway
      • Delete IPv6 gateway bandwidth limiting policy
      • Delete IPv6 Gateway
      • Delete the IPv6 egress-only policy
      • Query IPv6 gateway bandwidth limiting policy list
      • Query IPv6 gateway
      • Query the IPv6 egress-only policy list
      • Update IPv6 gateway bandwidth limiting policy
      • Update the IPv6 gateway release protection switch
    • NAT Gateway-Related Interfaces
      • Bind DNAT EIP to the NAT gateway
      • Bind SNAT EIP to the NAT gateway
      • Create DNAT rules in batches
      • Create DNAT rules
      • Create NAT gateway
      • Create SNAT rules in batches
      • Create SNAT rules
      • Delete DNAT rules
      • Delete SNAT rules
      • NAT Gateway Binds EIP
      • NAT gateway renewal
      • NAT Gateway Resize
      • NAT Gateway Unbinds EIP
      • Query DNAT rules
      • Query NAT gateway details
      • Query NAT gateway list
      • Query SNAT rules
      • Release NAT gateway
      • Unbind DNAT EIP from the NAT gateway
      • Unbind SNAT EIP from the NAT gateway
      • Update DNAT rules
      • Update NAT Delete Protection Switch
      • Update NAT gateway name
      • Update SNAT rules
    • Network Detection Related Interfaces
      • Create Network Probe
      • Delete network probe
      • Query network probe details
      • Query network probe list.
      • Update probe
    • Parameter Template-Related Interfaces
      • Add IP addresses to the IP address family
      • Add IP addresses to the IP address group
      • Create IP address family
      • Create IP address set
      • Delete IP address family
      • Delete IP address from IP address group
      • Delete IP address set
      • Query IP address family list
      • Query IP address group list
      • Query specified IP address family
      • Query specified IP address group
      • Remove IP address group from IP address family
      • Update IP address family
      • Update IP address set
    • Peering Connections-Related Interfaces
      • Application to process the peering connection
      • Bandwidth resizing for peering connections
      • Create peering connections
      • Disable DNS synchronization for the peering connections.
      • Enable DNS synchronization for the peering connections
      • List of peering connections to be queried.
      • Peering connection renewal
      • Release peering connections
      • Update the local API name and remarks for peering connections
      • Update the peering connection release protection switch
      • View details of peering connection
    • Route Table Related Interfaces
      • Create route rules
      • Delete route rules
      • Primary-standby switch
      • Query route table
      • Query routing rules
      • Update route rules
    • Security Group Related Interfaces
      • Enterprise security group
        • Authorize enterprise security group rules
        • Create enterprise security group
        • Delete enterprise security group rules
        • Delete enterprise security group
        • Query enterprise security group list
        • Update enterprise security group rules
      • Regular security group
        • Authorize regular security group rules
        • Create regular security group
        • Delete regular security group rules
        • Delete regular security group
        • Query regular security group list
        • Revoke regular security group rules
        • Update regular security group rules
        • View security group details
    • Service domain
    • Service Network Interface Card (SNIC)-Related Interfaces
      • Create service network interface card
      • Delete service network interface card
      • Query mountable public services
      • Query service network interface card details
      • Query service network interface card list
      • Update regular security group for service network interface card
      • Update service network interface card with enterprise security group
      • Update the service network interface card
    • Subnet-Related Interfaces
      • Create reserved network segment
      • Create subnet
      • Delete reserved network segment
      • Delete subnet
      • Query specified subnet
      • Query subnet list
      • Query the reserved network segment list
      • Update subnet
    • VPC-Related Interfaces
      • Create VPC
      • Delete VPC
      • Open VPC relay
      • Query IP Usage by Products in VPC
      • Query specified VPC
      • Query VPC intranet IP
      • Query VPC list
      • Shut down VPC relay
      • Update VPC
    • VPN-Related Interfaces
      • Bind EIP
      • Create SSL VPN server
      • Create SSL VPN users in batches
      • Create VPN tunnel
      • Create VPN
      • Delete SSL VPN server
      • Delete SSL VPN user
      • Delete VPN tunnel
      • Query SSL-VPN server
      • Query SSL-VPN user
      • Query VPN details
      • Query VPN List
      • Query VPN tunnels
      • Release VPN
      • Unbind EIP
      • Update SSL VPN server
      • Update SSL VPN user
      • Update VPN release protection switch
      • Update VPN tunnel
      • Update VPN
      • VPN gateway renewal
    • High-Availability Virtual IP Address (HAVIP) Related Interfaces
      • Bind EIP to high-availability virtual IP address
      • Bind instance to high-availability virtual IP address
      • Create high-availability virtual IP address
      • Delete high-availability virtual IP address
      • Query high-availability virtual IP address list
      • Query the specified high-availability virtual IP address
      • Unbind EIP from high-availability virtual IP address
      • Unbind instance from high-availability virtual IP address
      • Update high-availability virtual IP address
  • FAQs
    • Common Questions Overview
    • NAT FAQs
    • Route Table FAQs
    • Service Network Interface Card(SNIC) Common Questions
    • VPC FAQs
    • VPN FAQs
    • Service Network Interface Card (SNIC) Common Questions
  • Function Release Records
  • Operation guide
    • Access control
      • ACL
      • Parameter Template
      • Security group
    • Identity and access management
    • Monitor and Operations
      • NAT Gateway Instance Diagnosis
    • Network Connection
      • Dedicated gateway
      • IPv6 gateway
      • Layer 2 Gateway
      • NAT Gateway
        • Private Network NAT(Network Address Translation) Gateway
        • Public Network NAT(Network Address Translation) Gateway
        • Private Network NAT (Network Address Translation) Gateway
        • Public Network NAT (Network Address Translation) Gateway
      • Peering Connections
      • VPN Gateway
        • GRE VPN Gateway
        • IPsec VPN Gateway
        • SSL VPN Gateway
    • Network Diagnostics
      • Flow log
      • Gateway bandwidth limiting
      • Network probe
      • Path analysis
      • Port verification
      • Traffic monitor
    • Network interface card
      • Elastic network interface
      • High-availability virtual IP address (HAVIP)
      • Service network interface card
    • Network topology
    • Route table
    • Subnet
    • Tag Management
    • Using IPv6
    • VPC
  • Product Description
    • Application scenarios
    • Product advantages
    • Product features
    • Product Introduction
    • Related concepts
    • Usage restrictions
  • Product pricing
  • SDK
    • Go-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Exception handling
      • High-availability virtual IP address (HAVIP)
      • Initialization
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
        • Enterprise security group
        • Regular security group
      • Service network interface card
      • Subnet
      • VPC
      • VPN
    • Java-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6 gateway
      • NAT
      • Network probe
      • Overview
      • Parameter Template
      • Peering Connections
      • Regular security group
      • Route
      • Service network interface card
      • Subnet
      • Version history
      • vpc
      • VPN
    • PHP-SDK
      • ACL
      • Install the SDK Package
      • NAT
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Subnet
      • Version history
      • vpc
    • Python-SDK
      • ACL
      • Dedicated gateway
      • Elastic network interface
      • Enterprise security group
      • High-availability virtual IP address (HAVIP)
      • Install the SDK Package
      • IPv6Gateway
      • NAT
      • Network probe
      • Overview
      • Peering Connections
      • Route
      • Security group
      • Service network interface card
      • Subnet
      • Version history
      • VPC
      • VPN
  • Service Level Agreement (SLA)
    • IPv6 Gateway Service Level Agreement SLA
    • NAT(Network Address Translation) Gateway Service Level Agreement SLA
    • Peering Connections Service Level Agreement SLA
    • Service Network Interface Card(SNIC) Service Level Agreement SLA
    • VPN Gateway Service Level Agreement SLA
    • NAT (Network Address Translation) Gateway Service Level Agreement SLA
    • Service Network Interface Card (SNIC) Service Level Agreement SLA
  • Typical Practices
    • Configure Custom Service and Use Service Network Interface Card(SNIC) to Provide Service for Other VPCs
    • HAVIP Combined with Keepalived to Achieve Master-Backup Multi-Machine High Availability
    • Layer 2 Gateway Combined with Dedicated Line Access ET to Build Large Layer 2 Network Between IDC and Cloud VPC
    • Network Layer Security Description
    • Peering Connections Typical Practice
    • Security Group Configuration Practice (Advanced Level)
    • Security Group Configuration Practice (Beginner Level)
    • Typical Practice of Managing Elastic Network Interface Using Terraform
    • Typical Practice of Managing IPsec VPN Gateway Using Terraform
    • Using Keepalived in VPC to Achieve High-Availability Architecture
    • VPC Custom Route Table to Achieve Secure Traffic Mutual Access
    • Windows Using HAVIP to Configure Master-Backup Multi-Machine
    • Configure Custom Service and Use Service Network Interface Card (SNIC) to Provide Service for Other VPCs
  • VPC CLI
    • Configure BCE-CLI
    • Install BCE-CLI
    • Route Table Related Operations
    • Subnet Related Operations
    • Using VPC Service via CLI
    • Version Change Records
    • VPC Related Operations
  • Document center
  • arrow
  • VPCVPC
  • arrow
  • SDK
  • arrow
  • Go-SDK
  • arrow
  • NAT
Table of contents on this page
  • Initialization
  • Confirm Endpoint
  • Retrieve access key
  • Create a new NAT client
  • Create a new NAT client with AK/SK
  • Create an NAT client with STS
  • Configure HTTPS access to NAT
  • Configure the NAT client
  • Use a proxy
  • Set network parameters
  • Configure options for generating signature strings
  • NAT gateway management
  • Create NAT gateway
  • Query NAT gateway list
  • Query NAT gateway details
  • Update NAT gateway name
  • Release NAT gateway
  • NAT gateway renewal
  • Bind SNAT EIP to the NAT gateway
  • Unbind SNAT EIP from the NAT gateway
  • Bind DNAT EIP to the NAT gateway
  • Unbind DNAT EIP from the NAT gateway
  • Create SNAT rules
  • Create SNAT rules in batches
  • Delete SNAT rules
  • Update SNAT rules
  • Query SNAT rules
  • Create DNAT rules
  • Create DNAT rules in batches
  • Delete DNAT rules
  • Update DNAT rules
  • Query DNAT rules

NAT

Updated at:2025-10-16

Initialization

Confirm Endpoint

Before configuring the endpoint for SDK usage, please refer to the developer guide section on NAT Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to Region Selection Guide.

Currently supported regions are: "North China-Beijing," "South China-Guangzhou," "East China-Suzhou," "Hong Kong," "Central Finance-Wuhan," and "North China-Baoding." Corresponding details:

Access region Endpoint Protocol
BJ bcc.bj.baidubce.com HTTP and HTTPS
GZ bcc.gz.baidubce.com HTTP and HTTPS
SU bcc.su.baidubce.com HTTP and HTTPS
HKG bcc.hkg.baidubce.com HTTP and HTTPS
FWH bcc.fwh.baidubce.com HTTP and HTTPS
BD bcc.bd.baidubce.com HTTP and HTTPS

Retrieve access key

To use NAT, you must have a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. AK/SK are system-generated identifiers assigned for user authentication and signature certification in NAT.

Your AK/SK information can be obtained and understood through the following steps:

Register a Baidu AI Cloud account

Create AK/SK

Create a new NAT client

A NAT client serves as the interface for accessing NAT services, offering developers various methods to interact with these services.

Create a new NAT client with AK/SK

Users can refer to the following code to create a new NAT Client to access NAT with AK/SK:

Go
1import (
2	"github.com/baidubce/bce-sdk-go/services/vpc"
3)
4func main() {
5 // User’s Access Key ID and Secret Access Key
6	ACCESS_KEY_ID, SECRET_ACCESS_KEY := <your-access-key-id>, <your-secret-access-key>
7 // User-specified Endpoint
8	ENDPOINT := <domain-name>
9 // Initialize a NATClient
10	natClient, err := vpc.NewClient(AK, SK, ENDPOINT)
11}

In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. Refer to the Guide - How to Retrieve AKSK. The third parameter ENDPOINT is a user-specified domain name. If left empty, the default domain name will be used as the VPC service address.

Note:The endpoint parameter must be defined with the domain name of the specified region. For example, if the service is located in Beijing, the endpoint will be bcc.bj.baidubce.com.

Create an NAT client with STS

Request STS Token

NAT provides temporary third-party access authorization using the STS mechanism. STS (Security Token Service) is a temporary authorization service from Baidu AI Cloud. With STS, you can issue temporary access credentials with customized validity periods and permissions to third-party users. These users can use the credentials to directly invoke Baidu AI Cloud APIs or SDKs to access cloud resources.

To access NAT via STS, users must first acquire a certification string through the STS client.

Create NAT Client with STS Token

After acquiring the STS token, configure it in the NAT Client to support STS-based NAT client creation.

Code example

The GO SDK implements the STS service API. Below is a complete example for requesting an STS Token and creating an NAT Client object:

Go
1import (
2	"fmt"
3 "github.com/baidubce/bce-sdk-go/auth"                    //Import the authentication module
4 "github.com/baidubce/bce-sdk-go/services/vpc" //Import VPC service module
5 "github.com/baidubce/bce-sdk-go/services/sts"            //Import the Baige service module
6)
7func main() {
8 //Create a Client object for the STS service, using the default Endpoint
9	AK, SK := <your-access-key-id>, <your-secret-access-key>
10	stsClient, err := sts.NewClient(AK, SK)
11	if err != nil {
12		fmt.Println("create sts client object :", err)
13		return
14	}
15 //Obtain a temporary authentication token with a validity period of 60 seconds and an empty ACL
16	stsObj, err := stsClient.GetSessionToken(60, "")
17	if err != nil {
18		fmt.Println("get session token failed:", err)
19		return
20    }
21	fmt.Println("GetSessionToken result:")
22	fmt.Println("  accessKeyId:", stsObj.AccessKeyId)
23	fmt.Println("  secretAccessKey:", stsObj.SecretAccessKey)
24	fmt.Println("  sessionToken:", stsObj.SessionToken)
25	fmt.Println("  createTime:", stsObj.CreateTime)
26	fmt.Println("  expiration:", stsObj.Expiration)
27	fmt.Println("  userId:", stsObj.UserId)
28 //Create a NAT Client object using the requested temporary STS, with the default endpoint
29	natClient, err := vpc.NewClient(stsObj.AccessKeyId, stsObj.SecretAccessKey, "bcc.bj.baidubce.com")
30	if err != nil {
31		fmt.Println("create nat client failed:", err)
32		return
33	}
34	stsCredential, err := auth.NewSessionBceCredentials(
35		stsObj.AccessKeyId,
36		stsObj.SecretAccessKey,
37		stsObj.SessionToken)
38	if err != nil {
39		fmt.Println("create sts credential object failed:", err)
40		return
41	}
42	natClient.Config.Credentials = stsCredential
43}

Note: Currently, when configuring an NAT client with STS, regardless of where the corresponding NAT service endpoint is located, the STS endpoint must be set to http://sts.bj.baidubce.com. This default is utilized when creating an STS object in the above code.

Configure HTTPS access to NAT

NAT supports the HTTPS transport protocol. To use HTTPS to access NAT services with the NAT Go SDK, specify HTTPS in the endpoint when creating the NAT client object.

Go
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 ENDPOINT := ""https://bcc.bj.baidubce.com" // Specify the use of HTTPS protocol
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4natClient, _ := vpc.NewClient(AK, SK, ENDPOINT)

Configure the NAT client

If users need to configure specific parameters for the NAT Client, they can customize the configuration using the exported Config field of the NAT Client object after its creation. This allows for configuring parameters such as proxy and maximum number of connections for the client.

Use a proxy

The following code snippet enables the client to access NAT service using a proxy:

Go
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 // Create an NAT Client object
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4ENDPOINT := "bcc.bj.baidubce.com"
5client, _ := vpc.NewClient(AK, SK, ENDPOINT)
6 // Use the local port 8080 for the proxy
7client.Config.ProxyUrl = "127.0.0.1:8080"

Set network parameters

Users can configure network parameters using the following example code:

Go
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := bcc.NewClient(AK, SK, ENDPOINT)
5 // Configure to not retry, default: Back Off retry
6client.Config.Retry = bce.NewNoRetryPolicy()
7 // Configure connection timeout to 30 seconds
8client.Config.ConnectionTimeoutInMillis = 30 * 1000

Configure options for generating signature strings

Go
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := bcc.NewClient(AK, SK, ENDPOINT)
5 // Configure the HTTP request header Host for signing
6headersToSign := map[string]struct{}{"Host": struct{}{}}
7client.Config.SignOption.HeadersToSign = HeadersToSign
8 // Configure the validity period of the signature to 30 seconds
9client.Config.SignOption.ExpireSeconds = 30

Parameter description

When using the GO SDK to access NAT, the Config field of the created NAT Client object supports the following parameters, as shown in the table below:

ConfigMap name Types Meaning
Endpoint string Domain name for service requests
ProxyUrl string The proxy address for client requests
Region string Region for resource requests
UserAgent string User name, HTTP request’s User-Agent header
Credentials *auth.BceCredentials Authentication object for requests, divided into regular AK/SK and STS
SignOption *auth.SignOptions Options for authentication string signing
Retry RetryPolicy Retry policy for connections
ConnectionTimeoutInMillis int Connection timeout, in milliseconds, defaulting to 20 minutes

Description:

  1. The Credentials is created using the auth.NewBceCredentials and auth.NewSessionBceCredentials functions. The former is used by default, while the latter is used for STS certification. See "Create an NAT client with STS" for details.
  2. The SignOption field represents options when generating a signature string, as detailed in the table below:
Name Types Meaning
HeadersToSign map[string]struct{} HTTP headers used when generating the signature string
Timestamp int64 Timestamp used in the generated signature string, defaulting to the value at the time of sending request
ExpireSeconds int Validity period of the signature string
Plain Text
1 Among configuration options, HeadersToSign defaults to `Host`, `Content-Type`, `Content-Length` and `Content-MD5`; TimeStamp is typically set to zero, indicating that the timestamp at the time of generating the certification string shall be used, and users generally shall not explicitly specify the value for this field; ExpireSeconds defaults to 1,800 seconds or 30 minutes.
  1. The Retry field specifies the retry policy, currently supporting two types: NoRetryPolicy and BackOffRetryPolicy. By default, the latter is used. This retry policy specifies the maximum number of retries, the maximum retry duration, and the retry base. Retries increase exponentially based on the retry base multiplied by 2 until the maximum number of retries or the maximum retry duration is reached.

NAT gateway management

The network address translation (NAT) gateway provides Internet access for virtual private clouds and supports SNAT and DNAT. It allows multiple cloud server instances to share public IPs for Internet access and enables cloud server instances to deliver Internet services. The NAT gateway can link EIP instances and EIPGROUP to facilitate many-to-one or many-to-many address translation between intranet IPs and public IPs for cloud servers.

Create NAT gateway

Use the following code to create a NAT gateway

Function declaration

Go
1type CreateNatGatewayArgs struct {
2	ClientToken string             `json:"-"`
3	Name        string             `json:"name"`
4	VpcId       string             `json:"vpcId"`
5	Spec        NatGatewaySpecType `json:"spec"`
6	CuNum       string             `json:"cuNum,omitempty"`
7	Eips        []string           `json:"eips,omitempty"`
8	DnatEips    []string           `json:"dnatEips,omitempty"`
9	Billing     *Billing           `json:"billing"`
10	Tags        []model.TagModel   `json:"tags,omitempty"`
11}
12type CreateNatGatewayResult struct {
13	NatId string `json:"natId"`
14}
15func (c *Client) CreateNatGateway(args *CreateNatGatewayArgs) (*CreateNatGatewayResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Xjwvyul3d

Response Value

Operation succeeded:

JSON
1{
2    "natId": "nat-b58rnkn1g98h"
3}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_create_nat.go

Query NAT gateway list

Use the following code to query the NAT gateway list.

Function declaration

Go
1type ListNatGatewayArgs struct {
2	VpcId   string
3	NatId   string
4	Name    string
5	Ip      string
6	Marker  string
7	MaxKeys int
8}
9type ListNatGatewayResult struct {
10	Nats        []NAT  `json:"nats"`
11	Marker      string `json:"marker"`
12	IsTruncated bool   `json:"isTruncated"`
13	NextMarker  string `json:"nextMarker"`
14	MaxKeys     int    `json:"maxKeys"`
15}
16func (c *Client) ListNatGateway(args *ListNatGatewayArgs) (*ListNatGatewayResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Tjwvyukbd

Response value

Operation succeeded:

JSON
1{
2	 "nats":[
3        {
4            "id":"nat-bir8biqwr45e",
5            "name":"mynat",
6            "vpcId":"vpc-13vuxu016dew",
7            "spec":"small",
8            "status":"unconfigured",
9            "eips":[
10            ],
11            "paymentTiming":"Prepaid",
12            "expiredTime":"2018-08-13T08:10:59Z",
13            "createTime": "2021-04-25 17:22:34"
14        },
15        {
16            "id":"nat-b9q8n98mdxwc",
17            "name":"mynat",
18            "vpcId":"vpc-13vuxu016dew",
19            "spec":"small",
20            "status":"unconfigured",
21            "eips":[
22            ],
23            "paymentTiming":"Prepaid",
24            "expiredTime":"2018-07-27T13:18:00Z",
25            "createTime": "2021-04-25 17:22:34"
26        }
27    ]
28}
29"marker":"nat-b58rnkn1g98h",
30"isTruncated": true,
31"nextMarker": "nat-bi72s924x5xu",
32"maxKeys": 2
33}    

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_list_nat.go

Query NAT gateway details

Use the following code to query the NAT gateway details

Function declaration

Go
1type NAT struct {
2	Id            string           `json:"id"`
3	Name          string           `json:"name"`
4	VpcId         string           `json:"vpcId"`
5	Spec          string           `json:"spec,omitempty"`
6	CuNum         int              `json:"cuNum,omitempty"`
7	Status        NatStatusType    `json:"status"`
8	Eips          []string         `json:"eips"`
9	DnatEips      []string         `json:"dnatEips"`
10	PaymentTiming string           `json:"paymentTiming"`
11	ExpiredTime   string           `json:"expiredTime"`
12	Tags          []model.TagModel `json:"tags"`
13}
14func (c *Client) GetNatGatewayDetail(natId string) (*NAT, error)

Parameter meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Mjwvyuj7m

Response value

Operation succeeded:

JSON
1{
2    "id":"nat-bir8biqwr45e",
3    "name":"mynat",
4    "vpcId":"vpc-13vuxu016dew",
5    "spec":"small",
6    "status":"unconfigured",
7    "eips":[
8    ],
9    "dnatEips":[
10    ],
11    "paymentTiming":"Prepaid",
12    "expiredTime":"2018-08-13T08:10:59Z",
13    "createTime": "2021-04-25 17:22:34",
14    "tags":[
15        {
16          "tagKey": "tagKey",
17          "tagValue": "tagValue"
18        }
19    ]
20}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_get_nat_detail.go

Update NAT gateway name

Use the following code to update the NAT gateway name

Function declaration

Go
1type UpdateNatGatewayArgs struct {
2	ClientToken string `json:"-"`
3	Name        string `json:"name"`
4}
5func (c *Client) UpdateNatGateway(natId string, args *UpdateNatGatewayArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/ojwvyuisy

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_update_nat.go

Release NAT gateway

Use the following code to release a NAT gateway

Function declaration

Go
1func (c *Client) DeleteNatGateway(natId, clientToken string) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/yjwvyujjq

Response Value

Operation succeeded:

No special response parameters are available.

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_delete_nat.go

NAT gateway renewal

Use the following code to renew a NAT gateway

Function declaration

Go
1type RenewNatGatewayArgs struct {
2	ClientToken string   `json:"-"`
3	Billing     *Billing `json:"billing"`
4}
5func (c *Client) RenewNatGateway(natId string, args *RenewNatGatewayArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Vjwvyukqv

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_renew_nat.go

Bind SNAT EIP to the NAT gateway

Use the following code to bind an SNAT EIP

Function declaration

Go
1type BindEipsArgs struct {
2	ClientToken string   `json:"-"`
3	Eips        []string `json:"eips"`
4}
5func (c *Client) BindEips(natId string, args *BindEipsArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Ljwvyujy8

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_bind_eip.go

Unbind SNAT EIP from the NAT gateway

Use the following code to unbind a SNAT EIP

Function declaration

Go
1type BindEipsArgs struct {
2	ClientToken string   `json:"-"`
3	Eips        []string `json:"eips"`
4}
5func (c *Client) BindEips(natId string, args *BindEipsArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/qjwvyuigl

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_unbind_eip.go

Bind DNAT EIP to the NAT gateway

Use the following code to bind an DNAT EIP

Function declaration

Go
1type BindDnatEipsArgs struct {
2	ClientToken string   `json:"-"`
3	DnatEips    []string `json:"dnatEips"`
4}
5func (c *Client) BindDnatEips(natId string, args *BindDnatEipsArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/iki4chiu4

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_bind_dnat_eip.go

Unbind DNAT EIP from the NAT gateway

Use the following code to unbind a DNAT EIP

Function declaration

Go
1type UnBindDnatEipsArgs struct {
2	ClientToken string   `json:"-"`
3	DnatEips    []string `json:"dnatEips"`
4}
5func (c *Client) UnBindDnatEips(natId string, args *UnBindDnatEipsArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Uki4cj64l

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_unbind_dnat_eip.go

Create SNAT rules

Users can create SNAT rules with the following code.

Function declaration

Go
1type CreateNatGatewaySnatRuleArgs struct {
2	ClientToken       string   `json:"-"`
3	RuleName          string   `json:"ruleName,omitempty"`
4	SourceCIDR        string   `json:"sourceCIDR,omitempty"`
5	PublicIpAddresses []string `json:"publicIpsAddress,omitempty"`
6}
7type CreateNatGatewaySnatRuleResult struct {
8	RuleId string `json:"ruleId"`
9}
10func (c *Client) CreateNatGatewaySnatRule(natId string, args *CreateNatGatewaySnatRuleArgs) (*CreateNatGatewaySnatRuleResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Iki4clqjv

Response Value

Operation succeeded:

JSON
1{
2    "ruleId": "rule-zrsaybxm7nrn"
3}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_create_snat_rule.go

Create SNAT rules in batches

Users can create SNAT rules in batches with the following code.

Function declaration

Go
1type BatchCreateNatGatewaySnatRuleArgs struct {
2	ClientToken string         `json:"-"`
3	NatId       string         `json:"natId"`
4	SnatRules   []SnatRuleArgs `json:"snatRules"`
5}
6type BatchCreateNatGatewaySnatRuleResult struct {
7	SnatRuleIds []string `json:"snatRuleIds"`
8}
9func (c *Client) BatchCreateNatGatewaySnatRule(args *BatchCreateNatGatewaySnatRuleArgs) (*BatchCreateNatGatewaySnatRuleResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/oktlo8qfr

Response Value

Operation succeeded:

JSON
1{
2    "snatRuleIds": [
3      "rule-zrsaybxm7nrn",
4      "rule-f5kid5g50nua"
5    ]
6}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_batch_create_snat_rule.go

Delete SNAT rules

Users can delete SNAT rules with the following code

Function declaration

Go
1func (c *Client) DeleteNatGatewaySnatRule(natId string, snatRuleId string, clientToken string) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/vki4cot86

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_delete_snat_rule.go

Update SNAT rules

Users can update SNAT rules with the following code

Function declaration

Go
1type UpdateNatGatewaySnatRuleArgs struct {
2	ClientToken       string   `json:"-"`
3	RuleName          string   `json:"ruleName,omitempty"`
4	SourceCIDR        string   `json:"sourceCIDR,omitempty"`
5	PublicIpAddresses []string `json:"publicIpsAddress,omitempty"`
6}
7func (c *Client) UpdateNatGatewaySnatRule(natId string, snatRuleId string, args *UpdateNatGatewaySnatRuleArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Vki4cn14y

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_update_snat_rule.go

Query SNAT rules

Users can query SNAT rules with the following code

Function declaration

Go
1type ListNatGatewaySnatRuleArgs struct {
2	NatId   string `json:"natId"`
3	Marker  string `json:"marker"`
4	MaxKeys int    `json:"maxKeys"`
5}
6type ListNatGatewaySnatRulesResult struct {
7	Rules       []SnatRule `json:"rules"`
8	Marker      string     `json:"marker"`
9	IsTruncated bool       `json:"isTruncated"`
10	NextMarker  string     `json:"nextMarker"`
11	MaxKeys     int        `json:"maxKeys"`
12}
13func (c *Client) ListNatGatewaySnatRules(args *ListNatGatewaySnatRuleArgs) (*ListNatGatewaySnatRulesResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Pki4cq2nu

Response Value

Operation succeeded:

JSON
1{
2	"isTruncated": true,
3    "nextMarker": "rule-vza86i2k6dqu",
4    "maxKeys": 2,
5    "rules": [
6     {
7            "ruleId": "rule-k1jenum3v9s6",
8            "ruleName": "s3",
9            "publicIpsAddress": [
10                "100.88.10.185"
11            ],
12            "sourceCIDR": "1.1.1.1/32",
13            "status": "configuring"
14        },
15        {
16            "ruleId": "rule-kdgqkwpske2q",
17            "ruleName": "s2",
18            "publicIpsAddress": [
19                "100.88.10.185"
20            ],
21            "sourceCIDR": "192.168.1.0/24",
22            "status": "configuring"
23        }
24    ]
25}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_list_snat_rule.go

Create DNAT rules

Users can create DNAT rules with the following code.

Function declaration

Go
1type CreateNatGatewayDnatRuleArgs struct {
2	ClientToken      string `json:"-"`
3	RuleName         string `json:"ruleName,omitempty"`
4	PublicIpAddress  string `json:"publicIpAddress,omitempty"`
5	PrivateIpAddress string `json:"privateIpAddress,omitempty"`
6	Protocol         string `json:"protocol,omitempty"`
7	PublicPort       string `json:"publicPort,omitempty"`
8	PrivatePort      string `json:"privatePort,omitempty"`
9}
10type CreateNatGatewayDnatRuleResult struct {
11	RuleId string `json:"ruleId"`
12}
13func (c *Client) CreateNatGatewayDnatRule(natId string, args *CreateNatGatewayDnatRuleArgs) (*CreateNatGatewayDnatRuleResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/fki4c1gb3

Response Value

Operation succeeded:

JSON
1{
2    "ruleId": "rule-zrsaybxm7nrn"
3}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_create_dnat_rule.go

Create DNAT rules in batches

Users can create DNAT rules in batches with the following code.

Function declaration

Go
1type BatchCreateNatGatewayDnatRuleArgs struct {
2	ClientToken string         `json:"-"`
3	Rules       []DnatRuleArgs `json:"rules"`
4}
5type BatchCreateNatGatewayDnatRuleResult struct {
6	RuleIds []string `json:"ruleIds"`
7}
8func (c *Client) BatchCreateNatGatewayDnatRule(natId string, args *BatchCreateNatGatewayDnatRuleArgs) (*BatchCreateNatGatewayDnatRuleResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Aktl8mzvd

Response Value

Operation succeeded:

JSON
1{
2    "ruleIds": [
3      "rule-zrsaybxm7nrn",
4      "rule-f5kid5g50nua"
5    ]
6}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_batch_create_dnat_rule.go

Delete DNAT rules

Users can delete DNAT rules with the following code

Function declaration

Go
1func (c *Client) DeleteNatGatewayDnatRule(natId string, dnatRuleId string, clientToken string) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/zki4cbkkf

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_delete_dnat_rule.go

Update DNAT rules

Users can update DNAT rules with the following code

Function declaration

Go
1type UpdateNatGatewayDnatRuleArgs struct {
2	ClientToken      string `json:"-"`
3	RuleName         string `json:"ruleName,omitempty"`
4	PublicIpAddress  string `json:"publicIpAddress,omitempty"`
5	PrivateIpAddress string `json:"privateIpAddress,omitempty"`
6	Protocol         string `json:"protocol,omitempty"`
7	PublicPort       string `json:"publicPort,omitempty"`
8	PrivatePort      string `json:"privatePort,omitempty"`
9}
10func (c *Client) UpdateNatGatewayDnatRule(natId string, dnatRuleId string, args *UpdateNatGatewayDnatRuleArgs) error

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Aki4c9crm

Response Value

Operation succeeded:

There are no special response parameters

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_update_dnat_rule.go

Query DNAT rules

Users can query DNAT rules with the following code

Function declaration

Go
1type ListNatGatewaDnatRuleArgs struct {
2	Marker  string `json:"marker"`
3	MaxKeys int    `json:"maxKeys"`
4}
5type ListNatGatewayDnatRulesResult struct {
6	Rules       []DnatRule `json:"rules"`
7	Marker      string     `json:"marker"`
8	IsTruncated bool       `json:"isTruncated"`
9	NextMarker  string     `json:"nextMarker"`
10	MaxKeys     int        `json:"maxKeys"`
11}
12func (c *Client) ListNatGatewayDnatRules(natId string, args *ListNatGatewaDnatRuleArgs) (*ListNatGatewayDnatRulesResult, error)

Parameter Meaning

Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Hki4cf6bf

Response Value

Operation succeeded:

JSON
1{
2	"isTruncated": true,
3    "nextMarker": "rule-pej10dar6pxd",
4    "maxKeys": 2,
5    "rules": [
6        {
7            "ruleId": "rule-29d9jpprcm75",
8            "ruleName": "sg",
9            "publicIpAddress": "100.88.6.197",
10            "privateIpAddress": "192.168.3.3",
11            "publicPort": 333,
12            "privatePort": 333,
13            "status": "active",
14            "protocol": "TCP"
15        },
16        {
17            "ruleId": "rule-72z6p8ni6rce",
18            "ruleName": "sd",
19            "publicIpAddress": "100.88.6.197",
20            "privateIpAddress": "192.168.2.2",
21            "publicPort": 222,
22            "privatePort": 222,
23            "status": "active",
24            "protocol": "UDP"
25        }
26    ]
27}

Operation failed:

Throw an exception. For the exception list, refer to: NAT Gateway Exception List

Code example

For specific code examples, refer to example_list_dnat_rule.go

Previous
IPv6Gateway
Next
Network probe