Fail2Ban
Setup
Configure
Make a copy of jail.conf as jail.local and edit it to configure. Do not edit jail.conf as it will get overwritten when fail2ban updates.
After updating jail.local file restart fail2ban and check the status.
Monitor realtime activity
NGINX access log
# Realtime
tail -f /var/log/nginx/access.log
# Highest count
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -20
# Today
grep "$(date '+%d/%b/%Y:%H')" /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head
Monitoring through additional tools
Quick “who are they?” (country/ASN)
sudo apt update && sudo apt install geoip-bin -y
# Lookup top 10 IPs and their location
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10 | awk '{print $2}' | xargs -I{} geoiplookup {}