The Uncomplicated Firewall (UFW) is the default network firewall configuration tool on Ubuntu desktop and server systems. It provides an intuitive interface for managing iptables and nftables packet filtering rules. However, upon executing sudo ufw enable or rebooting your system, administrators frequently encounter a critical startup failure: Job for ufw.service failed because the control process exited with error code. See ‘systemctl status ufw.service’ and ‘journalctl -xeu ufw.service’ for details.
When UFW fails to start, your server or desktop is left without active firewall boundaries or may refuse to apply newly defined port-forwarding and NAT policies. This failure is predominantly triggered by syntax errors inside custom configuration files (such as /etc/ufw/before.rules), conflicts between legacy iptables and modern nftables backends, or missing kernel netfilter modules on virtualized VPS hosts. Follow this guide to resolve UFW service failures.
Inspect Service Error Logs with journalctl
To determine the exact underlying reason why systemd failed to start the UFW daemon, query the systemd unit journal:
systemctl status ufw.service
journalctl -xeu ufw.service
Carefully scan the terminal output for messages such as: “iptables-restore: line XX failed” or “Problem running ‘/etc/ufw/before.rules'”. In the majority of instances, the journal explicitly cites the exact configuration file and line number containing an invalid firewall parameter.
Validate Syntax in /etc/ufw/before.rules and user.rules
If you recently added custom NAT masquerading rules, port redirection, or Docker bridges, an unclosed bracket, missing table declaration, or typographical error in before.rules will halt the entire parser:
- Open the before-rules file in
nano:sudo nano /etc/ufw/before.rules - Verify that any custom
*nattable configuration ends with a mandatoryCOMMITdirective before the standard*filtertable begins:*nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE COMMIT - Check that no unsupported command-line arguments exist.
- Save changes (Ctrl + O) and exit (Ctrl + X).
Switch Between iptables-legacy and iptables-nft
Modern Ubuntu installations (20.04 LTS, 22.04 LTS, and 24.04 LTS) use nftables as the default packet filtering framework via the iptables-nft translation layer. If third-party software (such as Docker, Kubernetes, or Fail2ban) configured legacy netfilter rules, backend mismatches crash UFW:
- Check the current active iptables alternative:
sudo update-alternatives --display iptables - Switch to the legacy iptables backend:
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy - Attempt to start UFW:
sudo systemctl restart ufw.service - If your system requires modern nftables, you can revert using
update-alternatives --set iptables /usr/sbin/iptables-nft.
Reset UFW to Default Factory Rules
If corrupted custom rules are tangled across multiple configuration manifests, resetting UFW restores pristine default firewall policies without uninstalling packages:
- Reset the firewall rules:
sudo ufw reset - When prompted with “Resetting all rules to installed defaults. Proceed with operation (y|n)?”, type
yand press Enter. - Enable basic secure defaults (deny inbound, allow outbound):
sudo ufw default deny incoming sudo ufw default allow outgoing - Crucially, if managing a remote server over SSH, allow your SSH port before enabling:
sudo ufw allow 22/tcp - Enable UFW and verify active status:
sudo ufw enable sudo ufw status verbose