Tips: automatically block IP addresses that are illegally connected to FTP

Source: Internet
Author: User
Article Title: tips: automatically block IP addresses that are illegally connected to FTP. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Because FTP downloading is provided and threads are limited, it is found that many threads are constantly trying. This will greatly increase the load on the server. this will "harm people and do nothing "!
  
In order to punish such a person, he decided to write a SHELL and run it every minute in crond, automatically counting the IP address and thread quantity of illegal threads, and then automatically writing his IP address to iptables, to punish them!
  
Vi/usr/local/sbin/fuckgo
[Code: 1: f4eccf4a6f]
#! /Bin/bash
Fuck_who ()
{
Netstat-an | grep "210.51.184.197: 21" | grep-v LISTEN | grep-v ESTABLISHED | awk '{print $5 ;} '| awk-f' = ''{print $1;}' | sort | uniq-c | awk '{print $1" = "$2 ;}'
}
  
For _ un in $ (fuck_who)
Do
If [$ (echo $ _ un | awk-f' = ''{print $1;} ')-gt 9]
Then
Iptables-I INPUT-s $ (echo $ _ un | gawk-f' = ''{print $2;} ')-p tcp -- dport 21-j DROP
Fi
Done
[/Code: 1: f4eccf4a6f]
  
Vi/etc/crontab
Add
[Code: 1: f4eccf4a6f]
00-59/1 * root/usr/local/sbin/fuckgo
[/Code: 1: f4eccf4a6f]
/Etc/rc. d/init. d/crond restart
  
For more information, see
[Img: f4eccf4a6f] http://platinum.3322.org/mrtg/proftpd-day.png#/img:f4eccf4a6f]
From the figure, we can see that [color = blue: f4eccf4a6f] [B: f4eccf4a6f] blue [/B: f4eccf4a6f] [/color: f4eccf4a6f] has a very high instantaneous value, it won't last long, because that person's IP address has already entered the iptables "blacklist"
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.