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

iptables 能加载外部文件么?

  •  
  •   xingshu · Jul 15, 2016 · 3918 views
    This topic created in 3770 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
    hcymk2
    Jul 15, 2016
    1
    likuku
    likuku
    Jul 15, 2016
    2
    shell 写个脚本,读取这个文件来自动叫 iptables 加策略
    2026
    2026
    Jul 15, 2016
    3
    可以用 ipset ,写个同步脚本就行了
    xingshu
    xingshu
    OP
    Jul 15, 2016
    4
    @likuku 求个脚本试试:D
    ToughGuy
    ToughGuy
    Jul 16, 2016
    5
    ipset create denyAddr ip:hash
    ipset -A denyAddr 1.1.1.1
    ....

    iptables -A INPUT -m set --match-set denyAddr src -j DROP
    julyclyde
    julyclyde
    Jul 16, 2016
    6
    规则太多的话会导致 system interrupt 很多, CPU 都没时间处理正常事了
    likuku
    likuku
    Jul 19, 2016
    7
    @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
    EchoWhale
    Jul 19, 2016 via Android
    8
    配合 ipset 使用很优雅
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1134 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 18:04 · PVG 02:04 · LAX 10:04 · JFK 13:04
    ♥ Do have faith in what you're doing.