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 ...
随机推荐
- Vue2 整理(三):高级篇
前言 基础篇链接:https://www.cnblogs.com/xiegongzi/p/15782921.html 组件化开发篇链接:https://www.cnblogs.com/xiegongz ...
- 写给rust初学者的教程(一):枚举、特征、实现、模式匹配
这系列RUST教程一共三篇.这是第一篇,介绍RUST语言的入门概念,主要有enum\trait\impl\match等语言层面的东西. 安装好你的rust开发环境,用cargo创建一个空项目,咱们直接 ...
- 记一次aspnetcore发布部署流程初次使用k8s
主题: aspnetcorewebapi项目,提交到gitlab,通过jenkins(gitlab的ci/cd)编译.发布.推送到k8s. 关于gitlab.jenkins.k8s安装,都是使用doc ...
- vmware安装配置openwrt
前言 OpenWrt是一个轻量的嵌入式linux系统,功能十分强大. 现在将我在vmware上安装OpenWrt的过程简单记录下来,以备后续参考. 环境准备 vmware软件 已经安装好的一个vmwa ...
- Django详细笔记
django 学习 特点 快速开发 安全性高 可伸缩性强 URL 组成部分 URL: 同意资源定位符 一个URL由以下几部分组成 scheme://host:port/path/?query-stri ...
- Java-Response对象设置响应消息
功能:设置响应消息 1.设置响应行 格式:HTTP/1.1 200 OK 设置状态码:setStatus(int sc) 2.设置响应头:setHeader(String name,String va ...
- 利用FastAPI和OpenAI-Whisper打造高效的语音转录服务
最近好久没有写博客了,浅浅记录下如何将OpenAI-Whisper做成Web服务吧 介绍 在这篇指导性博客中,我们将探讨如何在Python中结合使用FastAPI和OpenAI-Whisper.Ope ...
- 集群及分布式定时任务中间件MEE_TIMED
集群及分布式定时任务中间件MEE_TIMED 转载请著名出处:https://www.cnblogs.com/funnyzpc/p/18312521 MEE_TIMED一套开源的定时任务中间件,MEE ...
- PHP 高性能框架 Workerman 凭什么能硬刚 Swoole ?
大家好,我是码农先森. 一次偶然看到了国外某机构针对 PHP 周边生态框架及扩展的性能测试排行榜,看到 Workerman 竟遥遥领先 Swoole.在我们 PHP 程序员现有的认知里,Swoole ...
- 释放资源的方式try-with-resources
1.try-catch-finally 2.try-with-resources 使用方法 try(//这里定义你要使用的资源){} catch(){} 注意:try()里只能存放流对象(资源对象), ...