主要命令

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. 斯坦福《机器学习》Lesson8感想-------1、SMO

    从上一篇文章可知支持向量(supervector)就是指的离分隔超平面近期的那些点.整个SVM最须要的步骤是训练分类器.得到alpha,从而得到整个用于数据分类的分隔超平面.支持向量机(super v ...

  2. 西门子TCP/UDPport

    通过TCP和UDP数据传输的不同服务用到了哪些port? func=ll&objid=21874445&nodeid0=10806074&load=treecontent&am ...

  3. 为什么使用 use strict

    进入标志: "use script"; 使用方式: 可以在 js 代码的第一行,也可以使用在函数中.但是写在 js 代码第一行不利于文件合并,因此可以写在一个自调用函数的第一行 使 ...

  4. 从es中提取全量数据的shell脚本

    [root@hadoop3 xiaole_chk_url]# sh looh.es.res.sh 100 200 1 % Total % Received % Xferd Average Speed ...

  5. Codesys——TON和TOF的使用方法

    1. 引言 介绍延迟导通.延迟关闭函数的使用方法. 2. 函数描述 TON: 当IN为FALSE时,输出Q为FALSE: 当IN为由FALSE变为TRUE时,延迟导通过程中Q为FALSE,当时间到Q变 ...

  6. C#的内存管理知识 .

    本章介绍内存管理和内存访问的各个方面.尽管运行库负责为程序员处理大部分内存管理工作,但程序员仍必须理解内存管理的工作原理,了解如何处理未托管的资源. 如果很好地理解了内存管理和C#提供的指针功能,也就 ...

  7. 码位(code position/point)Unicode 编码与 Python 2/3 编码兼容性问题

    Unicode HOWTO 0. 码位(code position/point) 一个码位由某个数值表示,全部码位共同构成其码值空间(code space). ASCII,0~7Fhex(128) 拓 ...

  8. algorithm库———count&&countif

    algorithm头文件定义了一个count的函数,其功能类似于find.这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果. 编写程序读取一系列int型数据,并将它们存储到vecto ...

  9. linux_bash_shell_cheat_sheet(自译)

    [说明] 发现错误或不足请务必联系我!!! linux_bash_shell_cheat_sheet.pdf (英文原本以及译本下载,链接失效请私信或邮箱联系)

  10. POJ3070Fibonacci

    矩阵乘法裸题 求快速幂 #include<iostream> #include<cstdio> #define ll long long #define Mod 10000 u ...