---
title: "Public IP address in a ClickHouse® cluster"
sidebar_label: "Public IP address"
sidebar_position: 16
description: "How to connect a public IP address to a shard of a ClickHouse® cluster"
---

import TrashIcon from '@selectel/docux/icons/trash'
import EditIcon from '@selectel/docux/icons/edit'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import Link from '@docusaurus/Link'
import Formbricks from '@theme/MDXComponents/Formbricks'

# Public IP address in a ClickHouse® cluster

A public IP address is a static public IP address that is assigned to a node to set up access to it in a private network from the internet. External traffic goes through the public IP address and is processed by a cloud router that performs the 1:1 NAT function.

The private subnet where a public IP address can be assigned must comply with the [requirements](#requirements) — before adding a public IP address, [prepare the subnet](#configure-subnet).

A public IP address can be assigned:

* when [creating a cluster](/managed-databases/clickhouse/create-cluster.mdx) in an existing private subnet;
* or in an [existing cluster](#assign-public-ip-in-existing-cluster).

In a ClickHouse® cluster, public IP addresses are connected to all shard nodes simultaneously. Each shard node has a separate public IP address. If you add a node to a shard where all nodes already have IP addresses, the new node will also be assigned a public IP address.

If necessary, you can [detach a public IP address](#detach-public-ip) for the entire shard.

## Requirements for a private subnet \{#requirements}

* The subnet must have a cloud router with internet access;
* The cloud router IP address must be the default gateway in the subnet.

If the subnet does not meet the requirements, [prepare it for connecting a public IP address](#configure-subnet).

## Prepare a private subnet for connecting a public IP address \{#configure-subnet}

1. [Create a cloud router with internet access](#create-cloud-router).
2. [Connect the private network to the cloud router](#connect-private-network-to-cloud-router).

### 1. Create a cloud router with internet access \{#create-cloud-router}

A cloud router allows you to route traffic between private networks.

The router can be used to set up internet access from a private network or to access a device in a private subnet from the internet via a public IP address.

1. In the [Control panel](https://my.selectel.ru/vpc/default/routers/), on the top menu, click **Products** and select **Cloud Servers**.
2. Go to the **Network** section → **Cloud Routers** tab.
3. Click **Create Router**.
4. Select the [location](/infrastructure/locations.mdx) where the cloud router will be created.
5. Enter the router name.
6. Select the **Connect router to internet** checkbox — an external IP address will be allocated for the router.
7. Click **Create**.

### 2. Connect a private network to the cloud router \{#connect-private-network-to-cloud-router}

1. In the [Control panel](https://my.selectel.ru/vpc/default/routers/), on the top menu, click **Products** and select **Cloud Servers**.
2. Go to the **Network** section → **Cloud Routers** tab.
3. Open the router card.
4. Click **Add subnet**.
5. Select a private subnet.
6. Optional: enter the router IP address. If you do not specify an IP address, it will be automatically selected from the available subnet addresses. The cloud router IP address must match the default gateway of the private subnet. The gateway can be viewed in the [control panel](https://my.selectel.ru/vpc/default/networks/): in the top menu, click **Products** → **Cloud Servers** → **Network** → the **Private Networks** tab → network page → the **Subnets** tab → subnet card → the **Automatic network settings** block → the **Subnet gateway**.
7. Click **Add subnet**.

## Connect a public IP address \{#assign-public-ip-in-existing-cluster}

Public IP addresses connect to all shard nodes simultaneously. Each shard node has a separate public IP address.

1. Ensure that the cluster is in a private subnet that complies with the [requirements](#requirements).
2. In the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), on the top menu, click **Products** and select **Managed Databases**.
3. Open the **Active** tab.
4. Open the database cluster page → tab **Settings**.
5. In the shard card, in the **Public access** row, click .<EditIcon />
6. Click **Connect**.

## Detach a public IP address \{#detach-public-ip}

Public IP addresses are detached from all nodes of a shard simultaneously.

1. In the [Control panel](https://my.selectel.ru/vpc/default/dbaas/), in the top menu click **Products** and select **Cloud Databases**.
2. Open the **Active** tab.
3. Open the database cluster page → **Settings** tab.
4. In the shard card, in the **Public access** row, click .<EditIcon />
5. Click **Disable**.

ClickHouse® is a registered trademark of ClickHouse, Inc. https://clickhouse.com.

<Formbricks />
