Sub topic 7
Firewall and network tooling differences
This chapter assumes you can use a Linux shell and know what a firewall does. It also assumes you have read the earlier chapters on distribution families and package management. The chapter compares what each distribution ships for packet filtering and network configuration. It also covers how to read and change that configuration safely.
What you get out of the box
Ubuntu Server, Debian, and Rocky Linux all use the kernel's netfilter packet filter. They differ in the front end, the tool you type commands into. They also differ in whether that front end is turned on, and in which tool owns the IP address configuration.
| Area | Ubuntu Server | Debian | Rocky Linux |
|---|---|---|---|
| Firewall front end | `ufw`, installed but inactive | None enabled. `nftables` and `iptables` are available | `firewalld`, installed and running |
| Default inbound posture | Everything allowed until `ufw` is enabled | Everything allowed | Zone `public`: only a few services allowed |
| Network configuration | Netplan, rendering to `systemd-networkd` | `ifupdown` (`/etc/network/interfaces`) on a standard install | NetworkManager (`nmcli`) |
| Config location | `/etc/netplan/*.yaml` | `/etc/network/interfaces` | `/etc/NetworkManager/system-connections/` |
Debian and Rocky details can vary by release and install method. Check what your host actually runs before you assume.
A freshly installed Ubuntu or Debian server accepts connections on every port that a service listens on. A freshly installed Rocky server drops most of them. This difference causes the most common surprise when people move between families. On Rocky, you install a web server, start it, and cannot reach it from another machine. On Ubuntu or Debian, the same steps work, but the service is exposed to the network until you add rules.
The packet filter underneath
Modern kernels use nftables, the successor to the older iptables system. The front ends differ in how they reach it:
firewalldon Rocky uses nftables as its backend.ufwon Ubuntu generates rules through theiptablescommand. On current releases that command isiptables-nft, a compatibility layer that stores the rules in nftables.- Debian uses nftables as the default framework. The
iptablescommand there is also a compatibility layer, selected through thealternativessystem.
You can inspect the real ruleset on any of the three, whatever front end created it:
sudo nft list rulesetIf the output is empty on Debian, no firewall is configured. On Rocky or Ubuntu with an active firewall, you will see tables and chains that the front end generated. Do not edit those by hand. The front end rewrites them on reload and discards your changes.
ufw on Ubuntu
ufw (Uncomplicated Firewall) is a thin front end with simple syntax. The installed default policy is "deny incoming, allow outgoing", but it does nothing until you enable it. Always allow SSH before you enable it, or you can lock yourself out of a remote machine:
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status verboseRules take effect immediately and persist across reboots. There is no separate runtime and permanent state. You can also allow by application profile (sudo ufw allow "Nginx Full"), which reads definitions from /etc/ufw/applications.d/. Many packages install such profiles.
ufw works on a single flat list of rules. It has no zones. That is enough for a single-purpose server. It gets awkward on a host with several network interfaces that need different trust levels.
firewalld on Rocky Linux
firewalld is a daemon that organizes rules into zones. A zone is a named trust level that you assign to interfaces or source addresses. The default zone is public, which allows only a handful of services, including ssh. Rules apply to the zone, not the host as a whole.
The most important concept is the split between runtime and permanent configuration. A command without --permanent changes the running firewall and is lost on reload or reboot. A command with --permanent changes the saved config but does not affect the running firewall until you reload:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reloadFor a quick test, add the rule without --permanent. If it works, make it permanent. A mistake then disappears on the next reload. These commands show the current state:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --list-allServices are named bundles of ports, such as http or https. For a port with no service definition, use --add-port=8080/tcp. Service definitions live in /usr/lib/firewalld/services/. Your own definitions go in /etc/firewalld/services/.
The same tasks side by side
| Task | Ubuntu (ufw) | Rocky (firewalld) |
|---|---|---|
| Open SSH | `ufw allow 22/tcp` | `firewall-cmd --permanent --add-service=ssh` |
| Open a custom port | `ufw allow 8080/tcp` | `firewall-cmd --permanent --add-port=8080/tcp` |
| Allow from one subnet | `ufw allow from 10.0.0.0/24 to any port 5432 proto tcp` | `firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/24" port port="5432" protocol="tcp" accept'` |
| Apply saved changes | Automatic | `firewall-cmd --reload` |
| Show rules | `ufw status numbered` | `firewall-cmd --list-all` |
| Remove a rule | `ufw delete allow 8080/tcp` | `firewall-cmd --permanent --remove-port=8080/tcp` |
Debian has no entry in this table because it ships no default front end. You have three realistic options:
- Install
ufwwithapt install ufw. It behaves as described above. - Install
firewalldwithapt install firewalld. It also behaves as described above. - Write a ruleset in
/etc/nftables.confand enable thenftablesservice.
Option 3 gives you full control and no extra daemon. You write the rules yourself, so the ruleset is only as safe as you make it. Here is a minimal, complete example:
sudo tee /etc/nftables.conf >/dev/null <<'EOF'
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iif lo accept
ct state established,related accept
ip protocol icmp accept
ip6 nexthdr icmpv6 accept
tcp dport 22 accept
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
EOF
sudo nft -c -f /etc/nftables.conf
sudo systemctl enable --now nftablesThe nft -c command checks the syntax without loading the file. Run it before you enable the service. A default-drop policy that lacks an SSH rule will cut off your session.
Container software and firewall rules
Docker and Podman manage their own netfilter rules. Docker publishes container ports by inserting rules that run before the ones ufw creates. A container started with -p 8080:80 can be reachable from outside even when ufw has no rule for port 8080. Treat ufw status as incomplete on any host that runs Docker. Check the real ruleset with nft list ruleset, and bind published ports to localhost (-p 127.0.0.1:8080:80) when they should not be public.
On Rocky, firewalld has direct support for Podman and its own docker zone. Even so, check which zone the container bridge ends up in, and what forwarding or masquerading rules apply.
Network configuration tools
The firewall decides what traffic is allowed. The network tool decides which addresses, routes, and DNS servers the machine uses. Three tools appear across the three distributions.
Netplan on Ubuntu
Netplan reads YAML files in /etc/netplan/ and writes configuration for a back end. On Ubuntu Server the back end is systemd-networkd. Cloud images usually get their file from cloud-init, so editing it by hand can be overwritten at the next boot unless you disable cloud-init's network handling. A static address looks like this:
network:
version: 2
ethernets:
ens18:
dhcp4: false
addresses: [192.0.2.10/24]
routes:
- to: default
via: 192.0.2.1
nameservers:
addresses: [192.0.2.53]Apply it with sudo netplan try. This command applies the change and reverts it automatically after 120 seconds unless you confirm. That protects you from losing remote access through a bad address. Use sudo netplan apply only when you can reach the console. YAML is strict about indentation, and Netplan warns when the file is readable by other users. Set it to chmod 600.
ifupdown on Debian
A standard Debian server install uses /etc/network/interfaces. The format is plain text, one stanza per interface:
auto ens18
iface ens18 inet static
address 192.0.2.10/24
gateway 192.0.2.1
dns-nameservers 192.0.2.53The dns-nameservers line only works when the resolvconf package is installed. Otherwise you edit /etc/resolv.conf or use systemd-resolved. ifupdown has no transactional apply. Restarting networking on a remote host can drop your session, so schedule a console-accessible window. Debian also supports systemd-networkd and NetworkManager, and they are common on images built for cloud use. Run systemctl is-active NetworkManager systemd-networkd networking to see which one is actually active.
NetworkManager on Rocky
Rocky uses NetworkManager and manages it with nmcli. Each interface has a connection profile, a saved set of settings. You modify the profile and then bring it up:
sudo nmcli connection modify ens18 \
ipv4.method manual \
ipv4.addresses 192.0.2.10/24 \
ipv4.gateway 192.0.2.1 \
ipv4.dns 192.0.2.53
sudo nmcli connection up ens18On Rocky 8, profiles are stored as ifcfg files under /etc/sysconfig/network-scripts/. Rocky 9 stores them as keyfiles in /etc/NetworkManager/system-connections/. The nmcli commands work the same for both.
Everyday inspection tools
These commands behave identically on all three and read the live kernel state, so they are the right first stop when something is broken:
ip -br address
ip route
ss -tulpn
resolvectl statusss -tulpn lists listening sockets and the processes that own them. Use it to compare "what is listening" with "what the firewall allows". resolvectl works only where systemd-resolved runs. That is the default on Ubuntu. It is optional on Debian and Rocky.
Diagnosing a connection that fails
When a client cannot reach a service, check the layers in order:
- Is the service listening? Run
ss -tulpn | grep PORTon the server. - Is the firewall allowing it? Use
ufw status,firewall-cmd --list-all, ornft list ruleset. - Is a mandatory access control denial involved? On Rocky, a service bound to a non-standard port can be blocked by SELinux while the firewall is open. The previous chapter covers that.
- Is the address and route correct? Use
ip -br addressandip route.
Steps 1 and 2 account for most reports. On Rocky, the usual cause is a service that is running but absent from the active zone. On Ubuntu with ufw enabled, it is a missing allow rule.
Choosing between them
- If you want the firewall protecting a new server from the first boot, Rocky's default is stricter. You still have to open services deliberately.
- If your team writes automation, note how each tool handles state.
ufwis simple to script.firewalldneeds runtime and permanent handling. Netplan and NetworkManager both have configuration-management modules. - If you run complex multi-interface hosts,
firewalldzones fit better than a flatufwlist. - If you want minimal moving parts, Debian with a hand-written nftables file has the fewest components. It also puts all responsibility on you.
Mixing front ends on one host causes trouble. Running ufw and firewalld together, or editing nftables by hand beneath either, produces rules that no single tool describes. Pick one and remove the others.
Exercise
You install nginx on a new Rocky Linux server and start it. A browser on another machine cannot connect, but curl localhost on the server works. Which command pair fixes this permanently, and why is the second command needed?
Show answer
Run sudo firewall-cmd --permanent --add-service=http followed by sudo firewall-cmd --reload. The --permanent flag writes the rule to the saved configuration only. It does not change the running firewall. The reload loads the saved configuration into the running one, so the rule takes effect now and also survives a reboot. The server works locally because the default zone blocks only inbound traffic from other machines.
Exercise
On an Ubuntu server you ran sudo ufw enable over SSH and your session froze. What did you probably skip, and which Netplan command would protect you from a similar lockout when changing the IP address?
Show answer
You probably did not allow SSH first, so the default deny rule blocked your own session. Run sudo ufw allow 22/tcp before enabling. For Netplan, use sudo netplan try, which reverts the change after a timeout unless you confirm it.