V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
iButterfly
V2EX  ›  问与答

工作平台转 Linux,防火墙怎么弄(≧﹏ ≦)

  •  
  •   iButterfly · Jun 12, 2014 · 4081 views
    This topic created in 4347 days ago, the information mentioned may be changed or developed.
    想默认不允许访问网络,特定程序加端口允许联网。
    iptables好像是针对IP加端口而不是程序。
    怎么弄?
    12 replies    2014-07-08 11:50:40 +08:00
    kafkakevin
        1
    kafkakevin  
       Jun 12, 2014
    有一个叫 tcp wrapper的东西,不过只支持一部分程序
    参考
    http://linux.vbird.org/linux_server/0250simple_firewall.php#tcp_wrappers_program
    initialdp
        2
    initialdp  
       Jun 12, 2014   ❤️ 1
    如果是ubuntu的话,用ufw,简单又方便。
    tamamaxox
        3
    tamamaxox  
       Jun 12, 2014
    我觉得iptables真心适合你的需求,既然你都要用linux的话
    xunyu
        4
    xunyu  
       Jun 12, 2014
    iptables足以
    lang1pal
        5
    lang1pal  
       Jun 12, 2014
    条件允许的话弄一个物理防火墙
    ceyes
        6
    ceyes  
       Jun 12, 2014
    把默认的policy 都设成drop,然后开放几个端口即可。

    这是我workstation 的 配 iptables 脚本,稍改一下就能满足你的需求吧。
    https://gist.github.com/ceyes/a3686796ef5980a2cbe9#file-firewall-sh
    rrfeng
        7
    rrfeng  
       Jun 12, 2014
    lz 问的是限制出,iptables 还真没法区分应用 。
    RainFlying
        8
    RainFlying  
       Jun 12, 2014
    iptables -P OUTPUT DROP // 非常危险
    iptables -m owner 不过 owner module 里非常有用的 ——-cmd-owner 选项已经没了。
    wzxjohn
        9
    wzxjohn  
       Jun 12, 2014
    @RainFlying 你说的是6楼的脚本么?没看到这句啊。。。
    RainFlying
        10
    RainFlying  
       Jun 12, 2014
    @wzxjohn 6 楼脚本是设置默认策略然后开了一些端口。老版本的 iptables 有一个 owner 模块,可以用来匹配程序名,比如 --cmd-owner httpd 用来匹配 httpd .
    rhwood
        11
    rhwood  
       Jun 12, 2014
    可以看一下csf,比iptables容易理解和操作。至于要限定程序有点难,可能得考虑曲线方式
    iButterfly
        12
    iButterfly  
    OP
       Jul 8, 2014
    看来Linux下没有太完美的解决方法- -
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3326 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1105ms · UTC 13:44 · PVG 21:44 · LAX 06:44 · JFK 09:44
    ♥ Do have faith in what you're doing.