How to Restoring iptables Automatically On Boot on Debian and Ubuntu

For some reason, Debian can’t do “/etc/init.d/iptables save”. There is no option in iptables which will make your rules permanent. But you can use iptables-save and iptables-restore to fulfill your task.


To save iptables rules to some file like /etc/iptables.rules using following command:
 
$ sudo iptables-save > /etc/iptables.rules

To make sure the iptables rules are started on a reboot we’ll create a new file: 

$ sudo vi /etc/network/if-pre-up.d/iptables

Add these lines to it: 

#!/bin/bash
iptables-restore < /etc/iptables.rules

Don’t forget to make it executable: 

$ sudo chmod +x /etc/network/if-pre-up.d/iptables

Other you can create the following if-up.d script called iptables that restores the saved iptables rule set.

$ sudo vi /etc/network/if-up.d/iptables
 
#!/bin/bash
iptables-restore < /etc/iptables.rules
 
$ sudo chmod +x /etc/network/if-up.d/iptables
 
Alternatively, you can add “iptables-restore < /etc/iptables.rules” command to /etc/rc.local, which gets executed at the end of system boot-up.
Add the following command in /etc/rc.local to reload the rules in every reboot.

$ sudo vi /etc/rc.local
 
iptables-restore < /etc/iptables.rules
Terima kasih telah membaca artikel tentang How to Restoring iptables Automatically On Boot on Debian and Ubuntu di blog Tutorial Opensource and Linux jika anda ingin menyebar luaskan artikel ini di mohon untuk mencantumkan link sebagai Sumbernya, dan bila artikel ini bermanfaat silakan bookmark halaman ini di web browser anda, dengan cara menekan Ctrl + D pada tombol keyboard anda.

Artikel terbaru :