Utility Command Reference

iptables comes with two utility commands for saving and restoring rule sets.

iptables-restore

iptables-restore
  [ -c | --counters ]
  [ -n | --noflush ]

Reads rules from standard input in the format written by iptables-save and adds those rules to the current iptables setup. Normally, tables are flushed before rules are restored into them, but you can use the -n (--noflush) option to have the new rules added to those already present. Table 1-85 describes the options to this command.

Table 1-85. iptables-restore options

Option

Description

-c

Restore the packet and byte counters for the rules.

--counters

Synonym for -c.

-n

Disable the preflushing of tables before restoration.

--noflush

Synonym for -n.

iptables-save

iptables-save
  [ -c | --counters ]
  [ [ -t | --table ] table ]

Displays rules and (optionally) byte and packet counts for all tables (the default) or for a specified table. The format is designed to be easy to parse and can be written to file for later restoration via iptables-restore. Table 1-86 describes the options to this command.

Table 1-86. iptables-save options

Option

Description

-c

Display the packet and byte counters for the rules.

--counters

Synonym for -c.

-t table

Display only the specified table.

--table

Synonym for -t.

Get Linux iptables Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.