iptables-restore command in Linux with examples
Last Updated :
10 Sep, 2024
The iptables-restore and ip6tables-restore commands are essential tools for managing IP and IPv6 tables in Linux. These commands are used to restore firewall rules from a specified file or directly from the standard input (STDIN). This feature is particularly useful for system administrators who need to quickly apply saved firewall configurations during system startup or after making changes to the network security setup.
Syntax:
iptables-restore [-chntv] [-M modprobe] [-T name] [file]
ip6tables-restore [-chntv] [-M modprobe] [-T name] [file]
Options for iptables-restore and ip6tables-restore
- -c, --counters: This option restores the values of all packet and byte counters.
- -h, --help: This option prints a short option summary.
- -n, --noflush: This option doesn't flush the previous contents of the table. If it is not specified, both the commands flush (delete) all previous contents of the respective table.
- -t, --test: This option only parses and constructs the ruleset, but do not commit it.
- -v, --verbose: This option prints additional debug info during ruleset processing.
- -M, --modprobe modprobe_program: This option Specifies the path to the modprobe program. By default, the iptables-restore will going to inspect '/proc/sys/kernel/modprobe' to determine the executable's path.
- -T, --table name: This option restores only the named table even if the input stream contains other ones.
iptables-restore command Example in Linux
1. Create a new 'iptable' which helps in restoring.
Before restoring rules, it's a good practice to save the current firewall configuration. You can do this with the 'iptables-save' command:

This command saves the current IP tables to a file named 'iptables.rules', which can be restored later using 'iptables-restore'.
2. It will create a new file named 'iptableslist.txt'. To see the contents of file run the following command on the terminal:

3. The content of the file is:

4. Now the last step is to restore from that file we just created. We can simply restore 'iptables' using the following command.

Conclusion
The 'iptables-restore' and 'ip6tables-restore' commands are powerful tools for managing firewall configurations in Linux. By allowing system administrators to restore IP and IPv6 tables from saved configurations, these commands simplify the process of applying complex firewall rules, enhance system security, and ensure consistency across reboots.
Similar Reads
iptables-save command in Linux with examples 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-ins
3 min read
iptables command in Linux with Examples The iptables command in Linux is a powerful tool that is used for managing the firewall rules and network traffic. It facilitates allowing the administrators to configure rules that help how packets are filtered, translated, or forwarded. On using this iptables, you can set up security policies to c
7 min read
restore command in Linux with Examples restore command in Linux system is used for restoring files from a backup created using dump. The restore command performs the exact inverse function of dump. A full backup of a file system is being restored and subsequent incremental backups layered is being kept on top of it. Single files and dire
5 min read
reset command in Linux with Examples reset command in the Linux system is used to initialize the terminal. This is useful once a program dies leaving a terminal in an abnormal state. Note that you may have to type reset to get the terminal up and work, as carriage-return may no longer work in the abnormal state. Also, the terminal will
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