arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save iptables on Linux
#2
I find it very difficult to believe that there was no useful information on this subject when you did a search on Google and similar search engines.

When it comes to iptables, I can think of 2 methods:
  • iptables-save & iptables-restore (manual method, can be automated through cronjob)
  • iptables-persistent (automated method)


iptables-save & iptables-restore

iptables-save
iptables-save > /etc/iptables/rules.v4 (Debian/Ubuntu)
iptables-save > /etc/sysconfig/iptables (RHEL/CentOS)
ip6tables-save > /etc/iptables/rules.v6 (IPv6 Debian/Ubuntu)
ip6tables-save > /etc/sysconfig/ip6tables (IPv6 RHEL/CentOS)

iptables-restore
iptables-restore > /etc/iptables/rules.v4 (Debian/Ubuntu)
iptables-restore > /etc/sysconfig/iptables (RHEL/CentOS)
ip6tables-restore > /etc/iptables/rules.v6 (IPv6 Debian/Ubuntu)
ip6tables-restore > /etc/sysconfig/ip6tables (IPv6 RHEL/CentOS)

To automate this you have to create a cronjob that runs the iptables-restore commands at boot/reboot to load the rules. Don't forget to always save your rules when you add new rules or modify existing rules.


iptables-persistent

iptables-persistent is a software package that you can install with your package manager. It also has a save command that will automatically save IPv4 and IPv6 rules. With this solution you don't require any cronjob to restore the rules. The software will do it for you automatically on boot/reboot.

References

For CentOS 7 and above you no longer really use iptables because RHEL 7 and above comes with firewalld.

To save rules in firewalld you simply add the permanent flag/option to your command.

Example:
firewall-cmd --zone=public --add-port=80/tcp --permanent

After that reload the rules to apply the rule as it is not instantly applied like with iptables:
firewall-cmd --reload

Of course you can actually disable firewalld and use iptables: https://serverfault.com/a/739465
[Image: zHHqO5Q.png]


Messages In This Thread
Save iptables on Linux - by hamed - 06-25-2020, 09:14 AM
RE: Save iptables on Linux - by Mashiro - 06-25-2020, 03:05 PM
RE: Save iptables on Linux - by humanpuff69 - 06-26-2020, 02:00 PM


person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting