How to Configure GUFW Firewall Rules on elementary OS
Linux does not secure an elementary OS installation merely because its desktop feels polished. This guide explains how to configure firewall rules with GUFW on elementary OS for better security. GUFW is the graphical front end for UFW, the host firewall that decides which incoming connections may reach a service and which outbound connections may leave the machine. It is especially valuable on a laptop used beyond the administrator’s desk.
The useful goal is least privilege: allow the traffic a computer needs and quietly refuse the rest. A host firewall also reduces exposure when an Australian broadband router is misconfigured, a device joins an unfamiliar café network, or a laptop travels between offices. It complements, rather than replaces, the router’s NAT and any cloud security group. That separation also makes rule changes easier to audit and recover.
Establish a Safe Baseline
Begin by separating the router from the computer. Many Australian NBN connections use a gateway supplied by Telstra, Optus, or Aussie Broadband, and that device normally performs network address translation before traffic reaches your PC. UFW then applies another filter directly to elementary OS. This matters on public Wi-Fi, through a router with port forwarding, and on servers that expose a service beyond the local network. A software firewall cannot replace a supported operating system, but it gives each machine its own local barrier.
Check the existing policy before changing it. Run sudo ufw status verbose and sudo ufw status numbered; the first shows whether filtering is active and its default policies, while the second lists explicit rules. Also use sudo ss -lntup to see which programs are listening. An inherited image may already contain rules, so avoid sudo ufw reset unless you have confirmed it is the correct host. Record current SSH or database access before making changes.
For a clean setup, run sudo ufw default deny incoming and sudo ufw default allow outgoing, then enable UFW with sudo ufw enable. If you administer the machine over SSH, add sudo ufw allow 22/tcp before enabling the firewall. Enable low logging while testing, and ensure boot integration with sudo systemctl enable ufw. On IPv6-enabled connections, UFW normally manages the corresponding IPv6 policy too. Keep a record of intentional exceptions.
Install GUFW and Inspect the Backend
GUFW is not necessarily preinstalled on every elementary OS release, so install it from the distribution repositories rather than adding an unfamiliar personal package archive. Run sudo apt update followed by sudo apt install gufw ufw. The gufw package supplies the interface, while ufw supplies the firewall engine. AppCenter may also offer a Firewall application that launches the same interface. This avoids dependency and packaging surprises.
Start it from the applications menu or run gufw in a terminal and authorise the administrative change. Its General tab controls incoming and outgoing policies, the Rules tab manages individual allowances and denials, and Logging controls diagnostic detail. These settings are written to the UFW backend, so the terminal and GUFW should show the same state. If they appear out of step, close GUFW and compare sudo ufw status verbose; use sudo ufw reload only after checking the intended configuration.
UFW’s application profiles live under /etc/ufw/applications.d and describe a service’s usual ports, protocol, and description. A profile gives GUFW a clearer service name than a bare port, but it does not grant access by itself; the corresponding allow or deny rule must still be active. For broader context on changes across the Linux ecosystem, Linux ecosystem news can help connect a package upgrade with unusual networking behaviour. Review profiles when services change their default port.
Add Precise Traffic Rules
Start from a traffic inventory rather than a list of memorable ports. sudo ss -lntup identifies listening sockets, while sudo ufw status numbered identifies the policy around them. In GUFW, open Rules, choose the add button, and decide whether the match is a port or a service, an Allow or Deny action, and TCP or UDP. Select the correct network interface or leave all interfaces selected only when the service should be reachable from every network. Add a short description so later audits are understandable.
A web server on elementary OS usually needs sudo ufw allow 80/tcp and sudo ufw allow 443/tcp. A remote administration service may need sudo ufw allow 22/tcp; a WireGuard endpoint commonly uses sudo ufw allow 51820/udp. These commands add narrow, protocol-specific rules. They do not open every port, and they do not replace a router port-forward or the security controls attached to a cloud instance. Do not open mail, database, or management ports merely because a tutorial lists them.
Source restrictions are useful when an administrator in a Perth or Brisbane office should reach SSH from a known network. For example, sudo ufw allow from 203.0.113.10 to any port 22 proto tcp permits that example address only; 203.0.113.10 is a documentation address, not a usable server. Use the real public address or a VPN subnet. A static office IP can change, so check it before relying on the rule. To make an exception impossible to miss, add sudo ufw deny 3306/tcp for an unused database port. UFW evaluates numbered rules in order, so inspect sudo ufw status numbered and remove obsolete entries from the highest number with sudo ufw delete 4.
Fit Rules to Australian Networks
Some Australian broadband plans, especially mobile and selected older NBN services, place the router behind carrier-grade NAT. In that arrangement, a port-forward on the home gateway may still leave the service unreachable because the upstream network blocks it. A business plan from an Australian provider may offer a public IPv4 address, while a standard household plan may not. GUFW can protect the host, but it cannot remove CGNAT; contact the ISP when public inbound access is genuinely required. A VPN can provide a controlled alternative to public port exposure.
Inside the house, trust should be narrower than “anything on my Wi-Fi”. If a Samba share must be available only on a 192.168.1.0/24 LAN, allow port 445 from that subnet rather than from everywhere: sudo ufw allow from 192.168.1.0/24 to any port 445 proto tcp. Confirm the router’s actual subnet first, and avoid opening discovery protocols such as SSDP or mDNS to the internet. Guest devices and smart TVs should remain outside the rule. The same reasoning applies to printers and local media servers.
Australian-hosted servers need the same two-stage setup. An AWS instance in the Sydney ap-southeast-2 or Melbourne ap-southeast-4 region, or a DigitalOcean droplet in Sydney, normally has a provider security group in front of UFW. Permit the required traffic in the provider control panel and then repeat the narrow rule in GUFW. Apply provider rules first, then confirm the host still rejects unwanted traffic. For a small Australian business handling personal information, least privilege supports the Privacy Act 1988, but firewalls alone do not establish complete compliance.
Troubleshoot Access and Lockouts
When a service fails, identify the failed layer instead of deleting random rules. Check sudo ufw status verbose, inspect sudo ss -lntup, and read recent entries in /var/log/ufw.log with sudo tail -n 50 /var/log/ufw.log. If the application is not listening, the problem is local; if it listens locally but not remotely, inspect the UFW rule, router forwarding, and carrier NAT in that order. A test from a phone on mobile data is useful because it leaves the home LAN and its Wi-Fi clients behind. Packet drops and a closed application port are different symptoms.
Containers create a special case. Docker-compatible engines can publish ports through their own iptables rules, bypassing the normal UFW allow policy, so a service may appear blocked by GUFW yet remain reachable. Bind a development container to 127.0.0.1 instead of all interfaces, restrict publication with a provider firewall, or use the engine’s DOCKER-USER filtering mechanism. Test container bindings separately from host listening addresses. Flatpak application permissions form a separate sandbox and do not replace a host packet filter.
A lockout is usually caused by removing SSH access while connected remotely. Keep a second terminal open, and use the provider’s serial console for a cloud server or the physical keyboard for a local machine. From a console, sudo ufw disable is an emergency recovery step; add the required SSH rule, re-enable UFW, and confirm access before closing the console. Never disable UFW on a public server and leave it in that state. Reserve sudo ufw --force reset for a host that must be rebuilt from a known policy, because it discards custom rules. Restore normal protection immediately after recovery.
Review and Maintain Firewall Policy
Review the policy after every major service change and on a fixed schedule. In GUFW’s Rules tab, remove allowances for retired applications; at the terminal, locate a rule’s number with sudo ufw status numbered and delete it with sudo ufw delete 4, adjusting the number as the list changes. Keep the old rule until the replacement has been tested. A copy of /etc/ufw provides a simple rollback reference, although it should be stored securely and tested on a non-production machine.
Keep the firewall software and kernel current with sudo apt update and sudo apt upgrade, then reboot when a kernel update requests it. If an upgrade changes Wi-Fi, VPN, Ethernet adapter, or virtual-machine behaviour, consult the kernel compatibility guide before attributing the fault to UFW. Package upgrades can also add or replace service definitions, so compare sudo ufw status with the Rules tab after each significant update. Do not postpone security updates merely because a working desktop is convenient.
Finally, confirm that UFW is enabled, rules survive a reboot, and logging is appropriate for the machine. sudo systemctl enable ufw handles boot activation, while sudo ufw status verbose records the active defaults and rules. Moderate logging is useful on servers and low logging is quieter on everyday desktops. For a remote server, include the SSH or VPN rule in the reboot checklist. Open GUFW’s Rules tab and verify that every active allowance corresponds to a service you actually use.