[2025-jun-17] The SlackDocs mailing lists at https://lists.alienbase.nl/mailman/listinfo have been retired. No one has been using these lists for years and it's time to say goodbye. The list archives remain available at https://scalzi.slackware.nl/mailman/listinfo/slackdocs

[2025-jun-17] The SlackDocs Wiki has moved to a new server, in order to make it more performant.

Welcome to the Slackware Documentation Project

Configuring a Basic Firewall with UFW

tl;dr — UFW (Uncomplicated Firewall) provides a simplified interface to iptables. Install it from SlackBuilds.org, add your rules, then integrate it with Slackware's /etc/rc.d/rc.firewall for automatic startup at boot.

Overview

This document describes a minimal and explicit approach to configuring a basic firewall on Slackware using UFW (Uncomplicated Firewall).

UFW provides a simplified interface to iptables while still allowing manual configuration when required. This setup covers installation, basic rule management, enabling UFW at boot, and optional NAT support for gateway scenarios.

Design goals

  • keep firewall rules simple and readable
  • integrate cleanly with Slackware init scripts
  • avoid background services beyond iptables
  • support both workstation and gateway use cases
  • retain full control over iptables behavior

Assumptions

  • Slackware 15.0 or Slackware -current is in use
  • UFW is installed via SlackBuilds.org
  • the user has root access
  • basic networking is already functional

Installing UFW

UFW is not part of the base Slackware distribution. Install it from SlackBuilds.org.

As root, mirror the build directory, build, and install:

# lftp -c "open https://slackbuilds.org/slackbuilds/15.0/network/; mirror ufw"
# cd ufw
# sudo sh ufw.SlackBuild
# sudo installpkg /tmp/ufw-*.t?z

Adding firewall rules

Allow basic services such as SSH, HTTP, and a custom TCP port:

# sudo ufw allow ssh
# sudo ufw allow http
# sudo ufw allow 8080/tcp

Rules are applied immediately but are not enforced until UFW is enabled.

Enabling UFW on Slackware

Enable the firewall:

# sudo ufw enable

Slackware uses /etc/rc.d/rc.firewall during system startup. To integrate UFW with this mechanism, create the following symlink:

If /etc/rc.d/rc.firewall already exists, back it up before creating the symlink: mv /etc/rc.d/rc.firewall /etc/rc.d/rc.firewall.bak
# sudo ln -s /etc/rc.d/rc.ufw /etc/rc.d/rc.firewall

Ensure the UFW init script is executable:

# sudo chmod 755 /etc/rc.d/rc.ufw

With this setup, UFW will be activated automatically at boot.

Checking firewall status

To view current rules:

# sudo ufw status

Example output:

Status: active

To                         Action      From
--                         ------      ----
SSH                        ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
8080/tcp                   ALLOW       Anywhere
SSH (v6)                   ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
8080/tcp (v6)              ALLOW       Anywhere (v6)

To view rules with numbering (useful for deletion):

# sudo ufw status numbered

Removing firewall rules

List rules with numbers:

# sudo ufw status numbered

Remove a rule by its number:

# sudo ufw delete 2

NAT and gateway configuration

UFW does not provide a high-level NAT command but supports NAT through manual configuration. This is useful when the system acts as a gateway or performs internet sharing.

Enabling IP forwarding

Edit the UFW sysctl configuration file:

# sudo vi /etc/ufw/sysctl.conf

Ensure the following line is enabled:

net/ipv4/ip_forward=1

Apply the change immediately:

# sudo sysctl -w net.ipv4.ip_forward=1

Adding NAT rules

Edit the UFW rules file:

# sudo vi /etc/ufw/before.rules

Add the following at the very top, before any *filter table:

*nat
:POSTROUTING ACCEPT [0:0]
# Replace eth0 with your external interface
-A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
COMMIT

This configuration enables NAT for hosts in the 192.168.0.0/24 network using eth0 as the outbound interface. Replace eth0 with your actual external interface name.

Reloading UFW

Apply the changes by restarting UFW:

# sudo ufw disable
# sudo ufw enable

Conclusion

UFW provides a practical and understandable firewall interface for Slackware systems when combined with Slackware's native init scripts.

By enabling UFW explicitly, integrating it with rc.firewall, and optionally configuring NAT through backend files, systems can be secured without sacrificing transparency or control.

References

Sources

* Originally written by r1w1s1

QR Code
QR Code howtos:security:ufw_on_slackware (generated for current page)