# POST /security/firewall/rules

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the security group.

Add a firewall rule

- Who may call it: administrator
- Token scope, any of: security, all
- Answers: 201 Created

Set kind to port to open an additional port or closed to drop traffic to a port even when a service is listening. For either kind, value accepts a port from 1 to 65535 or an inclusive range such as 30000-31000, with the lower port first. TCP is the default. Append /udp for UDP or /tcp for TCP. A closed rule lasts until removed, and IP addresses on the Allow list retain access. Closing a web interface or SSH port requires the caller's IP address to be on the Allow list.

For kind allow or deny, value accepts an IPv4 or IPv6 IP address or a network in CIDR notation. An allow rule can create an exception inside a larger denied network and lifts any active bans it covers. UrbeStack rejects duplicate rules, a deny rule fully covered by an existing allow rule, and an allow rule that would fully cover an existing deny rule. It also rejects a deny rule that covers the caller's IP address, a server IP address, or loopback. Invalid rule input returns 400.

Adding a deny rule requires that no other change be pending. UrbeStack restores the previous rules after five minutes unless you confirm with urbestack-firewall-confirm or through the Confirm button in the web interface. Verify access in a new session before confirming.

## As a command

- [urbestack-firewall-rule-add](https://urbestack.com/docs/commands/urbestack-firewall-rule-add.md): Adds a firewall rule.

## Request body

JSON, the type [FirewallRuleCreate](https://urbestack.com/docs/api/types/FirewallRuleCreate.md).

- `kind` (string, one of port, allow, deny, closed, required)
- `value` (string, up to 64 characters, required)
- `note` (string, up to 80 characters): Note shown beside the port in the firewall table. It accepts up to 80 printable characters and excludes quotes and backslashes.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/security/firewall/rules" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "port",
    "note": "added by hand",
    "value": 8443
  }'
```

Response, 201 Created:

```
{
  "lifted": 1,
  "revert": {
    "armed": true,
    "deadline": "text",
    "what": "text"
  },
  "rule": {
    "created_at": "2026-09-09T10:15:00Z",
    "id": 1,
    "kind": "port",
    "note": "added by hand",
    "value": 8443
  },
  "way_in": "panel"
}
```

## Errors

- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid id
- 400: Refused. <value> 
- 400: Refused. <value> is loopback: the server's own services talk to each other over it
- 400: Say which bans: an address or network, a service or rule, a search, or a time window; or clear all blocks
- 400: kind must be port, allow, deny or closed
- 401: Authentication required
- 404: Ban <id> not found
- 409: <value> holds <dn.value>, which is on Deny: remove it there first
- 409: <value> is on Allow as <al.value>: remove it there first
- 409: A <kind> rule for <value> already exists
