Why isn't the Iptables persistent service saving my changes?
iptables-persistent
does not work that way. Restarting the iptables-persistent
"service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.
To configure iptables-persistent
, you need to tell it about your current iptables ruleset.
One way to accomplish that is as follows:
iptables-save >/etc/iptables/rules.v4
ip6tables-save >/etc/iptables/rules.v6
Or, equivalently, the iptables-persistent
package also provides the following:
dpkg-reconfigure iptables-persistent
(You will need to answer yes to the questions about whether to save the rules.)
After that, the next time iptables-persistent
is started/restarted, the iptables rulesets you expect will be loaded.
Very simple way to save the current iptables rules is to use the command:
sudo service netfilter-persistent save
Using the above, which works at least in Ubuntu after installing the netfilter-persistent
(and iptables-persistent
) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).
Install iptables-persistent:
sudo apt install iptables-persistent
save rules after making desired changes:
sudo netfilter-persistent save