# Attaching a server to a private network and detaching it

https://www.gyrohosting.com/en/knowledgebase/article/gyro-cloud-istanbul-attach-server-private-network

- **What you will learn**: How to add a private network card to a running server, verify the private IP and detach the card.
- **Time**: 6 minutes
- **Who is it for**: Sysadmins and developers.
- **What you need**: A VPC and subnet ([creation guide](https://www.gyrohosting.com/en/knowledgebase/article/gyro-cloud-istanbul-create-vpc-subnet)) and a Gyro Cloud Istanbul server.

## 1. Attaching from the panel

You **do not need to shut the server down**; a new network card is added to it.

1. Open **My Services →** your server → the **Private network (VPC)** tool (or **Gyro Console → Private networks (VPC)**).
2. Choose **Attach to private network**; select the **VPC** and **subnet**. The **IP** is assigned automatically (first free address) or you can enter one (for example `10.10.2.10`).
3. Click **Attach**. The card state goes `attaching` → `ready`; this usually takes 30-60 seconds.
4. Verify on the server: `ip -br addr` shows the private IP on the new card.

> **Info**
> 
> The Gyro guest agent configures the private IP on the server; it is present on newly created servers. On older servers or ones created from your own image the card is attached but the IP is not configured automatically; apply the setting shown in the panel by hand.

## 2. Detaching

In the **Private network (VPC)** tool choose **Remove** on the card's row. The card is removed from the server and the IP is held for a short time before it becomes free.

## 3. Command line, API, Terraform

```
gyro server nic list 12345
gyro server nic attach 12345 --subnet-id <subnet-id> [--ip 10.10.2.10]
gyro server nic detach 12345 <nic-id>
```

API (the operation returns 202; it is complete when the card is `ready`):

```
curl -X POST https://www.gyrohosting.com/api/v1/client/cloud/servers/12345/nics \
  -H "Authorization: Bearer $GYRO_TOKEN" -H "Content-Type: application/json" \
  -d '{"subnet_id":"<subnet-id>","ip":"10.10.2.10"}'
curl -X DELETE https://www.gyrohosting.com/api/v1/client/cloud/servers/12345/nics/<nic-id> \
  -H "Authorization: Bearer $GYRO_TOKEN"
```

Terraform:

```
resource "gyro_server_nic" "web_db" {
  server_id = gyro_server.web.id
  subnet_id = gyro_subnet.database.id
}
```

The resource waits until the card is `ready` (at most 5 minutes).

## 4. Good to know

- **Do not change the private IP from inside the server**; it is assigned from the panel. Packets sent with a wrong IP are dropped in the network.
- The card name varies by distribution (`ens224`, `eth1` …); the card is recognised by its MAC address and configured at every boot.
- At most **3** private NICs per server; a server can join **one VPC** at a time (with several cards in different subnets of that VPC).
- The **web console** on the service page works independently of the network and is always available.
- If you reinstall the operating system the cards are attached again; IPs stay the same.

## 5. Frequently asked questions

**What do already_attached and other_vpc mean?**

The server is already attached to that subnet, or to another VPC. A server can join only one VPC at a time.

**What do ip_in_use and subnet_full mean?**

The IP you asked for belongs to another server, or the subnet is full. Pick another IP or subnet.

**Is the IP given to someone else right after I remove the card?**

No, a removed IP is held for a short time.

## Next step

- [Turning off the public IP](https://www.gyrohosting.com/en/knowledgebase/article/gyro-cloud-istanbul-turn-off-public-ip)
- [VPC gateway: internet egress and port forwarding](https://www.gyrohosting.com/en/knowledgebase/article/gyro-cloud-istanbul-vpc-gateway-nat)
