In this post we will learn, how to backup and restore iptables on Linux systems .As a Linux System Administrator,it is important to understand iptables. With iptables,you can secure the Linux Operating System.In this post,we have written a quick way to take backup and restore the iptables in Linux systems.
iptables is a user space application and it is a kernel-level component.iptables is very useful to control the network packets.In other words,it works as firewall for the Operating System. iptables apply to IPv4,IPv6,ebtables and ARP.
In 2.4 kernel iptables was introduced.(iptables also called as netfilter), which is similar to ipchains(Before Kernel 2.4 version,ipchains was in use).
Taking the backup of iptables is good idea.This practical applies to Red Hat and Debian based Operating System.(Read our various posts on iptables)
Note: To do backup and restore of iptables,the user must be root
How to take backup of iptables
To take the backup of iptables,use the following command.In below given syntax ,we are saving iptables backup in file called iptables.backup (You can change the iptable backup file name) . Never save it in /tmp ,even for a short time,it is bad practice.
iptables-save > /opt/iptables.backup
How to restore iptables from backup file
Use below given syntax,to restore the iptables back to Linux System.In this example,we are using same iptable backup file,which we have taken in above section (i.e iptables-save > /opt/iptables.backup
)
iptables-restore < /opt/iptables.backup
Note: As Linux System Administrator,it is recommended to use the iptables.It helps to secure the Operating System.Before applying any new iptable,actually it is also new for you.Always check it in test machine before applying to live server.
A nice tutorial. On my system I just got an empty file when running iptables.
I have used ufw and gufw and it seems they do not use iptables directly otherwise there would have been some entries in the iptables
Simple and very good, Thanks for the post