Android进阶学习

(2)iptables规则管理

2021-05-26  本文已影响0人  Jack_Ou

1.查看表中规则

# 查看filter表中所有规则
iptables -t filter -L

# 查询filter表中INPUT链规则
iptables -t filter -L INPUT
查询表.png

2.查看规则详情

# 加入-v参数,查看详情
iptables -t filter -L -v
查看规则详情.png

规则字段含义:

上图中的源地址与目标地址都为anywhere,iptables默认为我们进行了名称解析,但是在规则非常多的情况下如果进行名称解析,效率会比较低,我们可以使用 -n 选项,表示不对IP地址进行名称反解,直接显示IP地址

查看某链上细化规则.PNG

链括号中的参数含义:

Chain INPUT (policy ACCEPT 4883 packets, 342K bytes)

3.显示规则行号

iptables --line-number -nvL INPUT

// 查看精细的字节数可以加-x参数
iptables -nvxL INPUT
查看精确字节数.png

4.添加规则

使用 -I 或者 -A 来添加规则。

# 14.215.177.39 为百度的一个ip
iptables -t filter -I INPUT -s 14.215.177.39 -j DROP
iptables -t filter -A INPUT -s 14.215.177.39 -j ACCEPT
# 在INPUT链的第一行添加规则
iptables -t filter -A INPUT 1 -s 14.215.177.39 -j ACCEPT
增加规则.png 验证新加规则.png

5.删除规则

# 删除多少行,删除第一行规则
iptables -t filter -D INPUT 1
删除规则.png

6.修改规则

使用 -R 来更改指定行数规则

# 将INPUT链第一行规则改为接受14.215.177.39的报文,此处一定要加上-s,否者将默认0.0.0.0/0,接受全部。
iptables -t filter -R INPUT 1 -s 14.215.177.39 -j ACCEPT

7.设置链默认规则

使用 -P参数设置链默认规则

# 设置filter表FORWARD链默认规则为DROP
iptables -t filter -P FORWARD DROP

8.保存/恢复配置信息

使用iptables-save 指令

iptables-save > /data/iptables-rules
iptables-restore < /data/iptables-rules

参考文档

iptables规则管理

上一篇 下一篇

猜你喜欢

热点阅读