iptables-save command in Linux with examples
Last Updated :
09 Apr, 2024
The information transfer from a remote computer to your local computer and the vice-versa are viewed as the transfer of data packets by the firewall. The firewall has the control of data packets that are both incoming and outgoing.iptables is a utility to create a rule-based firewall that is pre-installed in most of the Linux computers. iptables command talks to the kernel and helps to control the data packets that use IPv4 protocol as the packet-switching protocol. Since firewall works in kernel level, to use the iptables command, root privilege is required. By default the firewall runs without any rules. The below example shows how to list the rules.
iptables -L -n -v

This example shows how to block all INPUT chain connections from the IP address
10.10.10.10.
iptables -A INPUT -s 10.10.10.10 -j DROP

Whenever the computer is rebooted or restarted, the iptables service and the existing rules are flushed out or reset. Hence, the above rule will be discarded by the computer if the computer gets restarted. To prevent such customized rules from getting scrapped, below command is used. It saves the rules automatically whereas it can also be manually stored in a user-specified file and can be reused later.
iptables-save

Now, even if the computer is restarted, the rules that you saved will be loaded automatically. The screenshot after rebooting the computer.

If the rules are not needed once the computer is restarted or if the purpose is to flush all the rules once the system is rebooted, iptables-save is of no use. As discussed earlier, the user can use iptables-save command which will save the current iptables rules in a user specified file, that can be used later when the user wants. The following example saves the rules in /etc/iptablesRule.v4.
iptables-save > /etc/iptablesRule.v4

Even after restarting the computer the following example helps to reload the rules from the saved file.
iptables-restore < /etc/iptablesRule.v4

The following holds the meaning for options.
iptables-save [-c] [-t table]
The -c argument tells iptables-save helps to keep track of the byte and packet counter values when the rule is issued. This helps in resuming the packet transfer from where the rule was previously established. Hence, it is useful in maintaining continuity. The default value is, of course, to not keep the counters intact when issuing this command. The -t argument tells the iptables-save command which tables to save that contains specific rules and chains. By default, all the tables are saved.
Similar Reads
ifup command in Linux with Examples The 'ifup' command in Linux is essential for managing network interfaces, allowing them to transmit and receive data by bringing them up. This command is typically used in conjunction with network configuration files, specifically '/etc/network/interfaces', which contain the necessary definitions fo
3 min read
import command in Linux with Examples import command in Linux system is used for capturing a screenshot for any of the active pages we have and it gives the output as an image file. You can capture a single window if you want or you can take the entire screen or you can take a screenshot of any rectangular portion of the screen. Here, w
4 min read
info command in Linux with Examples info command reads documentation in the info format. It will give detailed information for a command when compared with the man page. The pages are made using the Texinfo tools which can link with other pages, create menus, and easy navigation. Here, we will explore the functionality of the info com
3 min read
insmod command in Linux with examples insmod command in Linux systems is used to insert modules into the kernel. Linux is an Operating System that allows the user to load kernel modules on run time to extend the kernel functionalities. LKMs(Loadable Kernel Modules) are usually used to add support for new hardware (as device drivers) and
3 min read
install command in Linux with examples The 'install' command in Linux is a versatile tool used for copying files and setting their attributes, such as permissions, ownership, and group. Unlike commands like 'cp' that simply copy files, 'install' allows you to fine-tune these settings, making it ideal for installation scripts or manual fi
3 min read
iostat command in Linux with examples The iostat command in Linux is used for monitoring system input/output statistics for devices and partitions. It monitors system input/output by observing the time the devices are active in relation to their average transfer rates. The iostat produce reports may be used to change the system configur
8 min read
iotop Command in Linux with Examples The 'iotop' command is a powerful Linux tool designed for monitoring disk Input/Output (IO) usage in real-time. It provides a comprehensive view of the current disk IO activities by processes, making it invaluable for system administrators who need to track down processes that are causing high disk
3 min read
ip Command in Linux with Examples The ip command in Linux is a powerful utility for network configuration and management. It allows users to interact with various networking components such as network interfaces, routing tables, addresses, and more. Here, we will look into the 'ip' command, covering each aspect with examples, code,
7 min read
ipcrm command in Linux with examples ipcrm command in Linux is used to remove some IPC(Inter-Process Communication) resources. It eliminates the IPC objects and their associated data structure form the system. One must be a creator or superuser or the owner of the object in order to remove these objects. There are three types of System
2 min read
'IPCS' command in Linux with examples ipcs shows information on the inter-process communication facilities for which the calling process has read access. By default, it shows information about all three resources: shared memory segments, message queues, and semaphore arrays. Without options, the information shall be written in short for
3 min read