# TCP Services

Source: https://tiltas.openpanel.sh/docs/services/tcp

> Give a database or any other TCP program its own name and address in your Network.

A **TCP Service** is for programs that are not websites: PostgreSQL, Redis, MySQL, a game server, an MQTT broker. It
gets a name and an address of its own, and each allowed Device connects to it like to any server on the internet, with
the program's usual client.

## Its name and its address

When you create a TCP Service, Tiltas gives it a **Service address** from `100.96.0.0/12`, such as `100.96.0.7`. Its
name resolves to that address on every Device that may open it:

| Use | Example |
|---|---|
| The short name and the port | `postgres:5432` |
| The full name | `postgres.zukai.ql.internal:5432` |
| The Service address | `100.96.0.7:5432` |

In **Services**, the row shows the Service address and port, with the name and port under it. The API returns them as
`address` and `short_url`.

The address belongs to the Service, not to the Device that runs it. Only Devices that may open the Service get a route
to it; to every other Device it does not exist. When a Service is deleted, its address is not given to a new Service for
24 hours, so no Device that still remembers it reaches something else.

## Create one

In the [console](/app), open **Services** and choose **Create Service**.

- **Kind**: **TCP**.
- **Runs on**: the Device the program runs on, such as `db-1`.
- **Service name**: such as `postgres`. Devices and Services share one list of names.
- **Target on db-1**: where the program listens, as seen from that Device, such as `localhost:5432`, or a computer on its
  LAN, such as `192.168.1.30:5432`. See [What a target can be](/docs/services/targets).
- **Ports**: the ports the Service answers on. Leave it empty to use the target's port.

Under **Who can open it**, choose who may connect, then choose **Create Service**. The Service address is shown in the
list as soon as it exists.

## Connect

From any allowed Device, use the name and the port:

```bash tab="PostgreSQL"
psql -h postgres -p 5432 -U postgres
```

```bash tab="Redis"
redis-cli -h redis -p 6379
```

```bash tab="MySQL"
mysql -h mysql -P 3306 -u root -p
```

In a connection string, the name works the same way, for example `postgres://app@postgres:5432/app`. Where a program
only takes an IP address, give it the Service address.

## Ports

- **Empty**: the Service answers on the target's port. `localhost:5432` gives a Service on port 5432.
- **One or more ports, with a target that has a port**: every connection, on any of those ports, goes to the target's
  port.
- **One or more ports, with a target without a port**, such as `localhost`: each connection keeps the port it was made
  to, so a game server on ports 27015 and 27016 needs one Service.

A TCP Service carries TCP only. Programs that need UDP are reached through an [Access rule](/docs/access) to the Device
instead.

## Who can open it

The same as for a Web Service: everyone in the Network, or chosen Members, Groups and Devices. Tiltas checks it twice:
the packet filter refuses other Devices, and the hosting Device checks again before it connects to the target.

The program behind a TCP Service sees connections coming from the hosting Device, not from the visitor, and gets no
identity headers. Use the program's own sign-in (a database user and password, for example) as you would anywhere.

## Health

The hosting Device checks that the target accepts a TCP connection within 2 seconds. See
[Health checks](/docs/services/health).
