Making iptables rules persistent in Ubuntu
I’m pretty sure canonical had its reasons to make ubuntu iptables rules non-persistent by default. I can imagine situation when playing with rules could result in forcing yourself out of ssh connection. But, this non-persistence is annoying when you have rules set up the way you want it…
Fortunately it is very easy to “fix” this.
We will use iptables-save and iptables-restore.
1 2 3 |
sudo su touch /etc/iptables.conf iptables-save > /etc/iptables.conf |
Now edit /etc/rc.local (this file runs on boot, we will use it to restore iptables rules on start)
Before exit 0 add:
1 |
iptables-restore < /etc/itpables.conf |
And that’s it.
p.s. Every time you add new rules, don’t forget to save them:
1 |
iptables-save > /etc/iptables.conf |
Leave a Reply