Linode.com Forum Forum Index Linode.com Forum
Linode Community Forums
 


Very easy/simple way to block traffic from an IP/range of IP

Click here to go to the original topic

 
       Linode.com Forum Forum Index -> Linux Networking
Author Message
melancthon



Joined: 08 Feb 2008
Posts: 12

Posted: Sun Apr 06, 2008 7:44 pm    Post subject: Very easy/simple way to block traffic from an IP/range of IP  

Well, I have some idiot repeatedly trying to ssh into my Linode. I was wondering if there is a very simple way for me to just drop all that traffic from that IP. My Linode's network server is hovering at a constant 10k bits/sec, and the CPU is right at 2.0% constant.

Help?
Back to top  
zunzun



Joined: 18 Feb 2005
Posts: 167
Location: Birmingham, Alabama USA

Posted: Sun Apr 06, 2008 8:13 pm    Post subject:  

As a stopgap measure, change the SSH port?

James
Back to top  
mwalling



Joined: 10 Dec 2007
Posts: 134

Posted: Sun Apr 06, 2008 8:25 pm    Post subject:  

iptables -A INPUT -s $IDOITS/$BLOCK -j DROP
Back to top  
rweir



Joined: 09 Jan 2008
Posts: 10

Posted: Sun Apr 06, 2008 8:26 pm    Post subject: Re: Very easy/simple way to block traffic from an IP/range o  

melancthon wrote: Well, I have some idiot repeatedly trying to ssh into my Linode. I was wondering if there is a very simple way for me to just drop all that traffic from that IP. My Linode's network server is hovering at a constant 10k bits/sec, and the CPU is right at 2.0% constant.

Help?

fail2ban can be setup to use iptables to block hosts that repeatedly attempt and fail to login. denyhosts is similar but uses tcpwrappers by default.
Back to top  
Xan



Joined: 08 Feb 2004
Posts: 297
Location: Austin

Posted: Sun Apr 06, 2008 8:57 pm    Post subject:  

I use just a handful of iptables rules to handle this. I think the whole Internet's being swept by these jerks, looking for an easy password. Try this:

Code: iptables -N SSHSCAN
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSHSCAN
iptables -A SSHSCAN -m recent --set --name SSH
iptables -A SSHSCAN -m recent --update --seconds 300 --hitcount 3 --name SSH -j DROP

from http://www.ducea.com/2006/06/28/using-iptables-to-block-brute-force-attacks/

This blocks any new SSH attempts from an IP which has attempted 3 in the previous five minutes. It really puts the brakes on the brute force attacks.

Whitelisting your own IPs first is recommended, in case you open a bunch of connections within the time frame.

[edited to correct double-dashes]
Back to top  
mwalling



Joined: 10 Dec 2007
Posts: 134

Posted: Sun Apr 06, 2008 9:18 pm    Post subject:  

Xan wrote: Whitelisting your own IPs first is recommended, in case you open a bunch of connections within the time frame.

i learned this the hard way when completing scp with bash-completion turned on... every time you hit tab, it opened a new connection to the host
Back to top  
melancthon



Joined: 08 Feb 2008
Posts: 12

Posted: Sun Apr 06, 2008 10:06 pm    Post subject:  

Many thanks for the quick responses - I was a bit afraid of the sheer complexity that iptables can have, but the webmin interface for it wasn't too bad. For the time being I am just dropping all packets from the IP address; hopefully that will do the trick. I will look into these other options (such as ssh ports and addresses) as further measures as well. Thanks!
Back to top  
ywliu



Joined: 08 Apr 2005
Posts: 19

Posted: Sun Apr 06, 2008 10:40 pm    Post subject:  

I have been using this less-known tool for quite a time. Very effective to prevent from SSH/FTP probing.

blockhosts.py

http://www.aczoom.com/cms/blockhosts

Try it and you may love it as I do.

ywliu
Back to top  
reallove



Joined: 27 Dec 2007
Posts: 8
Location: Cluj-Napoca , Romania

Posted: Mon Apr 07, 2008 2:58 am    Post subject:  

I use this for blocking unwanted sshd connections.
Pretty good and effective.
Back to top  
chrisnolan



Joined: 02 Jun 2006
Posts: 15

Posted: Tue Apr 08, 2008 3:46 pm    Post subject:  

try also the package "denyhosts"

http://denyhosts.sourceforge.net/

HTH
C
Back to top  
Xan



Joined: 08 Feb 2004
Posts: 297
Location: Austin

Posted: Tue Apr 08, 2008 3:54 pm    Post subject:  

I don't understand why you would install extra packages and extra software to do a job that can be done by four iptables commands. "Keep it simple" would definitely be my philosophy for something like this.

Not only that, but the method I outlined above doesn't involve any permanent IP banning, which I like to avoid whenever possible.
Back to top  
kbrantley



Joined: 21 Sep 2007
Posts: 20

Posted: Tue Apr 08, 2008 4:12 pm    Post subject:  

Xan wrote: I don't understand why you would install extra packages and extra software to do a job that can be done by four iptables commands. "Keep it simple" would definitely be my philosophy for something like this.

Not only that, but the method I outlined above doesn't involve any permanent IP banning, which I like to avoid whenever possible.

And it's a great method. Thanks for that, I'm using it (slightly modified) now.
Back to top  
melancthon



Joined: 08 Feb 2008
Posts: 12

Posted: Tue Apr 08, 2008 4:35 pm    Post subject:  

However, those 4 iptables commands require the use of other modules which I can't seem to get working for iptables.

I'm using fail2ban presently which is seeming to do the trick as well as notifying me when it happens with the IP, so I can put on my diplomat hat and send nasty emails to support people requesting action!
Back to top  
Xan



Joined: 08 Feb 2004
Posts: 297
Location: Austin

Posted: Tue Apr 08, 2008 4:40 pm    Post subject:  

Certainly all these methods will work just fine. And the advantage of having so many options is if you have trouble with one you can try another.

But I'm surprised you're having trouble with iptables modules. They were part of the Linode kernel, at least when I started using them. Are you running the latest kernel?
Back to top  
Xan



Joined: 08 Feb 2004
Posts: 297
Location: Austin

Posted: Tue Apr 08, 2008 9:49 pm    Post subject:  

melancthon described his error messages in a PM, and it turns out what was in my post won't work verbatim. All the double-dashes are some kind of fancy Unicode dash, perhaps the result of the CMS on the site I got them from. I'm correcting the original post so that the commands should work.
Back to top  
 
       Linode.com Forum Forum Index -> Linux Networking
Page 1 of 1