Abstrax

Firewall

The firewall group manages the system firewall. On Debian-family systems it uses UFW. On RHEL-family systems it uses firewalld.

abstrax firewall <action> [flags]

Run abstrax doctor to see which firewall strategy is active (ufw or firewalld).

Permissions

Most firewall commands require root. firewall status, firewall defaults, and firewall rule list do not require root.

firewall install

Install the platform firewall package without enabling it.

Distro family Package
Debian/Ubuntu ufw
Rocky/Alma/RHEL firewalld
sudo abstrax firewall install

After install, enable the firewall with SSH protection:

sudo abstrax firewall enable --allow-ssh

firewall enable will also install the package automatically if it is missing.

firewall status

Show whether the firewall is active and list current rules.

abstrax firewall status

--json includes a defaults object with the same fields as firewall defaults when those values can be read. It is omitted if the defaults cannot be read.

firewall defaults

Show the default firewall policy. Does not require root. Registered as firewall.defaults.

abstrax firewall defaults
  Firewall:    ufw
  Incoming:    deny
  Outgoing:    allow
  Routed:      disabled
  Ping:        allow

The result is {backend, defaults}:

Field Values Notes
defaults.incoming allow, deny, or reject Default for unmatched inbound traffic
defaults.outgoing allow, deny, or reject Default for unmatched outbound traffic
defaults.routed for example disabled UFW only
defaults.ping allow, block, mixed, or unknown mixed if IPv4 and IPv6 disagree; unknown if it cannot be read

On UFW, Abstrax reads ufw status verbose, or /etc/default/ufw while UFW is inactive. On firewalld, it reads the target of the default zone: default and REJECT are reject, DROP is deny, and ACCEPT is allow. firewalld reports outgoing as allow.

firewall defaults set

Change the default incoming (and optionally outgoing) policy. Requires root. Registered as firewall.defaults.set.

sudo abstrax firewall defaults set --incoming deny
sudo abstrax firewall defaults set --incoming deny --outgoing allow
sudo abstrax firewall defaults set --incoming allow --yes
Flag Description
--incoming Required. deny, reject, or allow
--outgoing allow, deny, or reject. UFW only; refused on firewalld
--force Apply the policy even if it would block SSH
  • UFW: runs ufw default <policy> incoming|outgoing.
  • firewalld: sets the default zone target (DROP, %%REJECT%%, ACCEPT) and reloads. --outgoing is not supported.

--incoming allow opens every port that has no rule against it, so Abstrax warns and asks for confirmation. --yes skips the prompt.

--incoming deny or reject is refused while the firewall is active and no rule allows TCP to the SSH port, unless the policy already blocks incoming traffic. --force applies it anyway; --yes does not. Successful --json output includes ssh_check when the check ran. See Automatic SSH lockout protection.

firewall ping

Allow or block inbound ping (ICMP echo requests). Requires root. Registered as firewall.ping.

sudo abstrax firewall ping allow
sudo abstrax firewall ping block
  • UFW: switches the INPUT echo-request rules in /etc/ufw/before.rules and before6.rules between ACCEPT and DROP, writes a .bak of each changed file, reloads UFW, and restores the files if the reload fails.
  • firewalld: adds or removes the echo-request ICMP block in the default zone and reloads.

Check the current setting with abstrax firewall defaults.

firewall enable

Enable the firewall. On Debian-family hosts this enables UFW. On RHEL-family hosts this enables and starts the firewalld service.

If the firewall package is not installed yet (ufw or firewalld), Abstrax installs it first, then enables the firewall. Prefer --allow-ssh so SSH is opened before/while enabling.

sudo abstrax firewall enable --allow-ssh
Flag Default Description
--allow-ssh false Open the SSH port before enabling
--ssh-port 22 SSH port to allow when --allow-ssh is set

Enabling without opening SSH can lock you out of the server.

firewall disable

Disable the firewall.

sudo abstrax firewall disable

firewall allow

Allow traffic on a port.

sudo abstrax firewall allow 80
sudo abstrax firewall allow 443 --protocol=tcp
sudo abstrax firewall allow 8080 --from=203.0.113.0/24 --comment="app"
Flag Default Description
--protocol Protocol (tcp or udp)
--from Allow only from this IP or CIDR
--comment Rule comment (UFW)

Before the rule is added, Abstrax tries to allow your current client IP on the SSH port. That only happens in an interactive SSH session. See Automatic SSH lockout protection.

On RHEL-family systems, ports 80/http and 443/https map to firewalld services when --from is omitted. With --from, Abstrax adds a rich rule that accepts traffic from that source only, including for ports 80 and 443. An IPv6 source uses family="ipv6". Rules are added permanently and firewalld is reloaded afterward.

firewall deny

Deny traffic on a port.

sudo abstrax firewall deny 23
sudo abstrax firewall deny 3306 --from=203.0.113.0/24 --protocol=tcp
Flag Default Description
--protocol Protocol (tcp or udp)
--from Deny only from this IP or CIDR
--comment Rule comment (UFW)
--force false Deny the port even if it would block SSH

On UFW, --from with --protocol uses ufw <action> from <ip> to any port <port> proto <protocol> (the short port/<protocol> form is rejected by UFW when a source is set). The same form is used for firewall allow.

On firewalld, firewall deny adds IPv4 and IPv6 reject rich rules for the port. --from limits the reject rule to that source, using family="ipv6" for an IPv6 address.

Denying the SSH port is refused when the firewall is active and the change would leave no TCP path to SSH. --yes does not skip that check. See Automatic SSH lockout protection.

firewall allow-ip

Allow all traffic from an IP or CIDR.

sudo abstrax firewall allow-ip 203.0.113.10
sudo abstrax firewall allow-ip 203.0.113.10 --port=3306 --protocol=tcp --comment="mysql from app"
Flag Description
--to Destination IP
--port Destination port to open for this source (not a source port)
--protocol Protocol (tcp or udp). When a port is set and this is omitted, both protocols are allowed
--comment Rule comment (UFW)

On UFW, --port builds ufw allow from <ip> to <to|any> port <port> [proto <p>], so the port is the destination. firewalld already opens that destination with a rich rule.

Before the rule is added, Abstrax tries to allow your current client IP on the SSH port. That only happens in an interactive SSH session. See Automatic SSH lockout protection.

firewall deny-ip

Deny all traffic from an IP or CIDR.

sudo abstrax firewall deny-ip 198.51.100.0/24 --comment="blocked"
Flag Description
--comment Rule comment (UFW)

Before the rule is added, Abstrax tries to allow your current client IP on the SSH port. That only happens in an interactive SSH session. See Automatic SSH lockout protection.

firewall rule list

List current firewall rules. Each rule has a stable id (the first 8 characters of a hash of the rule) and a number, which is its current position in the list. The position can change when other rules are added or removed. Prefer id (or group on UFW) when you remove a rule.

Listed rules include protocol, direction, source, destination, comment, and whether the rule is IPv6. On UFW, a From column such as 10.1.2.3 3306/tcp is split into the address, source_port, and protocol (SRC column in the table; source_port in JSON). IPv4 and IPv6 copies of the same rule share a group. On firewalld, rich rules are included and can be removed by id.

When UFW is inactive, Abstrax reads ufw show added instead of returning an empty list. Those stored rules are marked pending (shown as ALLOW (not applied) / DENY (not applied)), and their ids match what ufw status numbered will assign once UFW is enabled.

abstrax firewall rule list
ID        NUM   PORT   PROTOCOL   ACTION   DIR   FROM           TO
3f2a91c0  1     22     tcp        ALLOW    IN
9c10ab44  2     443    tcp        ALLOW    IN    203.0.113.10

An empty FROM means any source. The ids above are examples; use the ids printed on your server.

Firewall commands that fail print the underlying ufw or firewall-cmd message (for example ufw: ERROR: Bad port) instead of a bare exit status 1.

firewall rule remove

Remove a rule by the id from firewall rule list, or by UFW group to delete both the IPv4 and IPv6 copies in one step.

sudo abstrax firewall rule remove 3f2a91c0
sudo abstrax firewall rule remove <group>

The id identifies the rule by its specification, so a later removal cannot hit a different rule that shifted into an old position. Passing either copy's id or the shared group runs one ufw delete that removes both address-family copies.

A numeric position still works and prints a warning, because that position can change. Removing by number deletes only that position.

sudo abstrax firewall rule remove 3
  • UFW: an id or group deletes the rule by its allow/deny specification (including source-port rules such as allow from <addr> port <port> proto <protocol>). A numeric position deletes that numbered UFW rule.
  • firewalld: an id removes the matching service, port, or rich rule permanently and reloads firewalld. Rich rules created with --from are removed this way.
Flag Default Description
--force false Remove the rule even if it would block SSH

The command is refused when this would remove the last TCP path to the SSH port and the firewall is active. --yes does not skip that check. See Automatic SSH lockout protection.

firewall remove service

Remove a firewalld service by name (RHEL-family).

sudo abstrax firewall remove service http
sudo abstrax firewall remove service https
Flag Default Description
--force false Remove the service even if it would block SSH

firewall remove service ssh is refused when that service is the last rule allowing TCP to the SSH port and the firewall is active. --yes does not skip that check.

firewall remove port

Remove a firewalld port (RHEL-family).

sudo abstrax firewall remove port 8080/tcp
sudo abstrax firewall remove port 9090/udp
Flag Default Description
--force false Remove the port even if it would block SSH

Removing the SSH port is refused when it is the last rule allowing TCP to that port and the firewall is active. --yes does not skip that check.

Automatic SSH lockout protection

Abstrax tries not to cut off the SSH session you are using, and it refuses changes that would leave an active firewall with no way to reach SSH.

Client IP protection

firewall enable, allow, deny, allow-ip, and deny-ip allow your current client IP on the SSH port before they change anything else, when Abstrax can see that IP.

That detection only works in an interactive SSH session. Abstrax reads SSH_CONNECTION, then SSH_CLIENT, then who. From a script, a systemd unit, or any other non-interactive run, it does nothing. It does not print an error.

--allow-ssh on firewall enable is still the way to open SSH for every client. Client-IP protection does not replace it, and it does not run for firewall rule remove, firewall remove service, or firewall remove port.

Refusing a change that would block SSH

Before firewall deny, firewall defaults set (when setting --incoming to deny or reject), firewall rule remove, firewall remove service, and firewall remove port, Abstrax reads the SSH port from the sshd configuration and simulates the change against the current rules:

  • remove uses the rule list without the rule, service, or port being deleted
  • deny inserts the new deny before any allow, because UFW uses the first matching rule
  • defaults set treats a default incoming deny or reject as blocking SSH when no allow rule covers the SSH port (unless the policy already blocks incoming traffic)

If the firewall is active and, after that change, no rule allows TCP to the SSH port, the command stops:

This would block SSH (port 22), and you could lose access to this server. Add another rule that allows SSH first, or pass --force to do it anyway.

The message uses the actual SSH port. An allow limited to one IP still counts as access, so removing one of two SSH allows is permitted when the other remains. A deny of the SSH port is placed before existing allows, so firewall deny 22 is refused while the firewall is active even if an allow is already present.

--force skips the check and applies the change. --yes does not. --yes only skips confirmation prompts.

When the firewall is inactive, the change is allowed. Abstrax prints a warning that firewall enable will need --allow-ssh, because enabling later would apply the rules that no longer let SSH in.

Successful --json results for these commands include the check in data when it ran:

"ssh_check": {"port": 22, "blocked": false}

blocked is true when the resulting rules would not allow TCP to that port. If the firewall is active in that case, the command errors instead of returning the result. --force skips the check, so ssh_check is omitted.

RHEL-family notes

  • firewalld changes use --permanent and are followed by --reload
  • firewalld rule ids are a stable hash. number is the current list position. Remove a service, port, or rich rule by id, or use firewall remove service and firewall remove port
  • SELinux is separate from firewalld; Abstrax detects and warns about SELinux but never disables it
  • Prefer abstrax firewall allow 80 / allow 443 for web traffic so firewalld services are used where possible. Pass --from when the port should be limited to one source; that writes a rich rule instead of opening the service to every address

Notes

  • Always ensure SSH access is allowed before enabling the firewall on a remote host
  • Use --verbose to see the underlying ufw or firewall-cmd invocations