Tunnel (port forwarding)
KRZN Live includes an embedded frp client, which exposes the server on the Internet through a frp server (frps) running on a machine with a public IP, like a VPS. No ports need to be opened or forwarded on the router of the machine running KRZN Live, and no separate frpc executable is needed.
Each service is exposed on the frp server with the same port number it has locally. For instance, the RTSP server, listening on port 8554, becomes reachable at rtsp://frp-server-address:8554/mystream.
Configure the frp server
On the public machine, download frp from the Releases page, create a frps.toml file:
bindPort = 7000
auth.token = "a-long-random-secret"
# ports that clients are allowed to expose
allowPorts = [
{ single = 8554 },
{ single = 1935 },
{ start = 8888, end = 8893 },
{ single = 8189 },
]
And launch the server:
./frps -c frps.toml
Make sure that the firewall of the public machine allows incoming connections to port 7000 (TCP) and to the exposed ports: 8554, 1935, 8888, 8889, 8892 (TCP) and 8189, 8890, 8892, 8893 (UDP).
Enable the tunnel
In krznlive.yml, fill the tunnel settings:
tunnel: true
tunnelServerAddress: frp-server-address
tunnelServerPort: 7000
tunnelToken: a-long-random-secret
tunnelServices: [rtsp, rtmp, hls, webrtc, srt, moq]
When KRZN Live starts, the tunnel connects to the frp server and keeps reconnecting if the connection is lost. Changes to these settings are applied without restarting the server.
Available services are rtsp, rtmp, hls, webrtc, srt, moq, playback, api, metrics and pprof. Services that are disabled in the configuration are skipped.
Stability
- The tunnel keeps 5 connections to the frp server open in advance, so new viewers don't wait for a round trip to the VPS, and detects dead connections within seconds.
- Every 30 seconds, every TCP service is tested end to end through the VPS, by talking its protocol (an RTSP request, an RTMP handshake, an HTTP request that must be answered by this server). The result is shown in the dashboard. When no service answers for 90 seconds, the tunnel restarts itself.
- WebRTC media normally uses UDP, which a tunnel carries less reliably. Set
webrtcLocalTCPAddress: :8189to also offer WebRTC over TCP: the port is exposed through the tunnel too, and browsers fall back to it when UDP doesn't work. - On lossy connections,
tunnelProtocol: quicorkcpcan be more stable thantcp. The same protocol must be enabled on the frp server (quicBindPortorkcpBindPortinfrps.toml).
Security
Once the tunnel is enabled, anyone who can reach the frp server can reach the exposed services. The default configuration allows anyone to publish and read streams, therefore configure authentication before enabling the tunnel.
Connections that come through the tunnel reach the server from 127.0.0.1. Therefore, permissions that are restricted by IP to localhost (ips: ["127.0.0.1", "::1"]), like the ones that the default configuration grants for the Control API, metrics and pprof, apply to anyone on the Internet. Do not expose api, metrics or pprof unless they are protected by a username and password, since the Control API allows to change the configuration and to run external commands.
The tunnel token is hidden in the output of the Control API.
Protocol notes
- RTSP: only the TCP transport is tunneled. Clients must use RTSP over TCP (for instance,
-rtsp_transport tcpwith FFmpeg). - WebRTC: when
webrtcis exposed, the frp server address is automatically added towebrtcAdditionalHosts, so that WebRTC clients connect to the frp server. Media flows through the UDP port 8189. - SRT and MoQ: UDP ports are tunneled, but a UDP tunnel adds latency and may lose packets more often than a direct connection.