Network interface attachments for your EC2 instance (original) (raw)

You can create network interfaces to be used by your EC2 instances as primary or secondary network interfaces. You must attach a network interface to an EC2 instance if it is in the same Availability Zone as the network interface. The instance type of an instance determines how many network interfaces you can attach to the instance. For more information, see Maximum IP addresses per network interface.

Considerations

Attach a network interface

You can attach a network interface to any instance in the same Availability Zone as the network interface, using either the Instances or Network Interfaces page of the Amazon EC2 console. Alternatively, you can specify existing network interfaces when you launch instances.

If the public IPv4 address on your instance is released, it does not receive a new one if there is more than one network interface attached to the instance. For more information about the behavior of public IPv4 addresses, see Public IPv4 addresses.

Console

To attach a network interface using the Instances page
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Instances.
  3. Select the checkbox for the instance.
  4. Choose Actions, Networking,Attach network interface.
  5. Choose a VPC. The network interface can reside in the same VPC as your instance or in a different VPC that you own, as long as the network interface is in the same Availability Zone as the instance. This enables you to create multi-homed instances across VPCs with different networking and security configurations.
  6. Select a network interface. If the instance supports multiple network cards, you can choose a network card.
  7. Choose Attach.
To attach a network interface using the Network Interfaces page
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Network Interfaces.
  3. Select the checkbox for the network interface.
  4. Choose Actions, Attach.
  5. Choose an instance. If the instance supports multiple network cards, you can choose a network card.
  6. Choose Attach.

AWS CLI

To attach a network interface

Use the following attach-network-interface command.

aws ec2 attach-network-interface \
    --network-interface-id eni-1234567890abcdef0 \
    --instance-id i-1234567890abcdef0 \
    --device-index 1

PowerShell

To attach a network interface

Use the Add-EC2NetworkInterface cmdlet.

Add-EC2NetworkInterface `
    -NetworkInterfaceId eni-1234567890abcdef0 `
    -InstanceId i-1234567890abcdef0 `
    -DeviceIndex 1

Detach a network interface

You can detach a secondary network interface that is attached to an EC2 instance at any time, using either the Instances or Network Interfaces page of the Amazon EC2 console.

If you try to detach a network interface that is attached to a resource from another service, such as an Elastic Load Balancing load balancer, a Lambda function, a WorkSpace, or a NAT gateway, you get an error that you do not have permission to access the resource. To find which service created the resource attached to a network interface, check the description of the network interface. If you delete the resource, then its network interface is deleted.

Console

To detach a network interface using the Instances page
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Instances.
  3. Select the checkbox for the instance. Check the Network interfaces section of the Networking tab to verify that the network interface is attached to an instance as a secondary network interface.
  4. Choose Actions, Networking,Detach network interface.
  5. Select the network interface and choose Detach.
To detach a network interface using the Network Interfaces page
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Network Interfaces.
  3. Select the checkbox for the network interface. Check the Instance details section of the Details tab to verify that the network interface is attached to an instance as a secondary network interface.
  4. Choose Actions, Detach.
  5. When prompted for confirmation, choose Detach.
  6. If the network interface fails to detach from the instance, choose Force detachment, Enable and then try again. We recommend that force detachment only as a last resort. Forcing a detachment can prevent you from attaching a different network interface on the same index until you restart the instance. It can also prevent the instance metadata from reflecting that the network interface was detached until you restart the instance.

AWS CLI

To detach a network interface

Use the following detach-network-interface command.

aws ec2 detach-network-interface --attachment-id eni-attach-016c93267131892c9

PowerShell

To detach a network interface

Use the Dismount-EC2NetworkInterface cmdlet.

Dismount-EC2NetworkInterface -AttachmentId eni-attach-016c93267131892c9