Amazon Elastic Compute Cloud
CLI Reference (API Version 2014-10-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.

ec2-assign-private-ip-addresses

Description

Assigns one or more secondary private IP addresses to the specified network interface. You can specify one or more specific secondary IP addresses, or you can specify the number of secondary IP addresses to be automatically assigned within the subnet's CIDR block range. The number of secondary IP addresses that you can assign to an instance varies by instance type. For more information, see Private IP Addresses Per ENI Per Instance Type and Elastic IP Addresses in the Amazon EC2 User Guide for Linux Instances.

The short version of this command is ec2apip.

Tip

If you are using the AWS CLI, see assign-private-ip-addresses instead.

Syntax

ec2-assign-private-ip-addresses --network-interface interface_id {[--secondary-private-ip-address-count count] | [--secondary-private-ip-address ip_address]}

Options

NameDescription

-n, --network-interface interface_id

The ID of the network interface.

Type: String

Default: None

Required: Yes

Example: -n eni-bc7299d4

-secondary-private-ip-address ip_address

The IP address to be assigned as a secondary private IP address to the network interface. This option can be used multiple times to assign multiple secondary IP addresses to the network interface.

If you don't specify an IP address, Amazon EC2 selects an IP address within the subnet range.

Type: String

Default: None

Required: Conditional

Condition: You can't specify this parameter when also specifying --secondary-private-ip-address-count.

Example: --secondary-private-ip-address 10.0.2.18 --secondary-private-ip-address 10.0.2.28

-secondary-private-ip-address-count count

The number of secondary IP addresses to assign to the network interface.

Type: Integer

Default: None

Required: Conditional

Condition: You can't specify this parameter when also specifying --secondary-private-ip-address.

Example: --secondary-private-ip-address-count 2

--allow-reassignment

Specifies whether to allow an IP address that is already assigned to another network interface to be reassigned to the specified network interface.

Type: Boolean

Default: false

Required: No

Common Options

OptionDescription

--region region

The region. Overrides the default region, the region specified by the EC2_URL environment variable, and the URL specified by the -U option.

Default: The region specified by the EC2_URL environment variable, or us-east-1 if EC2_URL isn't set.

-U, --url url

The uniform resource locator (URL) of the Amazon EC2 web service entry point.

Default: The endpoint specified by the EC2_URL environment variable, or https://ec2.amazonaws.com if EC2_URL isn't set.

-O, --aws-access-key aws_access_key_id

Your access key ID. For more information, see Tell the Tools Who You Are.

Default: The value of the AWS_ACCESS_KEY environment variable. If AWS_ACCESS_KEY isn't set, you must specify this option.

Example: -O AKIAIOSFODNN7EXAMPLE

-W, --aws-secret-key aws_secret_access_key

Your secret access key.

Default: The value of the AWS_SECRET_KEY environment variable. If AWS_SECRET_KEY isn't set, you must specify this option.

Example: -W wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

-T, --security-token delegation_token

The delegation token to pass along to the AWS request. This is only required when you are using temporary security credentials. For more information, see Using Temporary Security Credentials.

Default: The value of the AWS_DELEGATION_TOKEN environment variable (if set).

Example: -t AQoDYXdzEJr...<remainder of security token>

--connection-timeout timeout

The connection timeout, in seconds.

Example: --connection-timeout 30

--request-timeout timeout

The request timeout, in seconds.

Example: --request-timeout 45

-H, --headers

Includes column headers in the command output.

--show-empty-fields

Shows empty columns as (nil).

--hide-tags

Omits tags for tagged resources.

--debug

Displays internal debugging information. This can assist us when helping you troubleshooting problems.

-D, --auth-dry-run

Checks whether you have the required permissions for the command, without actually running the command. If you have the required permissions, the command returns DryRunOperation; otherwise, it returns UnauthorizedOperation.

-v, --verbose

Displays verbose output, including the API request and response on the command line. This is useful if you are building tools to talk directly to the Query API.

-

Reads arguments from standard input. This is useful when piping the output from one command to the input of another.

Example: ec2-describe-instances | grep stopped | cut -f 2 | ec2-start-instances -

-?, --help, -h

Displays usage information for the command.

Deprecated Options

We have deprecated the SOAP API for Amazon EC2. For more information, see SOAP Requests. From version 1.6.14.0 onwards of the Amazon EC2 CLI tools, the private key (-K, --private-key) and X.509 certificate (-C, --cert) options are not supported. Use your access key ID (-O, --aws-access-key) and secret access key (-W, --aws-secret-key) instead. For more information, see Setting Up the Amazon EC2 CLI and AMI Tools.

OptionDescription

-K, --private-key ec2_private_key

The private key to use when constructing requests to Amazon EC2.

Default: The value of the EC2_PRIVATE_KEY environment variable.

Example: -K pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem

-C, --cert ec2_cert

The X.509 certificate to use when constructing requests to Amazon EC2.

Default: The value of the EC2_CERT environment variable.

Example: -C cert-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem

Output

The command returns true if the operation succeeds or an error if the operation does not succeed.

Amazon EC2 command line tools display errors on stderr.

Examples

Example 1

This example command assigns two secondary private IP addresses (10.0.0.118 and 10.0.0.119) to the network interface eni-c08a35a9.

PROMPT> ec2-assign-private-ip-addresses --network-interface eni-c08a35a9
--secondary-private-ip-address 10.0.0.118 --secondary-private-ip-address 10.0.0.119
RETURN true

Example 2

This example command assigns two secondary private IP addresses to the network interface eni-c08a35a9. Amazon EC2 automatically assigns these IP addresses from the available IP addresses within the subnet's CIDR block range.

PROMPT> ec2-assign-private-ip-addresses --network-interface eni-c08a35a9
				--secondary-private-ip-address-count 2
RETURN true

Example 3

This example command assigns a secondary private IP address of 10.0.0.82 to the network interface eni-73e05a1.

PROMPT> ec2-assign-private-ip-addresses --network-interface eni-73e05a1
				--secondary-private-ip-address 10.0.0.82
RETURN true