Change the vSwitch for an Elastic Compute Service (ECS) instance if the current vSwitch runs out of available IP addresses, or if you need to migrate the instance to a new network segment as part of a network architecture upgrade. This feature lets you move an ECS instance's primary Elastic Network Interface (ENI) to another vSwitch within the same virtual private cloud (VPC) and availability zone.
Impacts and risks
Service interruption: This operation requires you to stop the instance, which interrupts services.
Private IP address change:
The primary private IP address of the instance changes to a new address from the CIDR block of the destination vSwitch. You can specify the new IP address or have one automatically assigned. Applications or services that use the original hard-coded private IP address, such as database connection strings, firewall whitelists, and other service configurations, will fail. You must manually update them after the change.
The public IP address remains unchanged.
Loss of network connectivity: If the instance uses a static IP address, the internal network settings (such as its IP address and gateway) will not match the newly assigned ones after the vSwitch change. This mismatch prevents you from connecting to the instance.
Access control: If the source and destination vSwitches have different network ACL rules, review and adjust them are needed to ensure your applications function correctly.
Route configuration: If your application relies on specific routing rules, the new vSwitch may have a different routing configuration. Ensure connectivity by associating a custom route table with a vSwitch and configuring the necessary route entries.
Procedure
Step 1: Prepare for the change
Stop the instance
If the instance is running, stop it. Ensure the instance is not in the status of Locked.
Perequisite checks
Multiple private IP addresses: If the primary ENI is assigned any secondary private IPv4 or IPv6 addresses, you must first unassign the secondary private IP addresses or delete the assigned IPv6 addresses.
(Optional) Configure the OS to use DHCP: If your instance uses a static IP address, reconfigure its OS to use DHCP (Dynamic Host Configuration Protocol) before changing the vSwitch. This lets the instance automatically get IP address, subnet mask, and default gateway.
Linux
For information, see Configure DHCP for a Linux instance.
Windows
The following steps use Windows Server 2022 as an example:
Connect to the Windows ECS instance.
For more information, see Use Workbench to connect to a Windows instance over RDP.
Open Network and Sharing Center.
Click Change adapter settings.
Double-click the primary ENI named Ethernet. Then, click Properties in the Ethernet Status dialog box.

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

In the Internet Protocol Version 4 (TCP/IPv4) Properties dialog box, select Obtain an IP address automatically.

Step 2: Change the vSwitch
Console
Go to ECS console - Instances page. In the top navigation bar, select the target region and resource group.
Find the instance whose vSwitch you want to change and click the instance ID.
On the instance details page, click All Actions > in the upper-right corner.
Change the vSwitch:
Select a destination vSwitch.
(Optional) Specify the Private IP Address. The private IP address must be within the CIDR block of the destination vSwitch.
If you do not set this parameter, an available primary private IP address is automatically assigned.
Once the change is complete, you can view the new vSwitch in the Configuration Information section on the Instance Details page.
The instance does not start automatically after the vSwitch change. You must start it manually.
API
Call the ModifyInstanceVpcAttribute operation to change the vSwitch of an ECS instance's primary ENI.
After the change is complete, call the DescribeInstances operation and check the VSwitchId in the response to view the new vSwitch of the instance.
After you change the vSwitch, the instance does not start automatically. You must call the StartInstance operation to start it manually.
FAQ
How do I convert between CIDR format and IP address ranges?
Refer to Examples of converting CIDR blocks to IP address ranges. You can also use the
ipcalcon an instance in the destination VPC's vSwitch to view the IP address range.How do I reconfigure secondary private IPv4 or IPv6 addresses for an instance after changing its vSwitch?
After changing the vSwitch, you can reconfigure secondary private IPv4 and IPv6 addresses from the new vSwitch's CIDR block. For more information, see Assign a secondary private IP address to an ENI and Configure an IPv6 address.
References
To interconnect ECS instances across different accounts or VPCs, you can use a VPC peering connection or Cloud Enterprise Network (CEN).
To migrate an ECS instance to another zone in the same region, see Cross-zone migration.
To migrate an ECS instance to another account or region for purposes such as cost optimization, disaster recovery, or addressing resource constraints, refer to Migrate data between ECS instances that belong to the same Alibaba Cloud account or different Alibaba Cloud accounts.