Skip to content

How do I terminate my Amazon EC2 instance but retain its primary network interface?

3 minute read
0

I want to terminate my Amazon Elastic Compute Cloud (Amazon EC2) instance. However, I don’t want to delete the primary elastic network interface.

Resolution

Note: You can't detach a primary network interface from an EC2 instance that's in the Running or Stopped state. However, you can attach or detach the secondary network interface when the instance is Running or Stopped.

Identify the primary network interface

Complete the following steps:

  1. Open the Amazon EC2 console.
  2. In the navigation pane, choose Network Interfaces.
  3. Choose a network interface, and then choose Details.
  4. Under Network interface attachment, check the network card index. If the network card index is 0, then this is the primary network interface for the instance. For more information, see Network cards.

Update the instance's network interface settings

By default, Amazon EC2 deletes the primary network interface of any instance that you terminate.

To change the default setting, complete the following steps:

  1. Open the Amazon EC2 console.
  2. In the navigation pane, choose Instances, and then choose the instance that you want to terminate.
  3. Choose the Networking tab, and then choose the primary network interface.
  4. Choose Actions, and then select Change termination behavior.
  5. Clear Delete on instance termination.
  6. (Optional) Enter a name for the network interface.

Terminate the instance

Important: It's a best practice to back up your instance before you terminate it. After you terminate the instance, you can't access it again.

Terminate the instance. Amazon EC2 keeps the same configuration for the primary network interface, such as its private IP address, virtual private cloud (VPC), subnets, and security groups. You can use the primary network interface to launch a new instance with this configuration.

Note: If the primary network interface has a public IP address, then Amazon EC2 releases the IP address when you terminate the instance.

Use the network interface from your terminated instance as the primary network interface of a new instance

Launch a new instance and complete the following steps for Network settings:

  1. Choose Edit, and then select your network interface's VPC and subnet IDs for VPC and Subnet.
  2. For Auto-assign public IP, choose Disable.
    Note: You can set the Enable option only for new network interfaces. If your primary network interface had a public IP address, then Amazon EC2 assigns a public IP address to the instance after instance launch.
  3. For Firewall (security groups), choose Select existing security group. Don't specify a security group for Common security groups. The existing network interface uses the attached security group by default.
  4. Expand Advanced configuration, and then under Network interface, select your network interface.

Note: For a Windows Amazon Machine Image (AMI), make sure that you select large enough storage settings for your configuration. The default storage setting at instance launch is 30 GB for a GP3 volume. You can change settings, such as Volume size and Type, based on your requirements.

Related information

Elastic network interfaces

AWS OFFICIALUpdated 4 months ago