This guide covers practical steps to monitor, detect, and prevent anomalies on Linux servers (Arch Linux-based), including protection of Apache, MariaDB, and against DDoS attacks.
journalctl)sudo pacman -S htop atop vnstat iftop audit
journalctl -p err..alert --since "1 hour ago"
journalctl -u sshd
journalctl -u httpd
journalctl -u mariadb
ausearch -m USER_LOGIN,USER_CMD
ps aux --sort=-%cpu | head
ss -tuln
find /etc /bin -type f -mtime -1
grep "access denied" /var/log/mysql/*
tail -n 100 /var/log/httpd/access_log
ufw, iptables
PermitRootLogin no
PasswordAuthentication no
AllowUsers youruser
sudo pacman -S fail2ban
sudo systemctl enable --now fail2ban
[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log
maxretry = 3
[apache-auth]
enabled = true
port = http,https
logpath = /var/log/httpd/error_log
maxretry = 5
Restart:
sudo systemctl restart fail2ban
sudo pacman -S apache
sudo nano /etc/httpd/conf/httpd.conf
# Add or enable:
ServerTokens Prod
ServerSignature Off
TraceEnable Off
Options -Indexes
sudo pacman -S modsecurity-apache
sudo mysql_secure_installation
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;
SHOW VARIABLES LIKE 'slow_query_log%';
iptables or nftables
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j DROP
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -f -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
#!/bin/bash
journalctl -p err..alert --since "1 hour ago" > /var/log/hourly_errors.log
fail2ban-client status >> /var/log/hourly_errors.log
vnstat --oneline >> /var/log/hourly_errors.log
Place script in /etc/cron.hourly/ or systemd timer.
sudo pacman -S goaccess
goaccess /var/log/httpd/access_log -o report.html --log-format=COMBINED