EDIT: Newer versions of RHEL use firewalld
by default, which is also available in Ubuntu.
If you would like your Ubuntu firewall to function in a similar way to RedHat/Fedora, in Ubuntu 18.04 20.04 22.04, you probably want these:
sudo apt install iptables-persistent netfilter-persistent
Then edit the rules in /etc/iptables/rules.v[46]
Other commands that might be useful:
netfilter-persistent save
netfilter-persistent start
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
systemctl stop netfilter-persistent
systemctl start netfilter-persistent
systemctl restart netfilter-persistent
If you ever find that your rules aren't correctly applied at boot, you can run these commands to test that there are not errors in your config files:
iptables-restore < /etc/iptables/rules.v4
ip6tables-restore < /etc/iptables/rules.v6
The two packages are similar, but provide slightly different functionality. If you only install iptables-persistent
, you won't get the service definition file for correct handling in systemd, eg /lib/systemd/system/netfilter-persistent.service
If you only install netfilter-persistent
, you will find that rules are not correctly applied at boot, as per the README
netfilter-persistent and its plugins
------------------------------------
netfilter-persistent does no work on its own. You need the accompanying
plugins (for example, iptables-persistent) to load and save filter rules.
However, commands are run from netfilter-persistent. For example, to save
all filter rules:
netfilter-persistent save
or to load them:
netfilter-persistent start
For more details, see `man netfilter-persistent`.
The system service will try to load rules at startup if enabled, but by
default it will not flush rules at shutdown. This behaviour can be changed
by editing /etc/default/netfilter-persistent.