Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've had thousands of attempted breakins from a couple of IPs. When I investigate the IP, I see they are definitely on the naughty list.
It looks like I can block them using:
Code:
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP
PS. What is the "MASK" part all about?
Yes, I know if my server is perfectly configured, I probably don't have anything to worry about. Try as I might, I am concerned that maybe I didn't do something perfect.
PS. Is there an online service that I can have interrogate my IP and look for holes?
So, instead of waiting for thousands of attempted breakins, am I able to subscribe to some service which automatically adds IPs that have been previously known to be malicious? I am not worried about accidentally blocking good guys as the server is only accessed by me (I don't wish to whitelist as I often access the server remotely from different IPs).
While I don't know of any global list you could use, have you looked into denyhosts? It monitors your /var/log/messages or /var/log/secure log files for failed access attempts and adds them to hosts.deny automatically. You can configure it to be a permanent ban, a temporary ban that lasts for N days, you can configure the number of failed attempts in a given amount of time for the IP to be banned, and it can treat root login attempts and user login attempts differently as well.
I run it on my home server, and over the last ~3 months (since I re-installed the OS) it's already added over 300 IPs to the ban list. I'll paste them below if you're interested.
One of the nice things about how it works is that if it adds an IP by mistake, all you have to do is put that IP in hosts.allow to whitelist it.
Every once in a while I'll get bored and start investigating some of them. So far they all seem to be from Russia or China. Probably some 13 year old idiot wannabe "hackers" running a pre-canned script to try and brute-force root access via ssh.
Last edited by suicidaleggroll; 10-24-2014 at 12:41 PM.
I also found denyhosts very useful. One additional measure is to use a non standard port for ssh. You could just forward a different port (say 1234) on your router to port 22 on the PC. This makes /etc/hosts.deny a bit shorter.
Looks like denyhosts just protects again ssh (which is probably most important) while fail2ban is more wide reaching (and probably more complicated). Still undecided on which one to use. Thoughts?
once the IP is added to hosts.deny it will be blocked for all services.
...note this only works for services that are compiled with libwrap. Also see this and this.
Quote:
Originally Posted by NotionCommotion
fail2ban is more wide reaching (and probably more complicated).
That's a misconception. Fail2ban comes with default filters for over 60 services, works with minimal configuration, works at the network level and can use ipset (meaning you only need one iptables rule!).
But would you recommend it for an amateur server guy who has a linux server for web development purposes only which is located on his LAN along with his family's various apple/windows/tv clients?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.