Is it possible to change subnet in EC2 without terminating the instance?

0

Is it possible to change subnet in EC2 without terminating the instance?

bala
asked 11 days ago142 views
5 Answers
3

No. The primary elastic network interface (ENI) can't be detached from an instance or have its subnet or VPC changed. You can create a new ENI connected to a new subnet and attach it as a secondary interface, though, but the primary one would remain in the old subnet.

EXPERT
Leo K
answered 11 days ago
profile picture
EXPERT
reviewed 11 days ago
profile picture
EXPERT
reviewed 11 days ago
1

Hello,

You can't directly change the subnet for the instance. but you can do it with another option.

  • Stop the existing Instance.
  • Detach the EBS volume.
  • Create a new instance in required subnet and stop it.
  • Attach the EBS Volume to the new instance and start the new instance.
  • Finally terminate the old instance.
  • So, You can achieve that subnet change and your data is also recovered from EBS.

Thank you

profile picture
answered 11 days ago
1

Hi,

A solution to your case may be the multi-VPC ENI attachment for EC2 instance announced at the end of 2023.

See https://aws.amazon.com/about-aws/whats-new/2023/10/multi-vpc-eni-attachments/

You can attach your instance to a new VPC or subnet without destroying existing ENI first.

Best,

Didier

profile pictureAWS
EXPERT
answered 11 days ago
profile picture
EXPERT
reviewed 11 days ago
profile picture
EXPERT
A_J
reviewed 11 days ago
0

Hello

Changing the subnet of an existing EC2 instance without terminating it is not directly possible in AWS. However, you can achieve the desired outcome by following these steps to effectively move your instance to a new subnet:

Stop the Instance: You must stop the instance before making any changes to its network settings.

**Detach the Root EBS Volume: **Note the device name (e.g., /dev/sda1) of the root volume.

**Launch a New Instance in the Desired Subnet: **Create a new instance in the target subnet with the same AMI, instance type, and any other necessary settings.

Stop the New Instance: Once the new instance is running, stop it to allow volume modifications.

Detach the New Instance's Root Volume: Detach the root EBS volume from this new instance.

Attach the Original Root Volume: Attach the original root EBS volume from your old instance to the new instance, using the same device name.

Start the New Instance: Start the new instance. It should now boot up with the original instance's data and configurations, effectively placing it in the new subnet.

Additional Considerations: *** Elastic IPs:** If your instance uses an Elastic IP, you can reassign it to the new instance.

*** Security Groups:** Ensure the new instance has the appropriate security group settings.

  • Data Consistency: Verify that all data and configurations are intact after moving the root volume.
answered 11 days ago
0

While you cannot move EC2 to another subnet, you can create a AMI from source instance to manually migrate.

Please refer to How do I move my EC2 instance to another subnet, Availability Zone, or VPC?

AWS
EXPERT
Mike_L
answered 11 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions