knocker-cli is a static Go CLI service that automatically requests a whitelist for the external IP of the device on IP address changes or when the whitelist expires. It runs in the background to ensure you always have access.
- Automatic IP Whitelisting: Automatically detects IP changes and requests a new whitelist.
- Background Service: Runs as a background service on Linux, macOS, and Windows.
- Cross-Platform: Built to be cross-platform with priority for Linux and macOS.
- Docker Support: Can be run in a Docker container.
- Manual Whitelisting: Manually trigger a whitelist request at any time.
- Structured journald events: Emits machine-readable journald events alongside human logs for desktop integrations.
knocker-cli operates in two distinct modes for handling IP changes:
The service knocks immediately on startup and refreshes at roughly 90% of the server-returned TTL. If no TTL is known, it uses a five-minute cadence. The server identifies the request's source IP.
Set watch_network: true (or KNOCKER_WATCH_NETWORK=true, or the
--watch_network flag). This requires a server with the authenticated
GET /status endpoint.
- At startup, check server status. If coverage is active, schedule renewal from the remaining TTL; otherwise knock immediately.
- On Linux, listen for kernel netlink interface, IPv4/IPv6 address, and route events, including disconnects, reconnects, and Ethernet/Wi-Fi or VPN changes. This listener requires no root privileges. Events are debounced for one second.
- On macOS and Windows, compare local interface/address snapshots every two seconds. Route-only changes are covered by periodic server checks.
- After a network change, query
/statuswith the API key. If already whitelisted (including CIDR coverage), keep the renewal schedule unchanged. Otherwise knock without specifying an IP, then reset renewal from the knock response's TTL. - Continue TTL-based renewal even when the IP does not change.
check_intervalindependently controls periodic status checks, covering upstream public IP changes or missed local events. - Failed status checks mean unknown coverage: do not knock based on that failure.
Retry after five seconds, doubling consecutive failure delays up to
check_interval; a successful status check resets the delay. Network events still trigger fresh checks. Failed scheduled renewals also retry after five seconds.
No third-party IP lookup is used. For existing configurations, a nonempty
ip_check_url enables this mode as a deprecated compatibility alias; its URL is
ignored. Servers without /status can continue using simple mode.
Status describes only the route and address family used by the API connection.
Install the prebuilt CLI on Linux x86_64 or ARM64 using Homebrew 6 or newer:
brew update
brew tap fariszr/tap
brew trust fariszr/tap
brew install --cask knocker-cli
knocker --helpReview the tap before granting trust. The package is named knocker-cli to
distinguish it from the core Knocker project; its executable remains knocker.
After tapping and trusting, the short package name works without a tap prefix.
To keep the CLI up to date:
brew update
brew upgrade --cask knocker-cliThe Homebrew tap follows published GitHub releases automatically. It checks for releases every six hours; maintainers can also configure immediate release notifications as described in the tap README. Homebrew installs the CLI without starting its background service. See the service installation instructions below to configure and start it.
To install from source, you will need Go 1.26 or newer.
git clone https://github.com/FarisZR/knocker-cli.git
cd knocker-cli
go install ./...You can also run Knocker using Docker.
docker build -t knocker-cli .
docker run -d --name knocker-cli -e KNOCKER_API_URL=... -e KNOCKER_API_KEY=... knocker-cliKnocker can be configured via a configuration file or environment variables.
Create a file named .knocker.yaml in your home directory with the following content:
api_url: "http://your-knocker-api-url"
api_key: "your-api-key"
watch_network: false # optional, check server status on network changes
check_interval: 5 # fallback server status check interval in minutes
ttl: 0 # optional, time to live in seconds for the knock request (0 for server default)You can also configure knocker-cli using environment variables:
KNOCKER_API_URL: The URL of the Knocker API.KNOCKER_API_KEY: Your API key.KNOCKER_WATCH_NETWORK: Enable network monitoring and server status checks (defaultfalse).KNOCKER_CHECK_INTERVAL: Fallback server status check interval in minutes (default5).KNOCKER_IP_CHECK_URL: Deprecated compatibility alias; any nonempty value enables network monitoring. The URL is ignored.KNOCKER_TTL: Optional time to live in seconds for the knock request (0 for server default).
When running as the packaged systemd user service, these variables can be placed in ~/.config/knocker/env using the standard KEY=value format.
When the service runs under systemd (for example as knocker.service), every operational log is mirrored to journald with a human-friendly MESSAGE and a stable set of KNOCKER_* fields. These events let desktop integrations such as GNOME shell extensions consume Knocker state without polling a separate API.
- Stream the events:
journalctl --user -u knocker.service -o json -f | jq 'select(.KNOCKER_EVENT != null)'to follow only structured entries, or pin to a specific type withKNOCKER_EVENT=StatusSnapshotas needed (journalctlonly supportsFIELD=valuecomparisons per its manual). - Schema version: All entries include
KNOCKER_SCHEMA_VERSION=1for forward compatibility. - Event types:
ServiceState— lifecycle notifications (started,stopping,stopped) with optionalKNOCKER_VERSION.StatusSnapshot— current whitelist, TTL, and next scheduled knock.WhitelistApplied/WhitelistExpired— whitelist changes with expiry metadata.NextKnockUpdated— upcoming knock timestamp (or0when cleared).KnockTriggered— manual (cli), scheduled (schedule), and network/status (network) knocks with success/failure result.Error— surfaced issues that should be shown in the UI.
Manual invocations of knocker knock produce the same KnockTriggered and WhitelistApplied events so external consumers stay in sync even when the background service is idle.
knocker runEven if the background service is running, you can manually trigger a whitelist request at any time.
knocker knockknocker installNote: On Linux the installer registers a per-user systemd unit at
~/.config/systemd/user/knocker.service. Start it immediately withsystemctl --user enable --now knocker. On macOS the installer writes~/Library/LaunchAgents/knocker.plist; load it withlaunchctl bootstrap gui/$UID ~/Library/LaunchAgents/knocker.plist.
knocker startknocker stopknocker uninstallknocker statusTo build the binary for your current platform, run:
go build -o knocker ./cmd/knockerTo create cross-platform builds, archives, and releases, you can use GoReleaser.
# This will create builds for all platforms defined in .goreleaser.yml
goreleaser release --snapshot --cleanWith uv, Python 3, Go, and a current checkout of the Knocker server available:
python3 scripts/e2e.py /path/to/knockerThis starts a disposable server on loopback with firewall integration disabled and an isolated whitelist. It tests CIDR coverage, network changes, TTL renewal, and recovery after a simulated disconnect, then removes the test data. Source changes are simulated using forwarded addresses from the trusted local test transport; it does not switch your machine's adapters.