Pages

Thursday, March 18, 2010

Saving iptables rules

I have a set of iptables rules I wanted to restore automatically on reboot, here is how I got them to restore after reboot.


After setting my rules I ran this in a terminal


~$ sudo iptables-save >/etc/iptables.rules


 then I opened up /etc/network/interfaces in a text editor



~$ sudo gedit /etc/network/interfaces


I added this line   pre-up /sbin/iptables-restore < /etc/iptables.rules to /etc/network/interfaces


























After that I did a reboot and ran sudo iptables -L to make sure the rules were set.



I read a couple of different post and web pages to learn to set my rules for iptables. The first was from the ubuntu forums  another used was from linuxhomenetworking.com these were two that I bookmarked. Of course there is always "man iptables" in a terminal the man pages are quite helpful.