NAT
Acquire Endpoint
When confirming the Endpoint configured when you use the SDK, you can first read the section on VPC Service Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently opens the multi-region (Region) support. Please refer to the part of network product VPC in Region Selection Introduction. The NAT services are a part of VPC services, and use the VPC service domain name.
Get the Key
To use Baidu Cloud products, you need to have a Baidu Cloud account and a valid AK (Access Key ID) and SK (Secret Access Key) for signature verification. You can obtain and understand your AK/SK information through the following steps:
1.[Register Baidu Cloud Account](https://login.bce.baidu.com/reg.html? tpl=bceplat&from=portal) 2.[Create AK/SK](https://console.bce.baidu.com/iam/? _=1513940574695#/iam/accesslist)
NatClient
Natclient is the Java client of NAT services, encapsulates the API of NAT services, and simplifies the interaction between developers and NAT services. The users can call the methods in NatClient to configure the NAT gateway.
Create NatClient
When creating NatClient, you need to first use Endpoint, AK and SK to configure the NatClientConfiguration type config instance, and then use the config instance to configure the NatClient. The configuration example is as follows:
static final String HOST = "";
static final String AK = "";
static final String SK = "";
NatClientConfiguration config = new NatClientConfiguration();
config.setCredentials(new DefaultBceCredentials(AK, SK));
config.setEndpoint(HOST);
NatClient natClient = new NatClient(config);
Create NAT Gateway
The createNat function can be used to create the NAT gateway in the specified VPC, and is defined as below:
public CreateNatResponse createNat(CreateNatRequest request)
Refer to the code directory for the definitions of CreateNatRequest and CreateNatResponse: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
name | String | Yes | The name of NAT gateway is composed by upper and lower case letters, numbers, and -_ /. special characters, and must start with letters, with a length of the range from1to 65. |
vpcId | String | Yes | ID of VPC to which NAT gateway belongs |
eips | List<String> | No | EIP bound to the NAT gateway |
spec | String | Yes | The size of NAT gateway is divided into three kinds: small (supporting binding a maximum of 5 public network IPs), medium (supporting binding a maximum of 10 public network IPs) and large (supporting binding a maximum of 15 public network IPs). |
billing | Customized Billing type | Yes | The billing mode supports the purchase by postpaid and monthly repayment. Refer to Billing Description for details. |
For the customized Billing type definition, refer to Billing.java.
Query the NAT Gateway List
The listNat function can be used to query the NAT gateway list. If the query condition is queried, the NAT gateways are screened according to the query condition. If no query condition is provided, all NAT gateways are queried by default. The function is defined as below:
public ListNatResponse listNat(ListNatRequest request)
Refer to the code directory for the definitions of ListNatRequest and ListNatResponse: nat/model/
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
vpcId | String | Yes | ID of VPC to which NAT gateway belongs |
natId | String | No | ID of NAT gateway |
name | String | No | Name of NAT gateway |
ip | String | No | IP address bound to the gateway |
marker | String | No | Starting location of query for batch acquisition of lists |
maxKeys | int | No | Maximum number contained in each page, generally not exceeding 1000. The default value is 1000. |
Query the NAT Gateway Details
The getNat function can be used to query the NAT details, and is defined as below:
public GetNatResponse getNat(String natId)
Refer to the code directory for the definition of GetNatResponse: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
Update the NAT Gateway Name
The modifyNat function can be used to update the NAT gateway name, and is defined as below:
public void modifyNat(ModifyNatRequest request)
Refer to the code directory for the definition of ModifyNatRequest: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
name | String | Yes | New name of NAT gateway |
Bind EIP
The bindEip function can be used to bind EIP to the NAT gateway, and is defined as below:
public void bindEip(BindEipRequest request)
Refer to the code directory for the definition of BindEipRequest: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
eips | List<String> | Yes | EIP to be bound to the NAT gateway |
Unbind EIP
The unbindEip function can be used to unbind EIP from the NAT gateway, and is defined as below:
public void unbindEip(BindEipRequest request)
Refer to the code directory for the definition of BindEipRequest: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
eips | List<String> | Yes | EIP to be unbound from the NAT gateway |
Release the NAT Gateway
The releaseNat function can be used to release the NAT gateway, and is defined as below:
public void releaseNat(ReleaseNatRequest request)
Refer to the code directory for the definition of ReleaseNatRequest: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
NAT Gateway Renewal
The purchaseReservedNat function can be used to renew the NAT gateway, and only the prepaid type supports the renewal operation. The function is defined as below:
public void purchaseReservedNat(PurchaseReservedNatRequest request)
Refer to the code directory for the definition of PurchaseReservedNatRequest: nat/model/ The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
natId | String | Yes | ID of NAT gateway |
billing | Customized Billing type | Yes | For the billion mode, refer to Billing Description for details. |
For the customized Billing type definition, refer to Billing.java.