Keep iptables rules after reboot
The iptables command on Linux allows setting the rules for the Linux built-in firewall to follow when filtering packets flowing through the system. The iptables command applies to IPv4 packets and the ip6tables applies to IPv6 packets. When you make modifications to your set up you can save them using the iptables-save command for IPv4 rules and ip6tables-save for IPv6 rules:
In Debian or Ubuntu systems you would therefore do this for IPv4:
And this for IPv6:
And the same for RedHat Enterprise Linux or CentOS:
Then you would use the iptables-restore command to restore the saved rules:
Manually restoring your own rules every time you boot the system may be a chore. Luckily there is an easy way to do this automatically. On Debian or Ubuntu just use the iptables-persistent package:
If you saved your rules in /etc/iptables/rules.v4 as specified above they will load automatically on every boot.
For RHEL or CentOS systems you can simply enable the iptables service:
And make sure your rules are saved:
The iptables command on Linux allows setting the rules for the Linux built-in firewall to follow when filtering packets flowing through the system. The iptables command applies to IPv4 packets and the ip6tables applies to IPv6 packets. When you make modifications to your set up you can save them using the iptables-save command for IPv4 rules and ip6tables-save for IPv6 rules:
In Debian or Ubuntu systems you would therefore do this for IPv4:
And this for IPv6:
And the same for RedHat Enterprise Linux or CentOS:
Then you would use the iptables-restore command to restore the saved rules:
Manually restoring your own rules every time you boot the system may be a chore. Luckily there is an easy way to do this automatically. On Debian or Ubuntu just use the iptables-persistent package:
If you saved your rules in /etc/iptables/rules.v4 as specified above they will load automatically on every boot.
For RHEL or CentOS systems you can simply enable the iptables service:
And make sure your rules are saved: