AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 998647
Accepted
Tim Altgeld
Tim Altgeld
Asked: 2020-01-13 12:30:33 +0800 CST2020-01-13 12:30:33 +0800 CST 2020-01-13 12:30:33 +0800 CST

fail2ban 动作路由到另一个 ip

  • 772

我想创建一个 fail2ban 操作,将流量路由到另一个 IP 禁止操作,并删除取消禁止操作的路由。

文件:/etc/fail2ban/action.d/ 中的 iptables-route.conf

# Fail2Ban configuration file
#
#

[INCLUDES]

before = iptables-common.conf

[Definition]

# Option:  actionstart
# Notes.:  command executed once at the start of Fail2Ban.
# Values:  CMD
#
actionstart = <iptables> -N f2b-<name>
              <iptables> -A f2b-<name> -j <returntype>
              <iptables> -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
              <iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
              <iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT

# Option:  actionstop
# Notes.:  command executed once at the end of Fail2Ban
# Values:  CMD
#
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
             <actionflush>
             <iptables> -X f2b-<name>
             <iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
             <iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT

# Option:  actioncheck
# Notes.:  command executed once before each actionban command
# Values:  CMD
#
actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'

# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    See jail.conf(5) man page
# Values:  CMD
#
actionban = <iptables> -I f2b-<name> 1 PREROUTING -s <ip> -j DNAT --to-destination 188.68.45.124

# Option:  actionunban
# Notes.:  command executed when unbanning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    See jail.conf(5) man page
# Values:  CMD
#
actionunban = <iptables> -D f2b-<name> -s <ip> -j DNAT --to-destination 188.68.45.124

[Init]

/etc/fail2ban/jail.d/ 中的文件 apache-route.local:

[apache-route]
enabled     = true
filter      = apache-probe
port        = http,https
banaction   = iptables-route.conf
maxretry    = 3
findtime    = 1500
bantime     = 600

logpath     = /var/www/*/userdata/logs/*-access.log

我什至无法测试它,因为它给了我以下错误:

fail2ban-客户端重启

在 /etc/fail2ban 下找不到“action.d/iptables-route.conf”的可访问配置文件

无法读取操作“iptables-route.conf”

监狱“apache-route”中的错误。跳过...

我试图让它工作,但我不知道为什么它会给我这个错误

debian
  • 2 2 个回答
  • 1013 Views

2 个回答

  • Voted
  1. Best Answer
    sebres
    2020-01-14T05:25:19+08:002020-01-14T05:25:19+08:00

    无法读取操作“iptables-route.conf”

    只需.conf从动作名称中删除:

    -banaction   = iptables-route.conf
    +banaction   = iptables-route
    

    顺便提一句。你的行为在我看来有点不对劲。为什么不默认iptables-multiport指定(覆盖)chain和blocktype?
    不知道你在尝试什么,但不会是这样的:

    banaction = iptables-multiport[chain=PREROUTING, blocktype="DNAT --to-destination 188.68.45.124"]
    

    做这份工作?

    • 0
  2. Tim Altgeld
    2020-01-14T07:18:53+08:002020-01-14T07:18:53+08:00

    为什么不使用指定(覆盖)链和块类型的默认 iptables-multiport?

    iptables-multiport 不添加输出链:

    -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT

    -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT

    所以我决定创建一个自己的操作来添加这些并在加载/卸载时删除它们

    我忘记了我还需要实现后路由,但我需要进一步重新考虑以存档它。

    我想要的是:

    在 Banaction 上,请求被路由到另一个 ip,其中托管了一个页面,上面写着“由于过多的无效请求而被禁止”,而不是仅仅拒绝/丢弃请求

    • 0

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve