Alibaba Cloud Command Line Interface (CLI) is a general-purpose command-line tool that is developed based on OpenAPI Explorer. You can integrate Alibaba Cloud CLI with Private DNS and manage the resources of Private DNS by using a shell tool. This topic describes how to use Alibaba Cloud CLI to call the API operations of Private DNS.
Background information
For more information about Alibaba Cloud CLI, see What is Alibaba Cloud CLI?
Install Alibaba Cloud CLI
You must install Alibaba Cloud CLI before you can use Alibaba Cloud CLI. You can install Alibaba Cloud CLI on the Windows, Linux, and macOS operating systems. Select an installation package of Alibaba Cloud CLI based on the operating system of your device. For more information, see the following topics:
You can also use Cloud Shell provided by Alibaba Cloud to debug the commands that you want to run in Alibaba Cloud CLI. For more information about Cloud Shell, see What is Cloud Shell?
Configure Alibaba Cloud CLI
An Alibaba Cloud account has the permissions to manage and access the APIs of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you create and use a RAM user to call API operations or perform routine O&M operations. You must attach the AliyunPvtzFullAccess policy to the RAM user. This policy allows the RAM user to manage the resources of Private DNS.
Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and a region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see the Credential types section of the Configure profiles topic. In this example, AccessKey credentials are used. Perform the following steps to configure Alibaba Cloud CLI:
Create a RAM user and grant the permissions to manage Alibaba Cloud services based on your business requirements. For more information, see Create a RAM user and Grant permissions to a RAM user.
Create an AccessKey pair for the RAM user and record the
AccessKey IDandAccessKey secretfor the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.Specify a region ID. Alibaba Cloud CLI calls API operations in the specified region. For more information about available regions, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can specify the
--regionoption to run a command in a specific region. If you specify this option, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings. For more information, see Command line options for API calls.Use the AccessKey pair of the RAM user to configure identity credentials in the configuration file named
AkProfile. For more information, see the Configuration examples section of the Configure identity credentials topic.
Generate a CLI command
Go to the Debugging page of the Private DNS API.
In the left-side search box of the Debugging page, search for the API operation that you want to call. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right side to view the generated sample command that contains the specified parameters.

Click the Run Command in CloudShell
icon to start Cloud Shell and debug the command in Cloud Shell. Click the Copy
icon to copy the sample command to the clipboard. You can paste the sample command into your local shell tool to run the sample command. Pay attention to the parameter formats when you copy and paste the CLI command to the local shell tool. For more information about the parameter formats in Alibaba Cloud CLI commands, see Parameter formats.
By default, the
--regionoption is added to the sample command that is generated in OpenAPI Explorer. When you copy the command to your local shell tool, Alibaba Cloud CLI ignores the region information in the default credential configurations and environment variable settings, and preferentially runs the command in the specified region. You can delete or retain this option based on your business requirements.
Use Alibaba Cloud CLI to call the API operations of Private DNS
Syntax
In Alibaba Cloud CLI, you can use the syntax shown in the following code block to run commands. For more information, see Syntax.
aliyun <command> <subcommand> [options and parameters]Command options
When you use Alibaba Cloud CLI, you can specify command options to change the default behaviors of commands or implement the extended features of commands. The following command options are frequently used:
--profile<profileName>: You can use the--profileoption and theprofileNameparameter to specify a configuration profile. After you specify a valid configuration profile, Alibaba Cloud CLI ignores the information in default credential configurations and environment variable settings and preferentially uses the configurations that you specify to run commands.--help: You can specify the--helpoption to obtain the help information about a command. For more information, see Use the help command.
For more information, see Command line options for API calls.
Examples
In the following examples, commands are run in Command Prompt of Windows. The parameter formats of commands vary on other operating systems. For more information about the parameter formats in Alibaba Cloud CLI commands, see Parameter formats.
Example 1: Use Alibaba Cloud CLI to call the
AddZoneoperation of Private DNS to create a zone named zone_test in the built-in authoritative acceleration module.Run the command.
aliyun pvtz AddZone --region cn-qingdao --ZoneName zone_test --DnsGroup FAST_ZONEView the command output.
{ "RequestId": "139C297E-8E9C-5E06-8758-CD4D6A4C89AF", "Success": true, "ZoneId": "79e6d8c6974042e9c9a4a988130****", "ZoneName": "zone_test" }
Example 2: Use Alibaba Cloud CLI to call the
AddZoneRecordoperation of Private DNS to add a Domain Name System (DNS) record for the zone named zone_test.Run the command.
aliyun pvtz AddZoneRecord --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Rr www --Type A --Value '192.168.XX.XX'View the command output.
{ "RecordId": 440563****, "RequestId": "61DD3A77-9E25-5E86-A314-3E2B741BE44A", "Success": true }
Example 3: Use Alibaba Cloud CLI to call the
BindZoneVpcoperation of Private DNS. This API operation is used to associate one or more virtual private clouds (VPCs) with the zone named zone_test to specify the effective scope of the zone.Run the command.
aliyun pvtz BindZoneVpc --region cn-qingdao --ZoneId 79e6d8c6974042e9c9a4a9881306**** --Vpcs.1.VpcId 'vpc-0jl96awrjt75ezglc****'View the command output.
{ "RequestId": "9D48AF1B-A5DE-50B8-9882-481C8C5010F8" }
If an error code is returned after you call an API operation of Private DNS, you must check whether the request parameters and their values are valid based on the returned error code.
You can also use Alibaba Cloud OpenAPI Diagnostics to perform self-service diagnostics based on the returned request ID or SDK error information.