iptables-save

iptables-save
网络

命令介绍

把当前 IPv4 防火墙规则打到标准输出。

语法

iptables-save [选项]

功能简介

iptables-save 把当前 IPv4 防火墙规则打到标准输出。重定向到文件,以后用 iptables-restore 读回来。

它输出的是完整表,包括 nat 和 mangle。只在屏幕上看时,用 less。保存的文件权限不要让别人改。

使用时注意

先把 -c、-t 表 用熟。换过发行版或版本之后,跑一次 iptables-save --help,确认这些开关还在。

参数说明

-c连计数器一起保存
-t 表只保存某一张表

经验技巧

  • 改规则前先 iptables-save 存一份。恢复用 iptables-restore,不要手敲回去。
  • 改规则之前先 iptables-save > 备份。回退比从记忆里重写快。

示例

iptables-save

把规则打到屏幕

iptables-save > /root/iptables.bak

做一份备份

iptables-restore < /root/iptables.bak

从备份恢复

iptables -S

想只看某一条写法时也可以用这个

相关命令

同分类

选项会随版本变化,以本机 man 手册为准。