Out of the box, any changes you make to your iptables
on Linux will be discarded on reboot. That might not always be desirable. There’s a package sitting in the repos for Ubuntu that allows your changes to persist.
sudo apt install iptables-persistent
On install it offers the option to save the current iptables configuration. The config gets saved in /etc/iptables/rules.v4
(and rules.v6 for ipv6).
You can save any further rule changes using iptables-save, which spits out the entire ruleset on stdout. A quick way to save your rule changes forever:
iptables-save > /etc/iptables/rules.v4
Simple!
(copied from my old site)