Change the vSwitch of an ECS instance (primary ENI)

更新时间:
复制 MD 格式

Change the vSwitch when the current vSwitch runs out of available IP addresses, or when you need to migrate an Elastic Compute Service (ECS) instance to a different CIDR block as part of a network architecture upgrade. With this feature, you can:

  • Move an instance's primary Elastic Network Interface (ENI) to a different vSwitch within the same virtual private cloud (VPC) and availability zone

  • Specify a new private IP address from the destination vSwitch's CIDR block, or have one assigned automatically

image

Potential impacts

Before proceeding, review the following impacts:

  • Service interruption: The instance must be stopped before you can change its vSwitch.

  • Private IP address change: The primary private IP address changes to a new address from the destination vSwitch's CIDR block. Any application or service that relies on the original IP address—such as database connection strings, firewall allowlists, or other service configurations—will stop working. Update those configurations after the change.

  • Public IP address: Remains unchanged.

  • Connectivity loss (static IP only): If the instance uses a static IP address, the internal network settings (IP address, subnet mask, and default gateway) will no longer match after the vSwitch change, preventing you from connecting to the instance. To avoid this, reconfigure the OS to use DHCP before changing the vSwitch.

  • Network ACL rules: If the source and destination vSwitches have different network ACL rules, review and update them to keep your applications working correctly.

  • Route configuration: If your application relies on specific routing rules, the new vSwitch may have a different routing configuration. Verify connectivity by associating a custom route table with the destination vSwitch and configuring the necessary route entries.

Prerequisites

Before you begin, ensure that you have:

Configure DHCP on a Linux instance

See Configure DHCP for a Linux instance.

Configure DHCP on a Windows instance

The following steps use Windows Server 2022 as an example.

  1. Connect to the Windows ECS instance.

  2. Open Network and Sharing Center.

  3. Click Change adapter settings.

  4. Double-click the primary ENI named Ethernet, then click Properties.

    Ethernet Status dialog

  5. In the Ethernet Properties dialog box, double-click Internet Protocol Version 4 (TCP/IPv4).

    Ethernet Properties dialog

  6. Select Obtain an IP address automatically, then click OK.

    image

Change the vSwitch

Console

  1. Go to the ECS console - Instances page. In the top navigation bar, select the target region and resource group.

  2. Click the ID of the instance whose vSwitch you want to change.

  3. On the instance details page, click All Actions > Network and Security Group > Change vSwitch in the upper-right corner.

  4. Select a destination vSwitch.

  5. Set the private IP address for the instance on the new vSwitch:

    • Specify an IP address: Enter an IP address within the destination vSwitch's CIDR block in the Private IP Address field. Use this option to minimize reconfiguration—for example, if you can allocate the same IP from the new subnet, downstream dependencies such as connection strings and allowlists do not need to change.

    • Auto-assign: Leave the Private IP Address field blank. An available address from the destination vSwitch's CIDR block is assigned automatically.

  6. Confirm the change.

After the change is complete, the new vSwitch appears in the Configuration Information section on the Instance Details page.

The instance does not start automatically after the vSwitch change. Start it manually.

API

Call ModifyInstanceVpcAttribute to change the vSwitch of an ECS instance's primary ENI.

To verify the change, call DescribeInstances and check the VSwitchId field in the response.

After the change, call StartInstance to start the instance.

FAQ

How do I convert between CIDR format and IP address ranges?

See Examples of converting CIDR blocks to IP address ranges. You can also run ipcalc on an instance in the destination vSwitch to view the IP address range directly.

How do I reconfigure secondary private IPv4 or IPv6 addresses after changing the vSwitch?

After the change, assign secondary private IPv4 and IPv6 addresses from the new vSwitch's CIDR block. See Assign a secondary private IP address to an ENI and Configure an IPv6 address.

What's next

References