Premium Content
This advanced tutorial is reserved for premium members.
9,90€ / month
- All advanced tutorials
- New content every week
- Progress tracking
- Cancel anytime
Tutorial to install and configure Portsentry, a tool that detects port scans and blocks attackers' IP addresses.
This advanced tutorial is reserved for premium members.
BLOCK_TCP and BLOCK_UDP are still set to 0, which is detection-only mode: the event is logged and nothing else happens. Or KILL_ROUTE is still commented out, or does not match your firewall — an iptables command on a system that only runs firewalld will fail silently. Uncomment the right line, set both BLOCK_* values to 2, then restart the service.1 adds the IP to /etc/hosts.deny. That file is only consulted by services built against TCP wrappers, which has become rare, so the protection is very partial. Value 2 runs the KILL_ROUTE command and inserts a real firewall rule, blocking all traffic from that IP whatever service it targets. On a modern system, 2 is the only sensible choice.INPUT chain, so just delete it: sudo iptables -D INPUT -s BLOCKED_IP -j DROP. Then confirm with sudo iptables -L INPUT -n that it is gone. Under firewalld, the --timeout=600 variant of the rich rule avoids the problem entirely since the block expires by itself after the delay.TCP_MODE="atcp" and UDP_MODE="audp" in /etc/default/portsentry, it listens on every unassigned port and catches far more scanners. The trade-off is a higher risk of false positives, so have your unblocking procedure ready before enabling them.nmap -p 1-1024 YOUR_SERVER_IP, but it must come from a machine whose IP you can afford to lose — definitely not your admin workstation, and not the IP your SSH session is coming from. During the scan, follow sudo tail -f /var/log/syslog (or /var/log/messages on CentOS): you will see the alert and then the addition to the block list, confirmed by sudo iptables -L INPUT -n.Did you enjoy this article?
Comments