BASH_SRV Telegram 104
💥 Автоматическая блокировка IP при большом количестве запросов 🛡️👮‍♂️

Если на сервере замечена подозрительная активность (например, слишком много запросов от одного IP), можно автоматически блокировать таких «шумных» клиентов с помощью iptables и awk:


#!/bin/bash
# автор: https://www.tgoop.com/bash_srv

# Лимит запросов за минуту
LIMIT=100
# Лог файл nginx или apache
LOG_FILE="/var/log/nginx/access.log"

# Найдём IP, превысившие лимит
awk '{print $1}' "$LOG_FILE" | sort | uniq -c | sort -nr | awk -v limit="$LIMIT" '$1 > limit {print $2}' | while read ip; do
# Проверим, не заблокирован ли уже
if ! iptables -L INPUT -v -n | grep -q "$ip"; then
iptables -A INPUT -s "$ip" -j DROP
echo "$(date): Заблокирован IP $ip" >> /var/log/ip_block.log
fi
done


📌 Что делает скрипт:

- Анализирует access.log
- Находит IP с количеством запросов > LIMIT
- Блокирует их через iptables

🧠 Советы:

- Запускай раз в 5 минут через cron
- Убедись, что iptables доступен и ты не блокируешь свой IP

👉@bash_srv
👍121



tgoop.com/bash_srv/104
Create:
Last Update:

💥 Автоматическая блокировка IP при большом количестве запросов 🛡️👮‍♂️

Если на сервере замечена подозрительная активность (например, слишком много запросов от одного IP), можно автоматически блокировать таких «шумных» клиентов с помощью iptables и awk:


#!/bin/bash
# автор: https://www.tgoop.com/bash_srv

# Лимит запросов за минуту
LIMIT=100
# Лог файл nginx или apache
LOG_FILE="/var/log/nginx/access.log"

# Найдём IP, превысившие лимит
awk '{print $1}' "$LOG_FILE" | sort | uniq -c | sort -nr | awk -v limit="$LIMIT" '$1 > limit {print $2}' | while read ip; do
# Проверим, не заблокирован ли уже
if ! iptables -L INPUT -v -n | grep -q "$ip"; then
iptables -A INPUT -s "$ip" -j DROP
echo "$(date): Заблокирован IP $ip" >> /var/log/ip_block.log
fi
done


📌 Что делает скрипт:

- Анализирует access.log
- Находит IP с количеством запросов > LIMIT
- Блокирует их через iptables

🧠 Советы:

- Запускай раз в 5 минут через cron
- Убедись, что iptables доступен и ты не блокируешь свой IP

👉@bash_srv

BY Bash Советы




Share with your friend now:
tgoop.com/bash_srv/104

View MORE
Open in Telegram


Telegram News

Date: |

As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. bank east asia october 20 kowloon Just as the Bitcoin turmoil continues, crypto traders have taken to Telegram to voice their feelings. Crypto investors can reduce their anxiety about losses by joining the “Bear Market Screaming Therapy Group” on Telegram. How to Create a Private or Public Channel on Telegram? A few years ago, you had to use a special bot to run a poll on Telegram. Now you can easily do that yourself in two clicks. Hit the Menu icon and select “Create Poll.” Write your question and add up to 10 options. Running polls is a powerful strategy for getting feedback from your audience. If you’re considering the possibility of modifying your channel in any way, be sure to ask your subscribers’ opinions first.
from us


Telegram Bash Советы
FROM American