gately

module
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: Apache-2.0

README

Gately

English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español | Français | Deutsch | Русский | Português (Brasil)

An open-source, auditable network gateway toolkit for home networks, NAS boxes, cloud hosts, and servers of all kinds. Inspired by Lucky, it offers the same class of features in a fully open-source form. DDNS, STUN traversal, port forwarding, reverse proxy, certificates, WAF, and more ship in a single ~22 MB file, and your Lucky configuration imports with one click.

Gately overview

Why Gately

Lucky is a well-loved tool among NAS and home-network users in China. It brings DDNS, STUN traversal, reverse proxy, and more together in one place, and it gave Gately its product direction; without Lucky there would be no Gately. Lucky is distributed free of charge as closed-source software, while Gately is fully open source, so users and the community can read the source and the configuration directly. For software that sits on your network edge and holds your DNS keys and certificate private keys, open source lets you see exactly what it does. Gately's commitments:

  • The source is released under Apache-2.0 and open to community review
  • No connections to any project-operated server by default and no device information reported; third-party sign-in uses your own OAuth apps, with no relay in between
  • Every outbound address (public IP lookup, STUN servers, and so on) is visible, editable, and can be turned off
  • Configuration is plain-text JSON, so you can put it under git for auditing and rollback

Features

Module Capabilities
Dynamic DNS Alibaba Cloud, Cloudflare, Tencent Cloud, DNSPod, Huawei Cloud, GoDaddy, Porkbun, dynv6, DuckDNS, custom callbacks; IP discovery via URL, network interface, or command; IPv4/IPv6; webhooks
STUN traversal TCP/UDP, keep-alive, UPnP/NAT-PMP, built-in forwarding, webhooks and scripts triggered on address change
Port forwarding TCP/UDP, IPv4/IPv6, port ranges, multi-target failover, connection limits, traffic statistics
SSL certificates Automatic ACME DNS-01 issuance and renewal (wildcard, EAB), upload, read from file, map to a directory and run a script
Tailscale Managed tailscaled (userspace networking, container-friendly) or attach to an existing system daemon; auth keys / login links, Headscale, subnet routes, exit nodes, peer list and SOCKS5 proxy, fixed port, extra tailscaled arguments and environment variables
frp frpc client (tcp/udp/http/https/stcp/xtcp proxies, changes apply instantly) and frps server (port allowlist, subdomains, dashboard); one-click import of legacy ini and new toml configs
Cloudflare Tunnel cloudflared token tunnels and trycloudflare quick tunnels, multiple tunnels, automatic restart, public address display
Web services Per-domain reverse proxy / redirect / static files / fixed text; HTTPS; WebSocket; PROXY protocol in and out; basic auth, web auth, GitHub/Google/QQ/OIDC sign-in; IP allow/deny lists, path rules, temporary share links, automatic ban on failed auth, GeoIP country filtering; backend weights / standby / load-balancing policies, active and passive health checks, compression, rate limiting, response caching, path rewriting; per-minute access statistics and Prometheus metrics
WAF Coraza + OWASP CRS v4, per-file rule toggles, custom SecLang, block or detection-only mode
Docker management Create and edit containers, logs and terminal, Compose, image update checks with one-click upgrade (automatic rollback on failure), networks and volumes
Web terminal SSH (trust host key on first use), Telnet, local shell (off by default); proxies, persistent sessions, SFTP file manager, 2FA and protocol confirmation, quick commands, split panes
Network diagnostics Ping, traceroute, port probe, DNS lookup, speed test, LAN scan
Notification center Webhook, Telegram, Bark, WeCom, DingTalk, Feishu, email; severity levels, wildcard, and silencing / dedup rules
Config backup Encrypted backups (scrypt + AES-GCM), retention policy, scheduled backups to a local directory or storage mount
CLI and MCP gately ctl talks to a running instance; gately mcp serves MCP over stdio (read-only by default)
Wake-on-LAN Magic packet broadcast, online detection
WebDAV Multiple users, per-user directories, read-only mode
FTP Multiple users, per-user directories, read-only mode, FTPS and passive port ranges
Storage management Local directories and remote WebDAV mounts, online file manager
Scheduled tasks Cron expressions, commands or HTTP requests, run history
Security and settings Two-factor authentication (TOTP), login rate limiting, secure entry path, LAN-only access, HTTPS for the admin UI, multiple API tokens (per-module read/write grants), custom DNS (DoH supported), time zone, config backup and restore
Migration Import a Lucky .lkcf file or a full-site config zip: port forwarding, DDNS, STUN, certificates, reverse proxy, WAF, Wake-on-LAN, web terminal, WebDAV, basic settings

Quick Start

Docker

Images are available for amd64, arm64, and arm/v7:

docker run -d --name gately --network host \
  -v ./gately-data:/etc/gately \
  -v /var/run/docker.sock:/var/run/docker.sock \
  ghcr.io/wangwanjie/gately:latest
docker logs gately 2>&1 | grep -i "initial password"

Open http://<device-ip>:16680 and sign in as admin with the initial password from the log. Then change the password and enable two-factor authentication under Settings. See deploy/docker-compose.yml for a complete Compose example.

Port forwarding, STUN, and web services listen on host ports, so --network host is recommended. If you do not need Docker management, drop the docker.sock mount.

Binary

Download the archive for your platform from Releases (Linux amd64/arm64/arm/mips/mipsle/riscv64, macOS, Windows, FreeBSD), extract it, and run:

./gately -c /etc/gately

Flags: -c sets the config directory (the GATELY_CONFIG_DIR environment variable also works), -listen overrides the admin UI listen address, and -version prints the version.

API usage

Create a token on the "API Tokens" page of the admin console. You can create several, grant each read-only or read-write access per module, set an expiry, and the plaintext is shown only once, right after creation. Scripts can then call the admin API in bulk:

curl -H "Authorization: Bearer gtl_xxxx" http://localhost:16680/api/ddns/tasks

Account, two-factor authentication, and token management, as well as the backup, restore, restart, and system settings endpoints, accept login sessions only. All endpoints, required permissions, and data schemas are listed on the "API Docs" page of the admin console. You can also export them to docs/api/en (openapi.json and API.md) with make api-docs; the website https://gately.cn references them directly when published.

When upgrading from an older version, the previous global API token becomes a "legacy token" automatically (same value, full access to every module). Tighten its permissions or replace it with a new token on the API Tokens page.

Tailscale, frp, cloudflared

These three modules manage the official external programs (automatic restart, logs aggregated in the UI). Gately does not bundle them, so you can always run the latest upstream release. Programs are located in this order: the path set in the module settings, PATH, then the bin/ subdirectory of the config directory. For Docker deployments, drop the binary into the mounted config directory, for example ./gately-data/bin/frpc; Tailscale needs both tailscale and tailscaled. Tokens and keys in config files are stored with 0600 permissions, and the cloudflared token is passed via an environment variable so it never appears in the process list.

Migrating from Lucky

See the migration guide. In short: under "Settings → Import from Lucky", choose the lucky_*.lkcf file from your Lucky config directory, preview it, then import. Imported rules are disabled by default; go module by module, disabling in Lucky and enabling in Gately.

Development

Requirements: Go 1.26+, Node.js 24+, pnpm.

make web      # build the frontend (outputs to web/dist, embedded via go:embed)
make build    # compile bin/gately
make test     # go test -race ./...
make lint     # gofmt, go vet, frontend type check

For frontend development, run cd web && pnpm dev; /api is proxied to local 127.0.0.1:16680.

Some tests are skipped by default and need extra setup:

Test How to enable
ACME end-to-end (Pebble) Install pebble and pebble-challtestsrv, set GATELY_PEBBLE_BIN and GATELY_PEBBLE_SRC (runs automatically in CI)
Real public STUN servers GATELY_NET_TEST=1
Import validation with a real Lucky config GATELY_LUCKY_SAMPLE and others, see TestImportRealSample in each module

For the directory layout and technology choices, see docs/ROADMAP.md.

The website (gately.cn) source lives in website/ and is built with VitePress: cd website && pnpm install && pnpm dev; pnpm deploy:site builds and syncs it to the server.

Contributing

  • Lucky compatibility is based on publicly observable behavior, interfaces, and configuration formats. Do not submit code copied from Lucky binaries or frontend bundles.
  • A new module needs a config schema with validation, runtime start/stop, REST endpoints, and unit tests. Modules that can be migrated from Lucky implement luckyimport.Importer; modules that want to show status on the overview page implement module.Summarizer.
  • Code comments are written in Chinese; control statements must use braces.

Star History

Star History Chart

License

Apache License 2.0

Directories

Path Synopsis
cmd
gately command
Gately 是开源的网络网关工具集,适用于家庭网络、NAS 与各类服务器:端口转发、DDNS、STUN 穿透、反向代理与证书管理。
Gately 是开源的网络网关工具集,适用于家庭网络、NAS 与各类服务器:端口转发、DDNS、STUN 穿透、反向代理与证书管理。
internal
apitoken
Package apitoken 实现可多个、可限定权限的 API 令牌。
Package apitoken 实现可多个、可限定权限的 API 令牌。
app
Package app 负责组装配置、认证、模块与管理 HTTP 服务。
Package app 负责组装配置、认证、模块与管理 HTTP 服务。
auth
Package auth 实现管理员账号、会话令牌与登录限流。
Package auth 实现管理员账号、会话令牌与登录限流。
backup
Package backup 负责配置备份的打包、加密、解析与保留策略,供手动导出、定时备份与恢复共用。
Package backup 负责配置备份的打包、加密、解析与保留策略,供手动导出、定时备份与恢复共用。
config
Package config 提供按模块划分的明文 JSON 配置存储。
Package config 提供按模块划分的明文 JSON 配置存储。
crud
Package crud 为"有序规则列表"类配置提供通用的增删改查、启停与排序接口。
Package crud 为"有序规则列表"类配置提供通用的增删改查、启停与排序接口。
ctl
Package ctl 实现 Gately 的命令行客户端与 MCP 服务器:二者都通过 HTTP + API 令牌调用运行中的实例, 不重复任何业务逻辑,接口清单直接来自实例的 OpenAPI 文档。
Package ctl 实现 Gately 的命令行客户端与 MCP 服务器:二者都通过 HTTP + API 令牌调用运行中的实例, 不重复任何业务逻辑,接口清单直接来自实例的 OpenAPI 文档。
dnsprovider
Package dnsprovider 封装各 DNS 服务商的记录更新接口。
Package dnsprovider 封装各 DNS 服务商的记录更新接口。
events
Package events 提供进程内事件总线:各模块在状态变化时发布事件,通知中心等订阅者异步消费。
Package events 提供进程内事件总线:各模块在状态变化时发布事件,通知中心等订阅者异步消费。
geoip
Package geoip 读取 MaxMind 格式(GeoLite2 / DB-IP 等)的国家或城市库,按 IP 查询国家代码。
Package geoip 读取 MaxMind 格式(GeoLite2 / DB-IP 等)的国家或城市库,按 IP 查询国家代码。
httpx
Package httpx 提供管理 API 共用的 JSON 读写与错误响应。
Package httpx 提供管理 API 共用的 JSON 读写与错误响应。
i18n
Package i18n 为后端运行时文案提供多语言:源码中的中文字面量即键,译文放在 locales/<语言>.json。
Package i18n 为后端运行时文案提供多语言:源码中的中文字面量即键,译文放在 locales/<语言>.json。
i18n/cmd/i18nsync command
i18nsync 把源码里的中文字面量同步到 internal/i18n/locales/<语言>.json: 新增的键写入空值等待翻译,已有译文保持不变,源码里已不存在的键默认保留(加 -prune 删除)。
i18nsync 把源码里的中文字面量同步到 internal/i18n/locales/<语言>.json: 新增的键写入空值等待翻译,已有译文保持不变,源码里已不存在的键默认保留(加 -prune 删除)。
i18n/extract
Package extract 扫描 Go 源码,收集所有含中文的字符串字面量,作为运行时翻译的键。
Package extract 扫描 Go 源码,收集所有含中文的字符串字面量,作为运行时翻译的键。
ipsource
Package ipsource 获取本机公网 IP,支持查询 URL、读取网卡和执行命令三种方式。
Package ipsource 获取本机公网 IP,支持查询 URL、读取网卡和执行命令三种方式。
logbuf
Package logbuf 提供带序号的内存环形日志缓冲,供前端增量拉取。
Package logbuf 提供带序号的内存环形日志缓冲,供前端增量拉取。
luckyimport
Package luckyimport 解析 Lucky 的 .lkcf 配置文件,用于迁移到 Gately。
Package luckyimport 解析 Lucky 的 .lkcf 配置文件,用于迁移到 Gately。
module
Package module 定义功能模块的统一接口。
Package module 定义功能模块的统一接口。
modules/backup
Package backup 实现定时配置备份:按 cron 表达式打包全部配置,写入本地目录或存储管理中的挂载点 (本地目录、WebDAV),支持口令加密与按数量保留,并在成功或失败时发布通知事件。
Package backup 实现定时配置备份:按 cron 表达式打包全部配置,写入本地目录或存储管理中的挂载点 (本地目录、WebDAV),支持口令加密与按数量保留,并在成功或失败时发布通知事件。
modules/cloudflared
Package cloudflared 托管 cloudflared 隧道: 使用 Cloudflare Zero Trust 的隧道令牌运行已配置的隧道,或创建无需账号的临时公网隧道。
Package cloudflared 托管 cloudflared 隧道: 使用 Cloudflare Zero Trust 的隧道令牌运行已配置的隧道,或创建无需账号的临时公网隧道。
modules/cron
Package cron 实现计划任务模块:按 cron 表达式定时执行命令或 HTTP 请求,并保留最近的执行记录。
Package cron 实现计划任务模块:按 cron 表达式定时执行命令或 HTTP 请求,并保留最近的执行记录。
modules/ddns
Package ddns 实现动态域名解析模块。
Package ddns 实现动态域名解析模块。
modules/docker
Package docker 实现 Docker 管理模块:查看容器、启停、日志,以及检查镜像更新并按原配置重建容器。
Package docker 实现 Docker 管理模块:查看容器、启停、日志,以及检查镜像更新并按原配置重建容器。
modules/frp
Package frp 托管 frpc(内网穿透客户端)与 frps(服务端): 在界面中维护连接与代理列表,生成配置文件并守护外部 frp 进程。
Package frp 托管 frpc(内网穿透客户端)与 frps(服务端): 在界面中维护连接与代理列表,生成配置文件并守护外部 frp 进程。
modules/ftp
Package ftp 实现 FTP 文件服务:多用户、每个用户映射到一个或多个目录,可设为只读,支持 FTPS 与被动端口范围。
Package ftp 实现 FTP 文件服务:多用户、每个用户映射到一个或多个目录,可设为只读,支持 FTPS 与被动端口范围。
modules/nettools
Package nettools 提供网络诊断工具:Ping、Traceroute、TCP 端口探测、DNS 查询、测速与局域网扫描。
Package nettools 提供网络诊断工具:Ping、Traceroute、TCP 端口探测、DNS 查询、测速与局域网扫描。
modules/notify
Package notify 实现通知中心:订阅进程内事件,按规则经 Webhook、Telegram、Bark、企业微信、钉钉、飞书、邮件等渠道推送。
Package notify 实现通知中心:订阅进程内事件,按规则经 Webhook、Telegram、Bark、企业微信、钉钉、飞书、邮件等渠道推送。
modules/portforward
Package portforward 实现 TCP/UDP 端口转发模块。
Package portforward 实现 TCP/UDP 端口转发模块。
modules/registry
Package registry 集中创建全部功能模块,供主程序、文档导出与测试共用。
Package registry 集中创建全部功能模块,供主程序、文档导出与测试共用。
modules/ssl
Package ssl 实现证书管理模块:ACME 自动签发与续期、上传证书、读取文件证书, 并可把证书写到目录供其他服务使用,同时为 Web 服务模块提供按 SNI 选择证书的能力。
Package ssl 实现证书管理模块:ACME 自动签发与续期、上传证书、读取文件证书, 并可把证书写到目录供其他服务使用,同时为 Web 服务模块提供按 SNI 选择证书的能力。
modules/storage
Package storage 实现存储管理与文件管理:登记本地目录或远程 WebDAV 作为挂载点, 并提供浏览器内的文件浏览、上传、下载、新建目录、重命名与删除。
Package storage 实现存储管理与文件管理:登记本地目录或远程 WebDAV 作为挂载点, 并提供浏览器内的文件浏览、上传、下载、新建目录、重命名与删除。
modules/stun
Package stun 实现 STUN 内网穿透模块:在 NAT1(全锥形)网络下获取公网映射端口, 并通过保活与内置转发把外部访问引到内网服务。
Package stun 实现 STUN 内网穿透模块:在 NAT1(全锥形)网络下获取公网映射端口, 并通过保活与内置转发把外部访问引到内网服务。
modules/tailscale
Package tailscale 托管 tailscaled 并通过 tailscale 命令完成登录与状态展示, 把本机加入 Tailscale 或 Headscale 组网,可发布子网路由与出口节点。
Package tailscale 托管 tailscaled 并通过 tailscale 命令完成登录与状态展示, 把本机加入 Tailscale 或 Headscale 组网,可发布子网路由与出口节点。
modules/waf
Package waf 实现基于 Coraza 与 OWASP 核心规则集(CRS)的 Web 应用防火墙, 以实例形式供 Web 服务的站点引用。
Package waf 实现基于 Coraza 与 OWASP 核心规则集(CRS)的 Web 应用防火墙, 以实例形式供 Web 服务的站点引用。
modules/webdav
Package webdav 实现 WebDAV 文件服务:多用户、每个用户映射到一个或多个目录,可设为只读。
Package webdav 实现 WebDAV 文件服务:多用户、每个用户映射到一个或多个目录,可设为只读。
modules/webservice
Package webservice 实现 Web 服务模块:按域名把请求分发到反向代理、重定向、静态文件或固定文本, 支持 HTTPS(证书来自证书模块)、PROXY 协议、基本认证、网页认证与 IP 访问控制。
Package webservice 实现 Web 服务模块:按域名把请求分发到反向代理、重定向、静态文件或固定文本, 支持 HTTPS(证书来自证书模块)、PROXY 协议、基本认证、网页认证与 IP 访问控制。
modules/webterminal
Package webterminal 实现 Web 终端:通过 WebSocket 在浏览器中使用 SSH、Telnet 或本机 Shell, 会话由服务端持久保存,浏览器断开后可按设置保留并重新附着。
Package webterminal 实现 Web 终端:通过 WebSocket 在浏览器中使用 SSH、Telnet 或本机 Shell, 会话由服务端持久保存,浏览器断开后可按设置保留并重新附着。
modules/wol
Package wol 实现网络唤醒模块:向局域网发送魔术包唤醒设备,并可通过 TCP 端口探测设备是否在线。
Package wol 实现网络唤醒模块:向局域网发送魔术包唤醒设备,并可通过 TCP 端口探测设备是否在线。
mountfs
Package mountfs 把多个本地目录组合成一个虚拟文件系统:根目录只读,按挂载名称列出各目录, 每个挂载可单独设为只读。
Package mountfs 把多个本地目录组合成一个虚拟文件系统:根目录只读,按挂载名称列出各目录, 每个挂载可单独设为只读。
netpipe
Package netpipe 提供两个连接之间的双向转发。
Package netpipe 提供两个连接之间的双向转发。
proc
Package proc 托管外部可执行文件(frpc、cloudflared、tailscaled 等): 查找二进制、后台运行、异常退出自动重启、把输出写入模块日志。
Package proc 托管外部可执行文件(frpc、cloudflared、tailscaled 等): 查找二进制、后台运行、异常退出自动重启、把输出写入模块日志。
resolver
Package resolver 让程序的出站域名解析使用自定义 DNS 服务器,支持普通 DNS 与 DNS over HTTPS。
Package resolver 让程序的出站域名解析使用自定义 DNS 服务器,支持普通 DNS 与 DNS over HTTPS。
reuseport
Package reuseport 提供可复用端口的监听与拨号,使同一本地端口既能监听入站连接, 又能主动连接 STUN 服务器与保活服务器(STUN 穿透的关键)。
Package reuseport 提供可复用端口的监听与拨号,使同一本地端口既能监听入站连接, 又能主动连接 STUN 服务器与保活服务器(STUN 穿透的关键)。
script
Package script 执行用户配置的 Shell 脚本,变量通过环境变量传入以避免注入。
Package script 执行用户配置的 Shell 脚本,变量通过环境变量传入以避免注入。
stun
Package stun 实现 RFC 5389 的 Binding 请求与响应,用于获取 NAT 映射后的公网地址。
Package stun 实现 RFC 5389 的 Binding 请求与响应,用于获取 NAT 映射后的公网地址。
sysstat
Package sysstat 采集概览页展示的主机与进程信息:CPU、内存、磁盘、网卡与实时速率。
Package sysstat 采集概览页展示的主机与进程信息:CPU、内存、磁盘、网卡与实时速率。
thirdauth
Package thirdauth 实现自建的第三方登录(GitHub、Google、QQ 与通用 OIDC)。
Package thirdauth 实现自建的第三方登录(GitHub、Google、QQ 与通用 OIDC)。
upnp
Package upnp 实现 UPnP IGD 端口映射(SSDP 发现 + SOAP 控制)与 NAT-PMP 端口映射。
Package upnp 实现 UPnP IGD 端口映射(SSDP 发现 + SOAP 控制)与 NAT-PMP 端口映射。
version
Package version 保存构建时注入的版本信息。
Package version 保存构建时注入的版本信息。
webhook
Package webhook 实现带变量替换的 HTTP 回调,供 DDNS、STUN 等模块在状态变化时通知外部系统。
Package webhook 实现带变量替换的 HTTP 回调,供 DDNS、STUN 等模块在状态变化时通知外部系统。
Package web 嵌入前端构建产物。
Package web 嵌入前端构建产物。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL