iptables is a user space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different Netfilter modules) and the chains and rules it stores. Different kernel modules and programs are currently used for different protocols; iptables applies to IPv4, ip6tables to IPv6, arptables to ARP, and ebtables to Ethernet frames.
I am using Ubuntu LTS 12.04. Follow the steps bellow to make iptables rules persistent after a reboot.
To view actual rules, issue this command:
The output will look like this:
Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
Saving iptables rules in a file:
iptables-save > /etc/iptables.rules
To make sure that the rules are applied at boot, we will create a new file
#!/bin/bash /sbin/iptables-restore < /etc/iptables.rules exit 0
This will load the configuration when the network interface is up.
We can do the same to save the iptables configuration automatically on shutdown by creating the following file
#!/bin/sh iptables-save > /etc/iptables.rules exit 0
Changing the permission so the files can be executed
chmod +x /etc/network/if-down.d/saveiptables chmod +x /etc/network/if-up.d/loadiptables
Hope you found this tutorial useful.