# Requirements

> A Linux server with Docker, four DNS hostnames pointing at it, and a few ports open. What a small community needs, IPv6, and what NAT means for voice.

## The server

- **Linux** with **Docker Engine 24 or later** and the **Compose plugin 2.24 or later**
  (`docker compose version`). Any 64-bit machine should work, x86 or ARM: a VPS, an ARM server, a
  mini PC at home. The published images are `linux/amd64` and `linux/arm64`, and Docker pulls
  the one for your machine. 32-bit systems (`armv7`) aren’t supported.
- **A Raspberry Pi 4 or 5** with a 64-bit system and 4 GB of RAM should run it. We haven’t
  tested it on real hardware yet: the `arm64` images were only tried emulated.
- **For a small community** (a few dozen people, some in voice at once): 2 CPU cores, 4 GB of
  RAM and 20 GB of disk, plus what people upload. Idle, the whole stack uses about 0.8 GB of RAM
  on an x86 machine, nearly half of it the S3 store. Calls and screen sharing use CPU and
  bandwidth while they last.
- **Building the images yourself** (instead of pulling them) needs more: about 4 GB of free RAM
  and 10 GB of disk while it builds. On a small ARM board, pull them: building there is slow.
- **Bandwidth** is what grows with use: every screen share or camera is sent to each person
  watching it. The [limits](https://docs.klang.gg/self-hosting/configuration/#limits) cap it.

## Four hostnames

Klang uses four DNS hostnames, all pointing at the server with `A` records (IPv4). Add `AAAA`
records only once IPv6 works in Docker’s network ([IPv6](https://docs.klang.gg/self-hosting/requirements/#ipv6), below).

| Hostname        | Example                  | What it serves                                  |
| --------------- | ------------------------ | ----------------------------------------------- |
| The app         | `chat.example.org`       | The web, its API and the two gateways           |
| The staff panel | `admin.chat.example.org` | The panel, on its own origin                    |
| Files           | `files.chat.example.org` | Attachments, avatars and emojis                 |
| Voice           | `voice.chat.example.org` | LiveKit’s signalling (voice, video and screens) |

Files and the panel live on their own hostnames on purpose. A file someone uploads is never
served from the app’s origin, and a problem in the app can’t reach the panel. Don’t use one
hostname for two of them.

## Ports

Open these in the server’s firewall (and forward them in your router if it’s at home):

| Port | Protocol | What for                                                           |
| ---- | -------- | ------------------------------------------------------------------ |
| 80   | TCP      | Let’s Encrypt’s check, and the redirect to HTTPS                   |
| 443  | TCP      | Everything over HTTPS: the app, the panel, files, voice signalling |
| 443  | UDP      | HTTP/3 (optional, faster on bad networks)                          |
| 7881 | TCP      | Voice and video when UDP is blocked                                |
| 7882 | UDP      | Voice and video: every call goes through this one port             |
| 3478 | UDP      | TURN, the relay for people behind strict NATs                      |

If another proxy already holds 80 and 443 on the machine, see
[Behind your own reverse proxy](https://docs.klang.gg/self-hosting/reverse-proxy/).

Nothing else is published: Postgres, Valkey and the S3 store are only reachable inside Docker’s
network. Don’t publish their ports.

The three voice ports can be changed in `.env` (`LIVEKIT_TCP_PORT`, `LIVEKIT_UDP_PORT`,
`LIVEKIT_TURN_PORT`), and they’re the same number inside and outside: LiveKit tells browsers the
port it listens on.

## IPv6

The kit’s Docker network is IPv4 only. If your hostnames have `AAAA` records anyway, Docker
still accepts the IPv6 connections, but it hands them to Caddy from its own address. Klang then
sees every visitor over IPv6 as one person: they share the rate limits, and the checks on new
accounts after a ban look at that one address.

So either leave the `AAAA` records out, or turn on IPv6 in the kit’s network. With **Docker
Engine 27 or later** it needs no change to Docker’s own configuration. Put this in
`selfhost/compose.override.yml` (Compose reads it by itself, and git ignores it):

```yaml
networks:
  default:
    enable_ipv6: true
```

Then recreate the network with `docker compose down` and `docker compose up -d` (without
`-v`: the data stays). Docker gives the network a private IPv6 range, and Caddy sees each
client’s real address. On an older Engine, update Docker first. We’ve checked that the network
comes up with IPv6 on Engine 29; we haven’t tested real IPv6 clients against it.

## NAT and the public IP

LiveKit has to tell browsers an address they can reach. By default it asks a STUN server for the
machine’s public IP (`LIVEKIT_USE_EXTERNAL_IP=true`), which works on a VPS and behind a home
router with the ports forwarded.

- If it can’t find it, or finds the wrong one, set it yourself: `LIVEKIT_USE_EXTERNAL_IP=false`
  and `LIVEKIT_NODE_IP=<the public IP>`.
- **Without a public IP of your own** (your provider puts you behind CGNAT), people outside your
  network can chat but can’t join calls. Use a VPS.
- People on the **same network as the server** reach it through its public IP: your router has
  to support NAT loopback (hairpin), or their calls won’t connect. The server itself doesn’t
  need it: inside Docker, the four hostnames point straight at Caddy.

## Portainer, Unraid, TrueNAS

The kit expects the whole repository on disk. Its compose file mounts files next to it (the
Caddyfile, `s3-init.sh`) and builds the store’s image from a short Dockerfile. A compose file
pasted into a web form, alone, won’t start. In Portainer, create the stack from the Git
repository (`selfhost/docker-compose.yml` at the release’s tag) and give it the variables of
`.env`. On other systems, clone the repository on the machine and run `docker compose` there.
