iptables 命令使用帮助总结
本文为博主原创,转载请注明出处:
1.iptables 命令帮助参数
root@controller1:~# iptables --help
iptables v1.6.1 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 chain Append to chain
--check -C chain Check for the existence of a rule
--delete -D chain Delete 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:
--ipv4 -4 Nothing (line is ignored by ip6tables-restore)
--ipv6 -6 Error (line is ignored by iptables-restore)
[!] --protocol -p proto protocol: 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
--wait -w [seconds] maximum wait to acquire xtables lock before give up
--wait-interval -W [usecs] wait time to try to acquire xtables lock
default is 1 second
--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.
2.iptables 常用参数
- -L, --list
- 列出所有规则链。
- 示例:
iptables -L列出所有链的默认规则。
- -A, --append
- 向指定链追加一条规则。
- 示例:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT向 INPUT 链追加一条规则,允许所有到 TCP 端口 22 的连接。
- -D, --delete
- 删除链中的一条规则。
- 示例:
iptables -D INPUT -p tcp --dport 22 -j ACCEPT删除 INPUT 链中允许 TCP 端口 22 的规则。
- -I, --insert
- 在链的指定位置插入一条规则。
- 示例:
iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT在 INPUT 链的第一条规则之前插入一条允许 TCP 端口 80 的规则。
- -R, --replace
- 替换链中的一条规则。
- 示例:
iptables -R INPUT 1 -p tcp --dport 8080 -j ACCEPT替换 INPUT 链中第一条规则为允许 TCP 端口 8080 的规则。
- -F, --flush
- 删除链中的所有规则。
- 示例:
iptables -F INPUT删除 INPUT 链中的所有规则。
- -N, --new-chain
- 创建一个新的用户自定义链。
- 示例:
iptables -N MYCHAIN创建一个名为 MYCHAIN 的新链。
- -X, --delete-chain
- 删除一个用户自定义链。
- 示例:
iptables -X MYCHAIN删除名为 MYCHAIN 的链。
- -P, --policy
- 设置链的默认策略。
- 示例:
iptables -P INPUT DROP将 INPUT 链的默认策略设置为 DROP。
- -j, --jump
- 指定匹配的数据包应该跳转到的目标。
- 示例:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT匹配的数据包将被接受(ACCEPT)。
11. -v, --verbose
- 显示更详细的信息。这通常包括每个规则的匹配次数、数据包数、字节数等统计信息。

3.常用命令
1.删除现有规则
iptables -F
(OR)
iptables --flush
2.屏蔽指定的IP地址
以下规则将屏蔽BLOCK_THIS_IP所指定的IP地址访问本地主机:
BLOCK_THIS_IP="x.x.x.x"
iptables -A INPUT -i eth0 -s "$BLOCK_THIS_IP" -j DROP
(或者仅屏蔽来自该IP的TCP数据包)
iptables -A INPUT -i eth0 -p tcp -s "$BLOCK_THIS_IP" -j DROP
3.允许来自外部的ping测试
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
4.允许从本机ping外部主机
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
5.允许环回(loopback)访问
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
6.允许 SSH 访问
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
7.允许 HTTP 访问
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
8.拒绝所有其他入站连接
iptables -P INPUT DROP
注意:这里使用了 -P INPUT DROP 来设置 INPUT 链的默认策略为 DROP,这意味着除非明确允许,否则所有入站连接都将被拒绝。
iptables 命令使用帮助总结的更多相关文章
- Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]
Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...
- 【简单学习shell】iptables命令实用
构造设备离线iptables命令iptables -I INPUT -p all -s 10.71.115.159 -j DROP 断链iptables -I INPUT -p all -s 10.7 ...
- iptables命令 高级网络
http://man.linuxde.net/iptables iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分.可以直接配置,也可以通过许多前端和图形界面配置. ...
- iptables命令使用详解
iptables的主要功能是实现对网络数据包进出设备及转发的控制.当数据包需要进入设备.从设备中流出或者经该设备转发.路由时,都可以使用iptables进行控制. 环境 操作系统:CentOS7.3 ...
- iptables命令提取总结,包含扩展模块<取自朱双印博客>
以下内容只是一些命令相关的,以朱双印博客中的iptables的教程提取出来的.纯粹只是命令的总结,如果需要看理论的知识,建议去看朱老师的博客,目前还没有看到写得比这个好的了. <http://w ...
- Linux iptables 命令
iptables 是 Linux 管理员用来设置 IPv4 数据包过滤条件和 NAT 的命令行工具.iptables 工具运行在用户态,主要是设置各种规则.而 netfilter 则运行在内核态,执行 ...
- iptables命令
iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分.可以直接配置,也可以通过许多前端和图形界面配置. 语法 iptables(选项)(参数) 选项 -t<表&g ...
- iptables命令、规则、参数详解
表 (table)包含4个表:4个表的优先级由高到低:raw-->mangle-->nat-->filterraw---RAW表只使用在PREROUTING链和OUTPUT链上 ...
- iptables命令(备忘)
语法 iptables(选项)(参数) 选项 -t<表>:指定要操纵的表: -A:向规则链中添加条目: -D:从规则链中删除条目: -i:向规则链中插入条目: -R:替换规则链中的条目: ...
- Linux iptables命令详解
iptables命令主要是设置防火墙信息的 常见命令参数 Usage: iptables -[AD] chain rule-specification [options] iptables -I ch ...
随机推荐
- 量子算法抛转(以及Oracle函数初步)
接下来要接触量子算法了,我们会看到怎么利用量子并行机制和干涉原理.干涉在算法对结果进行测量求值时举足轻重. Deutsch-Jozsa 算法 DJ算法是量子算法的入门算法,就像编程界的"He ...
- Navicat for mysql 无法连接到虚拟机的linux系统下的mysql
最近在linux Centos7版本的虚拟机上安装了一个MySql数据库,发现本地可以正常ping通虚拟机,但Navicat则无法正常连接到虚拟机里的MySql数据库,经过一番琢磨,发现解决这个问题的 ...
- php页面调用微信扫一扫
function.php <?php define("appID", "微信公众号appId"); define("appsecret" ...
- [oeasy]python001_先跑起来_python_三大系统选择_windows_mac_linux
先跑起来 Python 什么是 Python? Python [ˈpaɪθɑ:n] 是 一门 适合初学者 的编程语言 添加图片注释,不超过 140 字(可选) 类库 众多 几行代码 就 ...
- oeasy教您玩转vim - 73 - # 映射map
映射map 回忆上次缩写的细节 这次了解到了:abbrivate缩写 可以定义缩写 :ab o1z oeasy 这里面还可以包括方向键.回车键之类的东西 可以定义到指定的模式 iab cab 查看 ...
- 分析C语言程序
1 #include <stdio.h> 2 int main() 3 { 4 puts("C语言"); 5 return 0; 6 } 函数的概念 C语言提供了很多功 ...
- java面试一日一题:java内存模型
问题:请讲下java内存模型? 分析:该问题比较容易和jvm内存区域(java内存结构)这样的问题混淆,其实他们是两个概念,jvm内存区域指的是运行时的几块数据区域,包括堆.方法区.虚拟机栈.本地方法 ...
- vue3:如何进行组件间的信息传递
这里以父组件--主页面 | 子组件1--对话框 | 子组件2--按钮为例 父组件--主页面 import {provide, ref} from "vue"; # 创建对象,并且其 ...
- Scratch全套Q版三国人物角色素材包免费下载
全新Q版三国人物角色素材包,内含142张细腻可爱的Q版风格图片,涵盖三国名将.士兵.场景等丰富元素,为scratch爱好者提供多样选择,适合各类三国主题创作. 免费下载:www.xiaohujing. ...
- 图书《数据资产管理核心技术与应用》核心章节节选-3.1.2. 从Spark 执行计划中获取数据血缘
本文节选自清华大学出版社出版的图书<数据资产管理核心技术与应用>,作者为张永清等著. 从Spark 执行计划中获取数据血缘 因为数据处理任务会涉及到数据的转换和处理,所以从数据任务中解析血 ...