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 ...
随机推荐
- input标签 只能输入纯数字
<input type="number" pattern="number" onkeyup="value=value.replace(/[^\d ...
- 面试官:Dubbo一次RPC调用会经过哪些环节?
大家好,我是三友~~ 今天继续探秘系列,扒一扒一次RPC请求在Dubbo中经历的核心流程. 本文是基于Dubbo3.x版本进行讲解 一个简单的Demo 这里还是老样子,为了保证文章的完整性和连贯性,方 ...
- Arctic开源!网易数帆×华泰证券,推动湖仓一体落地
数字化转型趋势下,各行业对数据生产力的探索与追求逐步进入深水区.现实的问题是,企业数据仓库存储.数据湖多种技术并存的局面将长期存在,如何才能摆脱技术协同的内耗,让大数据直通生产力的彼岸? 8月11日下 ...
- IntersectionObserver 实现图片懒加载
背景 最近使用express做导航类型网站,因为这个是后端jade渲染,浏览器拿到页面之后,解析出来dom结构,导致100+的图片瞬间加载,严重浪费了宽带资源,加重服务器负担,因此打算延迟加载图片 模 ...
- SELECT *问题
1.mysql拿到一条命令,会去解析命令.优化查询,然后去存储引擎执行查找.SELECT * 语句取出表中的所有字段,会解析更多的 对象,字段,权限,属性相关,不论该字段的数据对调用的应用程序是否有用 ...
- 使用forEach循环异步方法,导致使用深拷贝时,得不到最新数据,控制台会打印出最新的数据
在使用forEach循环遍历一个数组,如果循环时有异步方法,会导致最终深拷贝得不到最新数据,但是控制台会打印最新的数据 `const arr = [ { name: "Jone", ...
- [oeasy]python0144_try的完全体_否则_else_最终_finally
try的完全体 回忆上次内容 上次细化了主控程序(main.py) 导入(get_fruits.py) 处理(process.py) 输出(output.py) 使用了 try 结构 try ...
- [oeasy]python0037_电传打字机_打印头_print_head_carriage_词源
换行回车 回忆上次内容 上次我们 diy了 自己的小动物 还可以 让小动物 变色.报时 还可以 说些话 这很亚文化 很酷炫的亚文化 不是吗? 回忆一下 最开始 研究报时 的 时候 回到 本行行头 的 ...
- Day 8 - 并查集、堆、set 与 map
并查集 引入 并查集是一种用于管理元素所属集合的数据结构,实现为一个森林,其中每棵树表示一个集合,树中的节点表示对应集合中的元素. 顾名思义,并查集支持两种操作: 合并(\(\text{Union}\ ...
- ArchLinux Vmware安装指北
ArchLinux Vmware安装指北 在本文开始之前,首先允许我提前声明一点,Arch Linux的安装并不算难,但是绝对也算不上简单,中间的安装可能会遇到很多问题,本篇文章不能保证完全贴合你的真 ...