우선, 바퀴를 재발 명하지 마십시오. 그것은 정확히 무엇 denyhosts을위한 것입니다 :
DenyHosts is a python program that automatically blocks ssh attacks by
adding entries to /etc/hosts.deny. DenyHosts will also inform Linux
administrators about offending hosts, attacked users and suspicious
logins.
내가 아는 한, 연결 denyhosts전용 ssh이지만
fail2ban거의 모든 것을 처리하는 것도 있습니다.
Fail2Ban consists of a client, server and configuration files to limit
brute force authentication attempts.
The server program fail2ban-server is responsible for monitoring log
files and issuing ban/unban commands. It gets configured through a
simple protocol by fail2ban-client, which can also read configuration
files and issue corresponding configuration commands to the server.
둘 다 리포지토리에서 사용할 수 있습니다.
sudo apt-get install denyhosts fail2ban
원하는 경우 스크립트를 작성할 수도 있습니다. 다음과 같은 것 :
#!/usr/bin/env sh
netstat -an |
awk -vmax=100 '/tcp/{split($5,a,":"); if(a[1] > 0 && a[1]!="0.0.0.0"){c[a[1]]++}}
END{for(ip in c){if(c[ip]>max){print ip}}}' |
while read ip; do iptables -I INPUT 1 -s "$ip" -j DROP; done
는 awkIP에를 추출하여 계산 만 개 이상의 나타나는 그 인쇄됩니다 max(여기 번 -vmax=100, 그에 따라 변경). 그런 다음 IP는 관련 iptables규칙 을 실행하는 while 루프로 공급됩니다 .
이 연중 무휴를 실행하려면 매분 정도 명령을 실행하는 cronjob을 만듭니다. 이 줄을 추가/etc/crontab
* * * * * root /path/to/script.sh