Skip to content

Commit 9fa401f

Browse files
authored
Update iptables.md
1 parent 49d21d9 commit 9fa401f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

command/iptables.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,38 @@ iptables -t 表名 <-A/I/D/R> 规则链名 [规则号] <-i/o 网卡名> -p 协
106106

107107
#### 列出已设置的规则
108108

109+
> iptables -L [-t 表名] [链名]
110+
111+
- 四个表名 `raw``nat``filter``mangle`
112+
- 五个规则链名 `INPUT``OUTPUT``FORWARD``PREROUTING``POSTROUTING`
113+
- filter表包含`INPUT``OUTPUT``FORWARD`三个规则链
114+
109115
```bash
110116
iptables -L -t nat # 列出 nat 上面的所有规则
111117
# ^ -t 参数指定,必须是 raw, nat,filter,mangle 中的一个
112118
iptables -L -t nat --line-numbers # 规则带编号
113119
iptables -L INPUT
120+
121+
iptables -L -nv # 查看,这个列表看起来更详细
114122
```
115123

116124
#### 清除已有iptables规则
117125

126+
```bash
127+
iptables -F INPUT # 清空指定链 INPUT 上面的所有规则
128+
iptables -X INPUT # 删除指定的链,这个链必须没有被其它任何规则引用,而且这条上必须没有任何规则。
129+
# 如果没有指定链名,则会删除该表中所有非内置的链。
130+
iptables -Z INPUT # 把指定链,或者表中的所有链上的所有计数器清零。
118131
```
119-
iptables -F
120-
iptables -X
121-
iptables -Z
132+
133+
#### 删除一条规则
134+
135+
```bash
136+
# 添加一条规则
137+
iptables -A INPUT -s 192.168.1.5 -j DROP
138+
139+
# 删除上面添加的规则,删除用-D参数
140+
iptables -D INPUT -s 192.168.1.5 -j DROP
122141
```
123142

124143
#### 开放指定的端口

0 commit comments

Comments
 (0)