Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
xingshu
V2EX  ›  Linux

iptables 能加载外部文件么?

  •  
  •   xingshu · Jul 15, 2016 · 3539 views
    This topic created in 3613 days ago, the information mentioned may be changed or developed.
    我这里屏蔽了一个巨大的 ip 表,都是要 drop 的 ip 地址
    现在直接编辑 iptables 感觉不方便

    我想建立一个 blockip 这样一个文件

    日常维护这个 blockip 这个文件就可以了

    有这样的方法么?
    8 replies    2016-07-19 21:02:29 +08:00
    hcymk2
        1
    hcymk2  
       Jul 15, 2016
    likuku
        2
    likuku  
       Jul 15, 2016
    shell 写个脚本,读取这个文件来自动叫 iptables 加策略
    2026
        3
    2026  
       Jul 15, 2016
    可以用 ipset ,写个同步脚本就行了
    xingshu
        4
    xingshu  
    OP
       Jul 15, 2016
    @likuku 求个脚本试试:D
    ToughGuy
        5
    ToughGuy  
       Jul 16, 2016
    ipset create denyAddr ip:hash
    ipset -A denyAddr 1.1.1.1
    ....

    iptables -A INPUT -m set --match-set denyAddr src -j DROP
    julyclyde
        6
    julyclyde  
       Jul 16, 2016
    规则太多的话会导致 system interrupt 很多, CPU 都没时间处理正常事了
    likuku
        7
    likuku  
       Jul 19, 2016
    @xingshu 比如:

    bash 的,假设你这个 ip list 文件 ip_list_for_block.list ,一行一个 ip/网络地址, 不太大(10MB 以内)

    for b_ip in $(cat ip_list_for_block.list | xargs)
    do
    iptables -A INPUT -s ${b_ip} -j DROP
    done
    EchoWhale
        8
    EchoWhale  
       Jul 19, 2016 via Android
    配合 ipset 使用很优雅
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1233 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 17:47 · PVG 01:47 · LAX 10:47 · JFK 13:47
    ♥ Do have faith in what you're doing.