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 ...
随机推荐
- 通过Docker搭建Debezium同步MySQL的数据变化
Debezium是红帽开发的一款CDC产品,和阿里的Canel类似,都是同步binlog,不过强大了一点点.为了不再麻烦,下面称之为dbz. 达拉崩吧斑得贝迪卜多比鲁翁... dbz的搭建依赖很多中间 ...
- 如何在 Windows 使用 Podman Desktop 取代 Docker Desktop
Podman Desktop 是 Docker Desktop 的免费替代品,是本地开发使用的另一个绝佳选择.它提供了类似的功能集,同时保持完全开源,让您避免使用 Docker 产品的许可问题.在本文 ...
- Vue手稿4
- HBase 在统一内容平台业务的优化实践
作者:来自 vivo 互联网服务器团队-Leng Jianyu.Huang Haitao HBase是一款开源高可靠性.扩展性.高性能和灵活性的分布式非关系型数据库,本文围绕数据库选型以及使用HBas ...
- vs2019如何自动生成有下划线前缀的字段名?
vs2019代码自动完成功能非常强大,今天要说的是根据构造函数的参数自动生成字段的事儿. 下图所示,IDE可以根据构造函数的参数自动生成私有字段 这个功能非常好,代码编写效率大大提升,生成的代码如下: ...
- Python pluggy框架基础用法总结
代码为例进行说明 实践环境 Python 3.6.5 pluggy 0.13.0 例1 注册类函数为插件函数 #!/usr/bin/env python # -*- coding:utf-8 -*- ...
- UE中返回值为数组的时候,无法传递Reference的问题
我如果要修改一个类或者结构体的成员变量, 那么我需要通过函数返回 也就是说Struct目前不能传递引用,只能传递备份
- STL 算法 <algorithm>,
STL 算法部分主要由头文件 <algorithm>,<numeric>,<functional > 组成.要使用 STL 中的算法函数必须包含头文件 < a ...
- 解锁 SQL Server 2022的时间序列数据功能
解锁 SQL Server 2022的时间序列数据功能 SQL Server2022在处理时间序列数据时,SQL Server 提供了一些优化和功能,比如 DATE_BUCKET 函数.窗口函数(如 ...
- hbuilderx打正式包所需的私钥证书的创建方法
现在使用uniapp作为底层框架来开发app应用已经成为了很多公司的事实标准,而uniapp的开发工具hbuilderx云打包的时候,需要私钥证书和证书profile文件. 而且还需要将打包好的ipa ...