# Move an instance to another network

Move a running or stopped instance to another VPC or subnet in place, and see beforehand what the move interrupts.

Replace _i-3f9a2c07_ with your instance's id and _6f1c2b8e-4a5d-4e7f-9b0c-1d2e3f4a5b6c_ with the id of the VPC it moves to.
The instance keeps running and keeps its public address, Elastic IP, volumes and disk. What
changes is its private address: the old one stops answering.

## Prerequisites

- Permission for `ec2:ModifyInstanceNetwork` (it counts as a destructive action: the old private
  address stops answering).
- In the console, also `ec2:DescribeInstances` to open the instance's page (without it the page is
  not found).
- The target VPC is in the instance's region and `available`. A subnet you name is in that VPC and
  in the instance's zone.
- The instance runs on a provider machine. A machine another service runs is refused with `409`
  and says which one to change instead: a Kubernetes node (its network is the cluster's), the
  machine of an app, or a member of an auto scaling group (change the group's subnets).

## What the move interrupts

| The two networks                                       | Order                                                                         | Private address                                                    |
| ------------------------------------------------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| Ranges that do not overlap (10.0.0.0/16, 10.20.0.0/16) | joins the new one, waits until the new address is up, then leaves the old one | the old one stays until the new one is up; about 35 seconds in all |
| Overlapping ranges, or another subnet of the same VPC  | leaves first, then joins                                                      | none for about 16 seconds                                          |

When the new interface appears, the operating system renews every address, so public traffic
pauses for about 150 ms. Every VPC is created as 10.0.0.0/16 unless you choose another
range, so two networks you made with the defaults overlap. Your security groups stay attached;
they filter public traffic only, so traffic inside the new VPC is not filtered by them.

Before you move, read the plan: it names the order, the new address and what depends on the
old network, such as a load balancer that sends to the instance's private address or a database
it reaches privately.

## Move

**Console**
1. Open the instance, then choose **Networking**.
2. Choose **Change network**.
3. For **VPC**, choose the network. The current one is marked; networks of another region or not
   ready yet are greyed with the reason. **Create network** makes one in place.
4. Optionally, for **Subnet**, choose a subnet. Without one an address anywhere in the VPC is
   chosen.
5. Read **What happens**: the interruption, the new address and what depends on the old network.
6. Choose **Move instance**. **Network changes** on the same tab shows each step as it happens.

To move several instances into one network, open the network, choose **Resources**, then **Move
instances here**, and select them; each shows its own plan.

**CLI**
```sh
dcloud ec2 instances network-move-plan i-3f9a2c07 --vpc-id 6f1c2b8e-4a5d-4e7f-9b0c-1d2e3f4a5b6c
dcloud ec2 instances change-network i-3f9a2c07 --vpc-id 6f1c2b8e-4a5d-4e7f-9b0c-1d2e3f4a5b6c
dcloud ec2 instances events i-3f9a2c07
```

**API**
```http
GET /ec2/api/instances/i-3f9a2c07/network-move-plan?vpcId=6f1c2b8e-4a5d-4e7f-9b0c-1d2e3f4a5b6c
```

```http
POST /ec2/api/instances/i-3f9a2c07/actions/change-network
{ "vpcId": "6f1c2b8e-4a5d-4e7f-9b0c-1d2e3f4a5b6c" }
```

The move answers `202` with the plan and the address chosen. Add `subnetId`, or `privateIp` to
take a given free address.

**Terraform**
Change `vpc_id` (and `subnet_id`) on the `dcloud_instance` and run `terraform apply`. The instance
is moved in place, not replaced, and `private_ip` shows the new address.

## Result

The instance's **Networking** tab, and `GET …/events`, show each step with how long it took, for
example "Joined app-net in 6.2 s", "Left default (10.0.0.7) in 5.1 s" and "Moved from default to
app-net". If the instance joined the new network but could not leave the old one, it stays in
both and says so; ask for the same move again to retry. If it could not join, nothing changed and
the reason is shown.

Instances launched before 24 November 2026 route the private ranges of a site-to-site VPN through
the network they were launched in. The plan shows one line to run on such an instance after the
move; a reboot does not fix it.

## Related

- [Networks and addresses](networks-and-addresses.md) · [Create a network](create-a-network.md)
- `ec2.instances.change-network` · `dcloud ec2 instances change-network` · `dcloud_instance`
