iptables基本操作笔记

一、基本操作

#启动防火墙
service iptables start
#停止防火墙
service iptables stop
#重启防火墙
service iptables restart
#查询防火墙运行等状态信息
service iptables status
#永久关闭防火墙
chkconfig iptables off
#永久关闭防火墙之后要启用
chkconfig iptables on
#保存对防火墙的设置
serivce iptables save
二、往防火墙添加规则
1)、直接编辑/etc/sysconfig/iptables
2)、通过命令进行添加
开放8080端口
#入栈规则
iptables -A  INPUT    -p tcp --dport 8080 -j ACCEPT
#出栈规则
iptables -A OUTPUT -p tcp --sport 8080 -j ACCEPT
禁止某个IP访问
iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP
删除规则
iptables -D INPUT 2   #删除INPUT链编号为2的规则
 
参数讲解:
-A 添加一条规则
-p 指定协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
--dport 进入端口,当数据从外部进入服务器为目标端口
--sport 出入端口,数据从服务器出去,则为数据源端口使用 
-j 就是指定是 ACCEPT 接收,或者 DROP 不接收
-s 指定来源IP等(如192.168.1.2)
 
具体看iptables --help
Usage: iptables -[ACD] chain rule-specification [options]
             iptables -I chain [rulenum] rule-specification [options]
             iptables -R chain rulenum rule-specification [options]
             iptables -D chain rulenum [options]
             iptables -[LS] [chain [rulenum]] [options]
             iptables -[FZ] [chain] [options]
             iptables -[NX] chain
             iptables -E old-chain-name new-chain-name
             iptables -P chain target [options]
             iptables -h (print this help information)
Commands:
Either long or short options are allowed.
  --append  -A chainAppend to chain
  --check     -C chainCheck for the existence of a rule
  --delete     -D chainDelete matching rule from chain
  --delete     -D chain rulenum                  Delete rule rulenum (1 = first) from chain
  --insert      -I    chain [rulenum]                Insert in chain as rulenum (default 1=first)
  --replace   -R   chain rulenum    Replace rule rulenum (1 = first) in chain
  --list           -L    [chain [rulenum]]    List the rules in a chain or all chains
  --list-rules -S    [chain [rulenum]]            Print the rules in a chain or all chains
  --flush        -F    [chain]                     Delete all rules in  chain or all chains
  --zero        -Z    [chain [rulenum]]     Zero counters in chain or all chains
  --new        -N    chain                     Create a new user-defined chain
  --delete  -chain   -X [chain]             Delete a user-defined chain
  --policy     -P     chain target             Change policy on chain to target
  --rename-chain           
                   -E     old-chain new-chain       Change chain name, (moving any references)
Options:
[!] --proto-p protoprotocol: by number or name, eg. `tcp'
[!] --source   -s address[/mask][...]       source specification
[!] --destination -d address[/mask][...]       destination specification
[!] --in-interface -i input name[+]       network interface name ([+] for wildcard)
    --jump           -j target       target for rule (may load target extension)
    --goto            -g chain                               jump to chain with no return
   --match  -m match       extended match (may load extension)
   --numeric  -n                               numeric output of addresses and ports
[!] --out-interface -o output name[+]       network interface name ([+] for wildcard)
  --table          -t table                               table to manipulate (default: `filter')
  --verbose  -v                               verbose mode
  --line-numbers                               print line numbers when listing
  --exact         -x                               expand numbers (display exact values)
[!] --fragment -f                               match second or further fragments only
  --modprobe=<command>               try to insert modules using this command
  --set-counters PKTS BYTES               set the counter during insert/append
[!] --version-V                               print package version.

更多iptables相关教程见以下内容

CentOS 7.0关闭默认防火墙启用iptables防火墙  http://www.linuxidc.com/Linux/2015-05/117473.htm

Iptables工作原理使用详解 http://www.linuxidc.com/Linux/2016-09/134945.htm

Ubuntu 14.04 配置iptables防火墙 http://www.linuxidc.com/Linux/2017-02/140556.htm

Linux下编译安装iptables  http://www.linuxidc.com/Linux/2017-04/142615.htm

iptables的备份、恢复及防火墙脚本的基本使用 http://www.linuxidc.com/Linux/2013-08/88535.htm

Iptables工作原理使用详解  http://www.linuxidc.com/Linux/2016-09/134945.htm

CentOS7下iptables配置过程 http://www.linuxidc.com/Linux/2017-01/139622.htm

iptables 用法及常用模块总结  http://www.linuxidc.com/Linux/2017-10/147347.htm

iptables命令使用详解  http://www.linuxidc.com/Linux/2017-10/148097.htm

Linux下iptables防火墙配置详解  http://www.linuxidc.com/Linux/2017-11/148407.htm

Linux防火墙iptables详解  http://www.linuxidc.com/Linux/2016-12/138474.htm

来源:http://www.linuxidc.com/Linux/2017-12/149195.htm

linux中iptables的用法的更多相关文章

  1. Linux中find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  2. [转]Linux中find常见用法示例

    Linux中find常见用法示例[转]·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \;find命令的参 ...

  3. linux中make的用法

    一.linux中make的用法 目的:       基本掌握了make 的用法,能在Linux系统上编程.环境:       Linux系统准备:       准备三个文件:file1.c, file ...

  4. Linux中“!"的神奇用法

    前言 实际上,不起眼的“!”在linux中有着很多让你惊叹的妙用.本文就来细数那些“!”的神奇用法. 执行上一条命令 例如,在执行完上面一条命令后,可以使用下面的方式再次执行上一条命令: $ wher ...

  5. Linux中sed的用法实践

    Linux中sed的用法实践 参考资料:https://www.cnblogs.com/emanlee/archive/2013/09/07/3307642.html http://www.fn139 ...

  6. Linux中Sed的用法

    Linux中Sed的用法 sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为: ...

  7. (转)linux 中特殊符号用法详解

    linux 中特殊符号用法详解 原文:https://www.cnblogs.com/lidabo/p/4323979.html # 井号 (comments)#管理员  $普通用户 脚本中 #!/b ...

  8. LINUX中IPTABLES防火墙使用

    对于有公网IP的生产环境VPS,仅仅开放需要的端口,即采用ACL来控制IP和端口(Access Control List). 这里可以使用Linux防火墙netfilter的用户态工具 iptable ...

  9. Linux中 find 常见用法示例

    Linux中find常见用法示例 #find path -option [ -print ] [ -exec -ok command ] {} \; #-print 将查找到的文件输出到标准输出 #- ...

随机推荐

  1. 数据库表名最大长度(Oracle=30;SqlServer=128;)

    1.Oracle 数据库 (支持30个字符) --30个字符 CREATE TABLE Tab_Test1234567890abcdefghijkl( ts int ); --select * fro ...

  2. 一文读懂BERT中的WordPiece

    1. 前言 2018年最火的论文要属google的BERT,不过今天我们不介绍BERT的模型,而是要介绍BERT中的一个小模块WordPiece. 2. WordPiece原理 现在基本性能好一些的N ...

  3. 2. CNN卷积网络-前向传播算法

    1. CNN卷积网络-初识 2. CNN卷积网络-前向传播算法 3. CNN卷积网络-反向更新 1. 前言 我们已经了解了CNN的结构,CNN主要结构有输入层,一些卷积层和池化层,后面是DNN全连接层 ...

  4. ActiveMQ入门实例(转)

    转载自:http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html 1.下载ActiveMQ 去官方网站下载:http://act ...

  5. java基础篇---异常处理

    认识异常 异常时导致程序中断运行的一种指令流,如果不对异常进行正确的处理,则可能导致程序的中断执行,造成不必要的损失,所以在程序的设计中必须考虑各种异常的发生,并正确的做好相应的处理,这样才能保证程序 ...

  6. <邱永汉股票入门>读书笔记

    书在这里 在踏入股票市场以前,首先必须具备的观念就是“我能够亏损的极限是多少”?而不仅仅是我该准备多少钱 任何投资都要具备智慧性的忍耐力 基本分析注重的是公司营运业绩的报告与企业体质的解释:技术分析则 ...

  7. WebStorm 7.0 支持更多的Web技术

    JetBrains刚刚发布了WebStorm 7.0 GA,支持EJS.Mustache.Handlebars.Web组件.Stylus.Karma.Istanbul.Compass,并增强了很多功能 ...

  8. Hibernate 查询说明

    1.Criteria setFetchSize实际上与分页操作并没有关系,它的作用是在查询中进行分批数据返回,其中的值就是每次分批查询的记录数,主要是为了提高查询性能的. 举个例子来说:如果你这次查询 ...

  9. Centos7下Yum安装PHP5.5,5.6,7.0

    默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们 ...

  10. 选择合适NFC标签

    NFC论坛选择的初始标签格式适用于最广泛的应用程序和装置性能: 类型1基于ISO14443A,目前由Innovision研究和技术公司独家供应 (TopazTM),具有96字节内存,成本低,应用广泛. ...