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
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to set up Apt caching server on Ubuntu or Debian - February 7, 2016
- How to monitor OpenFlow messages with packet sniffer - February 2, 2016
- How to search multiple pdf documents for words on Linux - January 13, 2016