Skip to content

Firewall rules for an OpenClaw IaaS deployment

A reference table of inbound, outbound, and per-channel reachability rules for a self-hosted OpenClaw gateway — nftables rule sets, UFW commands, and OnApp firewall API examples.

This is the reference page that gets bookmarked. You already know the principle from Private-network architecture for an OpenClaw deployment — keep the gateway on loopback, push human access through an overlay, allowlist webhook ingress per platform. What you want when the agent stops answering Telegram or the Slack signing-secret check fails is a fast lookup of which port maps to which platform, what direction the rule needs to be in, and where to put it. That is this page.

The OpenClaw gateway listens on TCP 18789 by default (github.com/openclaw/openclaw). Everything else is either an outbound call to a model provider or a channel API, or an inbound webhook from a chat platform. The rules below cover both directions, every supported channel, and the three flavors of firewall you are most likely to be writing rules in: nftables (most modern Linux installs), UFW (the friendly wrapper), and the OnApp firewall API (which fronts many IaaS panels) (docs.onapp.com).

Inbound — what should be reachable on the public NIC

The default posture is: nothing inbound on the public NIC except SSH. Every other inbound either rides an overlay (Tailscale, Cloudflare Tunnel) or has a narrow allowlist-based rule for a specific webhook.

PortProtoDirectionWhen you need itAllow source
22TCPinboundAlwaysYour bastion or your tailnet only
443TCPinboundWhen running any channel in webhook mode behind CaddyPer-platform CIDR allowlist (see channel table)
80TCPinboundOnly during Let’s Encrypt HTTP-01 challenge0.0.0.0/0 briefly, then close
18789TCPinboundNever on the public NICn/a — stays on 127.0.0.1

Tailscale’s tailscale0 interface does not need a public-NIC rule because the traffic is encapsulated WireGuard arriving on UDP 41641 outbound to Tailscale’s relays — see the wire format in tailscale.com — How Tailscale works. Cloudflare Tunnel needs no inbound rule at all; cloudflared makes outbound TCP 443 connections to Cloudflare’s edge (developers.cloudflare.com — Tunnel).

Outbound — what the gateway needs to reach

The gateway is a heavy outbound talker by design. Required destinations:

DestinationProto/portWhy
LLM provider API (Anthropic, OpenAI, Google, etc.)TCP 443Every model call
*.tailscale.com, *.tailscale.net, UDP 41641TCP 443, UDP 41641Tailscale control + WireGuard NAT traversal
*.cloudflare.com, quic.cloudflare.comTCP 443, UDP 443Cloudflare Tunnel transport
deb.nodesource.com, archive.ubuntu.com, etc.TCP 443/80Package updates
registry.npmjs.orgTCP 443OpenClaw updates and skill installs
Channel APIs (per channel — see table below)TCP 443Outbound polling, message sends

A default default allow outgoing in UFW covers all of these. If your environment requires explicit outbound allowlisting, you will end up with a long list — the LLM API endpoints alone span half a dozen domains depending on which provider you use (docs.anthropic.com, platform.openai.com/docs).

Per-channel reachability

Each chat channel has two reachability characteristics: where the channel’s API lives (always outbound from the gateway), and whether the channel uses polling or webhooks for inbound delivery (only webhooks need an inbound rule).

ChannelOutbound API hostOutbound portInbound modeWebhook source IPs (if applicable)
Telegramapi.telegram.orgTCP 443webhook or long-poll149.154.160.0/20, 91.108.4.0/22 (core.telegram.org — Webhooks)
Slackslack.com, api.slack.comTCP 443events API (webhook) or socket mode (outbound only)Slack does not commit to a fixed range; use signature validation (api.slack.com — Verifying requests)
Discorddiscord.com, gateway.discord.ggTCP 443, WebSocket 443gateway WebSocket (outbound) or HTTP interactions (webhook)Published in API docs (discord.com/developers — Interactions)
Signalsignal.org, signal-cli endpointsTCP 443outbound onlyn/a
iMessagemacOS Apple Push Notification serversTCP 5223, 443macOS-host-only (not applicable on Linux VPS)n/a
WhatsAppdepends on bridge (e.g., Meta Cloud API or Mautrix)TCP 443mostly webhookPer-bridge — check the bridge’s docs
Matrixyour homeserver, e.g., matrix.orgTCP 443outbound only (federation handled by HS)n/a
Microsoft Teams*.office.com, *.microsoft.comTCP 443webhook (Bot Framework)Azure outbound IPs (learn.microsoft.com — Azure IP ranges)
Google Chatchat.googleapis.comTCP 443webhookGoogle IPs are dynamic; signature validation is the actual auth (developers.google.com — Chat verification)
Mattermostyour Mattermost serverTCP 443outbound or webhookn/a if outbound
LINEapi.line.meTCP 443webhookPublished in LINE docs
GitHub (notifications/webhooks)api.github.comTCP 443webhookapi.github.com/meta — refresh periodically

If a channel can be configured in polling mode (Telegram, Discord, several others), polling mode is the right default for a personal OpenClaw — it requires zero inbound exposure. Webhook mode is lower-latency and the right default for higher-volume channels.

UFW (Ubuntu / Debian)

The base posture, lifted from Deploying OpenClaw on a small IaaS VPS for 24/7 access:

sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw --force enable
sudo ufw status verbose

If you opened :443 for webhooks, the layered nftables rules below take over the CIDR allowlist enforcement — UFW alone is not granular enough.

UFW does support comments, which are worth using:

sudo ufw allow 22/tcp comment 'SSH from bastion'
sudo ufw allow 443/tcp comment 'Caddy reverse-proxy for webhooks'

A clean ufw status verbose on a webhook-running OpenClaw VPS:

Status: active
Default: deny (incoming), allow (outgoing), disabled (routed)

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere                # SSH from bastion
443/tcp                    ALLOW IN    Anywhere                # Caddy reverse-proxy for webhooks
22/tcp (v6)                ALLOW IN    Anywhere (v6)
443/tcp (v6)               ALLOW IN    Anywhere (v6)

The CIDR allowlist is enforced one layer down, in nftables.

nftables (modern stack)

UFW writes nftables rules under the hood, but the most precise way to add allowlists is in a separate nftables config that systemd loads alongside UFW.

sudo tee /etc/nftables-openclaw.conf >/dev/null <<'NFT'
#!/usr/sbin/nft -f

table inet openclaw {
    # Per-platform allow-lists
    set telegram_v4 {
        type ipv4_addr
        flags interval
        elements = { 149.154.160.0/20, 91.108.4.0/22 }
    }

    set github_v4 {
        type ipv4_addr
        flags interval
        elements = {
            140.82.112.0/20, 192.30.252.0/22,
            185.199.108.0/22, 143.55.64.0/20
        }
    }

    # Tailnet (your CGNAT range — Tailscale uses 100.64.0.0/10)
    set tailnet {
        type ipv4_addr
        flags interval
        elements = { 100.64.0.0/10 }
    }

    chain webhook_in {
        type filter hook input priority -10; policy accept;

        # Default-deny on :443; selectively allow per platform
        tcp dport 443 ip saddr @telegram_v4 accept
        tcp dport 443 ip saddr @github_v4 accept
        tcp dport 443 drop
    }

    chain gateway_local {
        type filter hook input priority -5; policy accept;

        # Allow the gateway only from loopback or tailnet
        tcp dport 18789 iifname "lo" accept
        tcp dport 18789 ip saddr @tailnet accept
        tcp dport 18789 drop
    }
}
NFT

Load it via systemd:

sudo tee /etc/systemd/system/nftables-openclaw.service >/dev/null <<'UNIT'
[Unit]
Description=Custom OpenClaw nftables rules
After=network-online.target ufw.service
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/nft -f /etc/nftables-openclaw.conf
ExecReload=/usr/sbin/nft -f /etc/nftables-openclaw.conf
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
UNIT

sudo systemctl daemon-reload
sudo systemctl enable --now nftables-openclaw.service
sudo nft list ruleset

The policy accept plus selective drop model lets UFW’s default rules pass non-:443 traffic through unchanged while the OpenClaw table adds tight controls on the ports we actually care about. Documentation is at wiki.nftables.org.

Refreshing CIDR allowlists

The platform allowlists rot — IPs are added, ranges are split. The maintainable pattern is a cron job that pulls the upstream list and rewrites the nftables set:

sudo tee /usr/local/sbin/refresh-github-cidrs.sh >/dev/null <<'SH'
#!/usr/bin/env bash
set -euo pipefail
TMP=$(mktemp)
trap "rm -f $TMP" EXIT

curl -fsSL https://api.github.com/meta | jq -r '.hooks[]' | grep -v ':' > "$TMP"
LIST=$(paste -sd, "$TMP")
nft "flush set inet openclaw github_v4"
for cidr in $(cat "$TMP"); do
  nft "add element inet openclaw github_v4 { $cidr }"
done
SH
sudo chmod 700 /usr/local/sbin/refresh-github-cidrs.sh

Wire it to a daily cron via systemd timer or /etc/cron.daily/. Equivalent scripts exist for Telegram (static so far) and Azure (downloadable JSON, refreshed weekly).

OnApp firewall API

OnApp fronts a large share of small-IaaS panels (docs.onapp.com). The firewall API takes JSON over the standard OnApp REST endpoint and applies rules at the hypervisor edge — useful when you do not trust an in-guest firewall to be re-applied after a panel re-image.

Authentication is HTTP Basic with an API key. Replace <host>, <token>, and <vm-id> with your panel’s values.

List existing rules for a VM:

curl -s -u "user@example.com:<token>" \
  -H "Accept: application/json" \
  "https://<host>/virtual_machines/<vm-id>/firewall_rules.json"

Add an allow-rule for SSH from a single source IP:

curl -s -u "user@example.com:<token>" \
  -H "Content-Type: application/json" \
  -X POST \
  "https://<host>/virtual_machines/<vm-id>/firewall_rules.json" \
  -d '{
    "firewall_rule": {
      "command": "ACCEPT",
      "protocol": "TCP",
      "port": "22",
      "address": "203.0.113.10/32",
      "comment": "SSH from bastion"
    }
  }'

Add the Telegram webhook CIDR allowlist on :443:

for cidr in 149.154.160.0/20 91.108.4.0/22; do
  curl -s -u "user@example.com:<token>" \
    -H "Content-Type: application/json" \
    -X POST \
    "https://<host>/virtual_machines/<vm-id>/firewall_rules.json" \
    -d "{
      \"firewall_rule\": {
        \"command\": \"ACCEPT\",
        \"protocol\": \"TCP\",
        \"port\": \"443\",
        \"address\": \"$cidr\",
        \"comment\": \"Telegram webhook\"
      }
    }"
done

A final default-deny rule on :443 forces everything else to drop:

curl -s -u "user@example.com:<token>" \
  -H "Content-Type: application/json" \
  -X POST \
  "https://<host>/virtual_machines/<vm-id>/firewall_rules.json" \
  -d '{
    "firewall_rule": {
      "command": "DROP",
      "protocol": "TCP",
      "port": "443",
      "address": "0.0.0.0/0",
      "comment": "Default deny :443"
    }
  }'

Push the changes (some OnApp installs require an explicit commit step depending on version):

curl -s -u "user@example.com:<token>" \
  -X POST \
  "https://<host>/virtual_machines/<vm-id>/firewall_rules/update.json"

The OnApp firewall ordering is sequential — DROP after ACCEPT means matched ACCEPTs win — so order matters. Verify with the list call.

Quick lookups

“What’s the default OpenClaw port?” TCP 18789, on loopback. The Gateway HTTP listener config keys are gateway.port and gateway.bind in openclaw.json (github.com/openclaw/openclaw).

“Tailscale doesn’t need an inbound rule, right?” Right. Tailscale uses outbound UDP 41641 by default (or whatever DERP relay the peer picked). Your firewall does not need any inbound port for Tailscale to work (tailscale.com — How Tailscale works).

“Cloudflare Tunnel?” Outbound TCP 443 to Cloudflare’s edge. Nothing inbound. The tunnel daemon runs as a service and dials home (developers.cloudflare.com — Cloudflare Tunnel).

“Where does Caddy live in this?” Caddy listens on :443 and reverse-proxies a single path (/webhooks/<platform>) to 127.0.0.1:18789. The nftables allowlist controls who reaches :443. Caddy does not need any extra inbound holes (caddyserver.com).

“What ports does the dashboard use?” Same as the gateway — 127.0.0.1:18789. The dashboard is a path on the gateway, not a separate service.

Sources


Last verified on OpenClaw current.

Have us deploy and harden this for you.