If you have customized iptables rules, and would like to load the customized iptables rules persistently across reboots on Debian, you can leverage if-up.d scripts that are located in /etc/network/if-up.d. On Debian, any script that is marked as executable and placed in /etc/network/if-up.d gets executed when a network interface is brought up.
In order to run iptables automatically after reboot on Debian, do the following.
First, customize iptables as you wish, and then save the current iptables rule-set using iptables-save command.
The above command will dump the current iptables rule set into /etc/firewall.conf file which iptables-restore command can later use to restore the same rule set.
Now create the following if-up.d script called iptables that restores the saved iptables rule set.
#!/bin/sh iptables-restore < /etc/firewall.conf
Alternatively, you can add "iptables-restore < /etc/firewall.conf" command to /etc/rc.local, which gets executed at the end of system boot-up.
Subscribe to Xmodulo
You can have daily Linux tutorials and FAQs delivered to your email inbox. Simply enter your email address below to subscribe to our mailing list. You will receive hands-on guides and carefully written tutorials related to Linux, everything for free.