iptables 命令问题.

2014-07-17 17:13:02 +08:00
 Navee
折腾linux iptables的时候,看着教程插入了几条INPUT规则,最后一条是drop all
比如这样:
num target prot opt source destination
1 ACCEPT tcp -- anywhere anywhere tcp dpt:80
2 DROP all -- anywhere anywhere
然后接着装其他东西需要开端口的时候没有注意,用的增加规则而不是插入规则,这样新增加的规则就到了drop all 规则后面,如下:
num target prot opt source destination
1 ACCEPT tcp -- anywhere anywhere tcp dpt:80
2 DROP all -- anywhere anywhere
3 ACCEPT tcp -- anywhere anywhere tcp dpt:100
造成后加入的规则无效,本来想找找看有没有命令吧在中间的drop all 规则挪到最后,找了半天发现没有
然后就蛋疼的删除了drop all 然后增加drop all达到了想要的效果
但是这样实在是不太方便,如果我后面还要增加规则呢?
请教一下有没有命令直接将两条规则调换位置.
2996 次点击
所在节点    Linux
11 条回复
coderwang
2014-07-17 17:26:15 +08:00
iptables-save > xxx
vim xxx
iptables-restore < xxx
zent00
2014-07-17 18:59:49 +08:00
直接用 -I 吧。
bigporker
2014-07-17 18:59:59 +08:00
我都是直接编辑 /etc/sysconfig/iptables 的
Roboo
2014-07-17 20:50:54 +08:00
好像是 -n 2
默认是插入第一行
看下帮助信息
DiveIntoEyes
2014-07-17 21:10:57 +08:00
First check the line number:
iptables -nL --line-numbers
Delete based on line:

iptables -D INPUT {line}
Insert where you would like it to be:
DiveIntoEyes
2014-07-17 21:11:59 +08:00
Navee
2014-07-17 21:46:20 +08:00
@zent00 I 默认是插入第一条.现在的问题是我想把这些规则插入到drop all之前,原有规则之后
Navee
2014-07-17 21:46:47 +08:00
@coderwang
@bigporker
查到了这种方式,但是没试,待会试一下.
Navee
2014-07-17 21:49:21 +08:00
@DiveIntoEyes 这种也是先删掉,然后插入,不过谢谢你的答案,让我知道了可以指定插入行.
leavic
2014-07-17 22:13:17 +08:00
iptables -I [链名] [规则号] [规则]

规则号就是你要的
onemoo
2014-07-17 22:23:06 +08:00
我是把iptables配置写成脚本,直接在脚本里编辑规则。没用过行号功能。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/123166

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX