# How to Create a Router

Source: https://docs.quake.ai/docs/network/how-to/create-router
Markdown: https://docs.quake.ai/docs/network/how-to/create-router.md

---

# How to create a router

Create a router to connect a private network to an external network. Routers enable instances on private subnets to reach the internet and allow floating IP addresses to route traffic to your instances.

<PrerequisiteBlock methods={["console", "cli", "api", "terraform"]}>

You need an existing [network and subnet](/docs/network/how-to/create-network) to connect the router to.

</PrerequisiteBlock>

## Create the router

<MethodTabs>
<Method label="Console">

Each router row on the **Network** > **Routers** list exposes two per-row icons in the Action column:

| Icon | Tooltip | Dropdown items |
|---|---|---|
| Chain | `Networking` | `Connect Private Network`, `Disconnect Private Network`, `Detach Public Network` |
| Gear | `Settings` | `Edit` |

There is no `More` button on the Routers list; subnet attach and detach actions live behind the `Networking` icon. To delete a router, use the top-level **Delete** button (not a per-row icon item).

1. Select **Network** > **Routers** > **Create Router**.
2. Name the router and provide a description.
3. Optionally select a subnet to attach the router to.
4. **Attach to Public Network** is selected by default, with `PublicStatic` preselected in the required **Public Network** field beneath it. Leave it selected to give the router an external gateway, or clear it if you do not want one.
5. Select **OK**.

After creation, connect the router to your private subnet:

1. Find the router in the **Routers** list.
2. On the router's row, click the **Networking** icon and select **Connect Private Network**.
3. Select your network and subnet row from the list.
4. Select **OK**.

</Method>
<Method label="CLI">

Create the router with an external gateway:

```bash
openstack router create my-router
```

Set the external gateway to `PublicStatic`:

```bash
openstack router set --external-gateway PublicStatic my-router
```

Connect the router to your private subnet:

```bash
openstack router add subnet my-router my-subnet
```



You can create the router and set the gateway in one command:
`openstack router create --external-gateway PublicStatic my-router`



</Method>
<Method label="API">

Create the router with an external gateway:

```bash
curl -X POST "$OS_NETWORK_URL/v2.0/routers" \
  -H "X-Auth-Token: $OS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "router": {
      "name": "my-router",
      "admin_state_up": true,
      "external_gateway_info": {
        "network_id": "PUBLIC_STATIC_NETWORK_ID"
      }
    }
  }'
```

Add your subnet as a router interface:

```bash
curl -X PUT "$OS_NETWORK_URL/v2.0/routers/ROUTER_ID/add_router_interface" \
  -H "X-Auth-Token: $OS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "subnet_id": "SUBNET_ID"
  }'
```




```python
import openstack

conn = openstack.connect(cloud="rumble")

router = conn.network.create_router(
    name="my-router",
    external_gateway_info={"network_id": "PUBLIC_STATIC_NETWORK_ID"},
)

conn.network.add_interface_to_router(router, subnet_id="SUBNET_ID")
print(f"Router: {router.id}")
```




</Method>
<Method label="Terraform">

```hcl
data "openstack_networking_network_v2" "public" {
  name = "PublicStatic"
}

resource "openstack_networking_router_v2" "my_router" {
  name                = "my-router"
  admin_state_up      = true
  external_network_id = data.openstack_networking_network_v2.public.id
}

resource "openstack_networking_router_interface_v2" "my_router_iface" {
  router_id = openstack_networking_router_v2.my_router.id
  subnet_id = openstack_networking_subnet_v2.my_subnet.id
}
```

See the [simple VM template](/resources/iac-templates/simple-vm) for a complete example that includes network, subnet, router, and instance resources.

</Method>
</MethodTabs>

## Verify the result

<MethodTabs>
<Method label="Console">

Navigate to **Network** > **Routers**. The router row shows **Public Network Attached** as `Yes` and the external network's UUID in the **Public Network** column. Open the router's detail page to see the human-readable external network name (`PublicStatic`) under **External Network Info**, and open the **Ports** tab to confirm a router-interface port exists on your private subnet's IP range.

</Method>
<Method label="CLI">

```bash
openstack router show my-router
```

Confirm `external_gateway_info` shows the `PublicStatic` network and `interfaces_info` includes your subnet.

</Method>
<Method label="API">

```bash
curl -s "$OS_NETWORK_URL/v2.0/routers?name=my-router" \
  -H "X-Auth-Token: $OS_TOKEN" | python3 -m json.tool
```

</Method>
<Method label="Terraform">

```bash
tofu show
```

</Method>
</MethodTabs>

## See also

- [Network API Reference](/reference/network): full parameter documentation for the Network API
- [Network CLI reference](/reference/network/cli)
- [Network API reference](/reference/network/api)
- [Routers console](/reference/network/console/routers)
- [How to create a network](/docs/network/how-to/create-network)
- [How to allocate floating IPs](/docs/network/how-to/allocate-floating-ips)
