主要命令

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. 面向对象设计:共性VS个性-------继承的粒度和聚合的粒度以及类的重构

    共性和个性 依据面向对象的原理.类是对象的抽象.也就是说.类是一系列的既有共性又有个性的对象的高度概括,类的属性和方法代表了隶属于该类的全部对象的共性,类的每一个对象实例都能够有不同的属性值,这反映了 ...

  2. CodeForces 16B Burglar and Matches(贪心)

    B. Burglar and Matches time limit per test 0.5 second memory limit per test 64 megabytes input stand ...

  3. express 与 mvc

    听人介绍,说express.js是一个for nodejs的mvc框架. 既然是MVC,那么,express里面,什么是M,什么是V,又什么是C? C,很容易看出来,就是路由.express的路由机制 ...

  4. 3736 【HR】万花丛中2

    3736 [HR]万花丛中2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description HR神犇在成功攻略ZX后,花心 ...

  5. 命令行下mysql的部分操作

    远程链接数据库: mysql –u用户名 [–h主机名或者IP地址] –p密码 (用户名是登录的用 户,主机名或者IP地址为可选项,如果是本地连接则不需要,远程连接需要填写,密码是对应用户的密码.) ...

  6. word文档在线预览解决方案

    花了一整天在网上翻关于 “word文档在线预览解决方案” 相关的资料,感觉实现难度比较大还是用PDF来解决好了.. 下面列一下比较好的参考资料吧 参考资料 前端实现在线预览pdf.word.xls.p ...

  7. Vue项目中如何使用less(添加less依赖)

    今天在新工程里添加了一段样式代码代码突然报错了: <!-- Add "scoped" attribute to limit CSS to this component onl ...

  8. 引水工程 Kruskal + Prim

    Kruskal题解 : 以案例输入为例 有五个缺水地区 , 这个个缺水地区之间建立联系的费用已经给出 并且之间水库的费用也已经给出 , 自己水库也已看为 是另一个 点 , 这样就有了 6 个点 , 这 ...

  9. Android内存管理(12)*「实例」用Monitor 生成.hprof文件 并分析内存泄漏

    参考 http://blog.csdn.net/xiaanming/article/details/42396507 基本步骤: 1,准备一个有内存泄漏的代码 2,如何发现内存泄漏 3,生成.hpro ...

  10. Android内存管理(11)*常见JVM回收机制「Java进程内存堆分代,JVM分代回收内存,三种垃圾回收器」

    参考: http://www.blogjava.net/rosen/archive/2010/05/21/321575.html 1,Java进程内存堆分代: 典型的JVM根据generation(代 ...