Create a network interface for your EC2 instance (original) (raw)

You can create a network interface for use by your EC2 instances. When you create a network interface, you specify the subnet for which it is created. You can't move a network interface to another subnet after it's created. You must attach a network interface to an instance in the same Availability Zone. You can detach a secondary network interface from an instance and then attach it to a different instance in the same Availability Zone. You can't detach a primary network interface from an instance. For more information, see Network interface attachments for your EC2 instance.

Console

To create a network interface
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Network Interfaces.
  3. Choose Create network interface.
  4. (Optional) For Description, enter a descriptive name.
  5. For Subnet, select a subnet. The options available in the subsequent steps change depending on the type of subnet you select (IPv4-only, IPv6-only, or dual-stack (IPv4 and IPv6)).
  6. For Private IPv4 address, do one of the following:
    • Choose Auto-assign to allow Amazon EC2 to select an IPv4 address from the subnet.
    • Choose Custom and enter an IPv4 address that you select from the subnet.
  7. (Subnets with IPv6 addresses only) For IPv6 address, do one of the following:
    • Choose None if you do not want to assign an IPv6 address to the network interface.
    • Choose Auto-assign to allow Amazon EC2 to select an IPv6 address from the subnet.
    • Choose Custom and enter an IPv6 address that you select from the subnet.
  8. (Optional) If you’re creating a network interface in a dual-stack or IPv6-only subnet, you have the option to Assign Primary IPv6 IP. This assigns a primary IPv6 global unicast address (GUA) to the network interface. Assigning a primary IPv6 address enables you to avoid disrupting traffic to instances or ENIs. Choose Enable if the instance that this ENI will be attached to relies on its IPv6 address not changing. AWS will automatically assign an IPv6 address associated with the ENI attached to your instance to be the primary IPv6 address. Once you enable an IPv6 GUA address to be a primary IPv6, you can't disable it. When you enable an IPv6 GUA address to be a primary IPv6, the first IPv6 GUA will be made the primary IPv6 address until the instance is terminated or the network interface is detached. If you have multiple IPv6 addresses associated with an ENI attached to your instance and you enable a primary IPv6 address, the first IPv6 GUA address associated with the ENI becomes the primary IPv6 address.
  9. (Optional) To create an Elastic Fabric Adapter, choose Elastic Fabric Adapter,Enable.
  10. (Optional) Under Advanced settings, you can optionally set IP prefix delegation. For more information, see Prefix delegation.
  1. (Optional) Under Advanced settings, for Idle connection tracking timeout, modify the default idle connection timeouts. For more information, seeIdle connection tracking timeout.
  1. For Security groups, select one or more security groups.
  2. (Optional) For each tag, choose Add new tag and enter a tag key and an optional tag value.
  3. Choose Create network interface.

AWS CLI

Example 1: To create a network interface with IP addresses chosen by Amazon EC2

Use the following create-network-interface command. This example creates a network interface with a public IPv4 address and an IPv6 address chosen by Amazon EC2.

aws ec2 create-network-interface \
    --subnet-id subnet-0abcdef1234567890 \
    --description "my dual-stack network interface" \
    --ipv6-address-count 1 \
    --groups sg-1234567890abcdef0
Example 2: To create a network interface with specific IP addresses

Use the following create-network-interface command.

aws ec2 create-network-interface \
    --subnet-id subnet-0abcdef1234567890 \
    --description "my dual-stack network interface" \
    --private-ip-address 10.251.50.12 \
    --ipv6-addresses 2001:db8:🔢5678:1.2.3.4 \
    --groups sg-1234567890abcdef0
Example 3: To create a network interface with a count of secondary IP addresses

Use the following create-network-interface command. In this example, Amazon EC2 chooses both the primary IP address and the secondary IP addresses.

aws ec2 create-network-interface \
    --subnet-id subnet-0abcdef1234567890 \
    --description "my network interface" \
    --secondary-private-ip-address-count 2 \
    --groups sg-1234567890abcdef0
Example 4: To create a network interface with a specific secondary IP address

Use the following create-network-interface command. This example specifies a primary IP address and a secondary IP address.

aws ec2 create-network-interface \
    --subnet-id subnet-0abcdef1234567890 \
    --description "my network interface" \
    --private-ip-addresses PrivateIpAddress=10.0.1.30,Primary=true \
                           PrivateIpAddress=10.0.1.31,Primary=false
    --groups sg-1234567890abcdef0

PowerShell

Example 1: To create a network interface with IP addresses chosen by Amazon EC2

Use the New-EC2NetworkInterface cmdlet. This example creates a network interface with a public IPv4 address and an IPv6 address chosen by Amazon EC2.

New-EC2NetworkInterface `
    -SubnetId subnet-0abcdef1234567890 `
    -Description "my dual-stack network interface" `
    -Ipv6AddresCount 1 `
    -Group sg-1234567890abcdef0
Example 2: To create a network interface with specific IP addresses

Use the New-EC2NetworkInterface cmdlet.

New-EC2NetworkInterface `
    -SubnetId subnet-0abcdef1234567890 `
    -Description "my dual-stack network interface" `
    -PrivateIpAddress 10.251.50.12 `
    -Ipv6Address $ipv6addr `
    -Group sg-1234567890abcdef0

Define the IPv6 addresses as follows.

$ipv6addr = New-Object Amazon.EC2.Model.InstanceIpv6Address
$ipv6addr1.Ipv6Address = "2001:db8:🔢5678:1.2.3.4"
Example 3: To create a network interface with a count of secondary IP addresses

Use the New-EC2NetworkInterface cmdlet. In this example, Amazon EC2 chooses both the primary IP address and the secondary IP addresses.

New-EC2NetworkInterface `
    -SubnetId subnet-0abcdef1234567890 `
    -Description "my network interface" `
    -SecondaryPrivateIpAddressCount 2 `
    -Group sg-1234567890abcdef0
Example 4: To create a network interface with a specific secondary IP address

Use the New-EC2NetworkInterface cmdlet. This example specifies a primary IP address and a secondary IP address.

New-EC2NetworkInterface `
    -SubnetId subnet-0abcdef1234567890 `
    -Description "my network interface" `
    -PrivateIpAddresses @($primary, $secondary) `
    -Group sg-1234567890abcdef0

Define the secondary addresses as follows.

$primary = New-Object Amazon.EC2.Model.PrivateIpAddressSpecification
$primary.PrivateIpAddress = "10.0.1.30" <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>r</mi><mi>i</mi><mi>m</mi><mi>a</mi><mi>r</mi><mi>y</mi><mi mathvariant="normal">.</mi><mi>P</mi><mi>r</mi><mi>i</mi><mi>m</mi><mi>a</mi><mi>r</mi><mi>y</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">primary.Primary = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8778em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">ima</span><span class="mord mathnormal" style="margin-right:0.03588em;">ry</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">ima</span><span class="mord mathnormal" style="margin-right:0.03588em;">ry</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>true
$secondary = New-Object Amazon.EC2.Model.PrivateIpAddressSpecification
$secondary.PrivateIpAddress = "10.0.1.31" <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>e</mi><mi>c</mi><mi>o</mi><mi>n</mi><mi>d</mi><mi>a</mi><mi>r</mi><mi>y</mi><mi mathvariant="normal">.</mi><mi>P</mi><mi>r</mi><mi>i</mi><mi>m</mi><mi>a</mi><mi>r</mi><mi>y</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">secondary.Primary = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">seco</span><span class="mord mathnormal">n</span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.03588em;">ry</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">ima</span><span class="mord mathnormal" style="margin-right:0.03588em;">ry</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>false

IP addresses per network interface

Network interface attachments

Did this page help you? - Yes

Thanks for letting us know we're doing a good job!

If you've got a moment, please tell us what we did right so we can do more of it.

Did this page help you? - No

Thanks for letting us know this page needs work. We're sorry we let you down.

If you've got a moment, please tell us how we can make the documentation better.