Disable illegal IP login server

Source: Internet
Author: User

Check the online server log today/var/log/secure found a lot of foreign IP attempts to log on to the server, has not been much attention to this aspect, as a system administrator is a dereliction of duty ah, although the server has set a strong password, but see someone want to engage you still very uncomfortable. At the beginning of the idea is through the firewall, and then Google to have a more simple than the firewall of the method, that is, through the/etc/hosts.deny configuration file can be banned some IP, the code is as follows:

#!/bin/bashCat/var/log/secure|awk'/failed/{print $ (NF-3)}'|sort|uniq-c|awk'{print $ = "$";}'>/root/black.txtcounts="2" forIteminch' cat/root/black.txt ' do IP= ' echo $item | awk-f='{print $}'' NUM= ' echo $item | awk-f='{print $}'`    if[$NUM-gt $Counts];then grep $IP/etc/hosts.deny >/dev/NULLif[ $? -GT 0];then Echo"sshd: $IP:d eny">>/etc/Hosts.deny fi fidone

Not to be continued ....

Disable illegal IP login server

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.