Skip to content

Fail2Ban Telegram Notifier is a script that sends alerts to Telegram when an IP is blocked by Fail2Ban.

License

Notifications You must be signed in to change notification settings

tonytkachenko/fail2ban-telegram-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fail2Ban Telegram Notifier 🚀

Fail2Ban + Telegram

Fail2Ban Telegram Notifier is a powerful extension for Fail2Ban that sends notifications to Telegram when an IP is blocked.
The script supports CIDR range blocking (bancidr) and IP-API integration

📌 Features

Sends Telegram alerts when Fail2Ban blocks an IP
Can notify about blocking entire CIDR ranges when multiple IPs from the same network attack
Retrieves IP information using ip-api.com
Detects VPN/proxy usage
Supports multiple Telegram chats
Easy installation and configuration

🚀 Installation

1️⃣ Download and Install the Script

git clone https://github.com/tonytkachenko/fail2ban-telegram-notifier.git
cd fail2ban-telegram-notifier
sudo cp telegram_notifier.conf /etc/fail2ban/
sudo cp telegram.conf /etc/fail2ban/action.d/
sudo cp telegram_notifier.sh /etc/fail2ban/action.d/

2️⃣ Configure the settings:

Open /etc/fail2ban/telegram_notifier.conf and set the following parameters:

sudo nano /etc/fail2ban/telegram_notifier.conf

Sample configuration:

# Telegram Bot Token
TOKEN="your-telegram-bot-token"

# Telegram Chat IDs (space-separated)
CHAT_IDS="-1001234567890"

# Use ip-api.com to get IP information?
USE_IPAPI="yes"

3️⃣ Grant execution permissions to the script:

sudo chmod +x /etc/fail2ban/action.d/telegram_notifier.sh

4️⃣ Enable it in the Jail configuration:

[DEFAULT]
banaction = iptables-multiport
action = %(action_)s
         telegram # <- Set action

5️⃣ Restart Fail2Ban

sudo systemctl restart fail2ban

🔒 Security

  • Ensure that your Telegram bot is protected and not accessible to unauthorized users.
  • Set proper permissions on /etc/fail2ban/telegram_notifier.conf to prevent others from viewing the bot token.

🔥 Upcoming Features

  • Anti-Spam mechenism
  • Autoinstall script

📄 License

This project is licensed under the MIT License.

🤝 Support & Contributions

Feel free to open an Issue or Pull Request if you have suggestions or improvements! 🚀

About

Fail2Ban Telegram Notifier is a script that sends alerts to Telegram when an IP is blocked by Fail2Ban.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages