主要命令

iptables-save| awk ' !x[$0]++ | iptables-restore

演示:

[root@testname ~]# iptables -vL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
761 47910 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- any any anywhere anywhere
282 16920 ACCEPT all -- lo any anywhere anywhere
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh
16 1852 REJECT all -- any any anywhere anywhere reject-with icmp-host-prohibited
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:rap-listen
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpts:x11:x11-ssh-offset
0 0 ACCEPT udp -- any any anywhere anywhere state NEW udp dpt:xdmcp
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:50001
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpts:bmcpatrolagent:csvr-proxy
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpts:13700:13800 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- any any anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 938 packets, 74222 bytes)
pkts bytes target prot opt in out source destination [root@testname ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1531 -j ACCEPT
[root@testname ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 6000:6010 -j ACCEPT
[root@testname ~]# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 177 -j ACCEPT
[root@testname ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 50001 -j ACCEPT
[root@testname ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3181:3190 -j ACCEPT
[root@testname ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 13700:13800 -j ACCEPT [root@testname ~]# iptables-save
# Generated by iptables-save v1.4.7 on Sun Jun 21 19:59:46 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [28:5520]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp -m state --state NEW -m tcp --dport 1531 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6000:6010 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 177 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 50001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3181:3190 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 13700:13800 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 1531 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6000:6010 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 177 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 50001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3181:3190 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 13700:13800 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sun Jun 21 19:59:46 2015 [root@testname ~]# iptables-save| awk ' !x[$0]++' | iptables-restore [root@testname ~]# iptables-save
# Generated by iptables-save v1.4.7 on Sun Jun 21 20:01:09 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5:636]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp -m state --state NEW -m tcp --dport 1531 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6000:6010 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 177 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 50001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3181:3190 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 13700:13800 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sun Jun 21 20:01:09 2015

How To:防火墙规则去重的更多相关文章

  1. [moka同学摘录]iptables防火墙规则的添加、删除、修改、保存

    文章来源:http://www.splaybow.com/post/iptables-rule-add-delete-modify-save.html 本文介绍iptables这个Linux下最强大的 ...

  2. OpenStack 的防火墙规则流程

    Contents [hide] 1 发现的问题 2 解决过程 3 删除临时错误数据 4 其实前面的解决办法是错的 发现的问题 3台虚拟机在同一宿主机,防火墙配置都一样,但是他们的网络表现不一致,有的能 ...

  3. 保存iptables的防火墙规则的方法【转载】

    转自: 保存iptables的防火墙规则的方法 - 51CTO.COMhttp://os.51cto.com/art/201103/249504.htm 保存iptables的防火墙规则的方法如下: ...

  4. CentOS6.7 防火墙规则(Iptables)

    查看防火墙的状态 /etc/init.d/iptables status 开启防火墙 /etc/init.d/iptables start 关闭防火墙 /etc/init.d/iptables sto ...

  5. CentOS7 防火墙规则 (firewalld)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  6. pfSense配置基于时间的防火墙规则

    基于时间的规则允许防火墙规则在指定的日期和/或时间范围内激活.基于时间的规则与任何其他规则的功能相同,只是它们在预定时间之外的规则集中实际上不存在. 基于时间的规则逻辑处理基于时间的规则时,调度计划确 ...

  7. CMD命令行netsh添加防火墙规则

    1.为e:\f.exe 添加防火墙规则(参考:https://www.cnblogs.com/zhen656/p/4275270.html),需要管理员权限. >netsh advfirewal ...

  8. fedora 28 , firewalld 防火墙控制,firewall-cmd 管理防火墙规则

    今天,在使用fedora时,需要修改防火墙规则,一时间忘记了命令是什么,这里进行记录一下. 目前 fedora 28/ centos 7 使用 firewalld 作为防火墙软件:下面我就怎么简单管理 ...

  9. Linux防火墙基础与编写防火墙规则

    Iptables采用了表和链的分层结构,每个规则表相当于内核空间的一个容器,根据规则集的不同用途划分为默认的四个表,raw表,mangle表,nat表,filter表,每个表容器内包括不同的规则链,根 ...

随机推荐

  1. cc2540 usbdongle 安装驱动失败的终极解决方法 【原创,多图】

    Ghost winxp win7系统安装CC2540 usbdongle CDC驱动程序 [重要提示] 因为非常多朋友使用Ghost系统.导致安装cdc驱动时安装不成功,出现 "INF中的服 ...

  2. configure: error: mysql configure failed. Please check config.log for more information.

    为php添加mysql模块时报错 configure: error: mysql configure failed. Please check config.log for more informat ...

  3. css list menu

    选择让page和folder都显示出来

  4. ssh连接超时问题解决方案,每一种方案都可以

    1.服务端修改 vim /etc/ssh/sshd_config 修改 ClientAliveInterval 60 ClientAliveCountMax 40 60秒,向客户端发送一次请求. 超过 ...

  5. hdu 1512 Monkey King —— 左偏树

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1512 很简单的左偏树: 但突然对 rt 的关系感到混乱,改了半天才弄对: 注意是多组数据! #includ ...

  6. oracle数据库简单操作

    导入某用户所有表和数据:imp sgp/sgp@192.168.0.99:1521/orcl file=sgp20161025.dmp full=y 导出指定表及数据:exp sgp/sgp@192. ...

  7. discuz的全局变量

    $_G 保存了 discuz! 中所有的预处理数据 缓存能够很好的提高程序的性能,一些配置数据没必要每次都查询数据库,只要在修改了的时候更新下缓存即可. Discuz! 中所有的缓存保存在 $_G[c ...

  8. 最全的C/C++入门到进阶的书籍推荐,你需要嘛?

    编程是操作性很强的一门知识,看书少不了,但只有学习和实践相结合才能起到很好的效果,一种学习方法是看视频->看书->研究书中例子->自己做些东西->交流->看书. 研究经典 ...

  9. Java中从控制台输入的三种方式

    我们最熟悉的从控制台读取一个字符或者一个字符串都知道用Scanner,那么除了Scanner还有没有其他的呢,答案是有的,我们来看看. System.in.read() System.in.read( ...

  10. Ansible+Jenkins+Gitlab搭建及配置

    Ansible+Jenkins+Gitlab搭建及配置,已经生产环境使用,运行良好. 主机组文件里面好多ip敏感信息就不写了