V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Navee
V2EX  ›  Linux

iptables 命令问题.

  •  
  •   Navee ·
    navee · 2014-07-17 17:13:02 +08:00 · 2968 次点击
    这是一个创建于 3578 天前的主题,其中的信息可能已经有所发展或是发生改变。
    折腾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达到了想要的效果
    但是这样实在是不太方便,如果我后面还要增加规则呢?
    请教一下有没有命令直接将两条规则调换位置.
    11 条回复    2014-07-17 22:23:06 +08:00
    coderwang
        1
    coderwang  
       2014-07-17 17:26:15 +08:00
    iptables-save > xxx
    vim xxx
    iptables-restore < xxx
    zent00
        2
    zent00  
       2014-07-17 18:59:49 +08:00
    直接用 -I 吧。
    bigporker
        3
    bigporker  
       2014-07-17 18:59:59 +08:00
    我都是直接编辑 /etc/sysconfig/iptables 的
    Roboo
        4
    Roboo  
       2014-07-17 20:50:54 +08:00 via Android
    好像是 -n 2
    默认是插入第一行
    看下帮助信息
    DiveIntoEyes
        5
    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:
    Navee
        7
    Navee  
    OP
       2014-07-17 21:46:20 +08:00
    @zent00 I 默认是插入第一条.现在的问题是我想把这些规则插入到drop all之前,原有规则之后
    Navee
        8
    Navee  
    OP
       2014-07-17 21:46:47 +08:00
    @coderwang
    @bigporker
    查到了这种方式,但是没试,待会试一下.
    Navee
        9
    Navee  
    OP
       2014-07-17 21:49:21 +08:00
    @DiveIntoEyes 这种也是先删掉,然后插入,不过谢谢你的答案,让我知道了可以指定插入行.
    leavic
        10
    leavic  
       2014-07-17 22:13:17 +08:00
    iptables -I [链名] [规则号] [规则]

    规则号就是你要的
    onemoo
        11
    onemoo  
       2014-07-17 22:23:06 +08:00
    我是把iptables配置写成脚本,直接在脚本里编辑规则。没用过行号功能。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   859 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:44 · PVG 06:44 · LAX 15:44 · JFK 18:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.