PDA

View Full Version : How to block a ip ?



zirkov
November 18th, 2007, 09:27
I'm new in server, I know some basic linux command. Last day I found someone try downloading from my server with multiple connection. My question is, how to block his IP accessing my web/server ?

Secret
November 18th, 2007, 10:31
if your server has .htaccess support, put this in the web root folder.


order deny,allow
allow from all
deny from 123.123.123.123

replace 123.123.123.123 with the ip number you wish to block

sellwhm
November 18th, 2007, 10:54
You can use csf firewall(cpanel servers) and apf firewall to block the multiple connections too. If you got cpanel/whm, you can use cpanel to block the connection too with the Cpanel IP Deny feature. The csf firewall has an easy method of dealing with this...You just add the IP to the firewall....No file editing neccessary...

serverorigin
November 18th, 2007, 13:57
Depends on the OS...That .htaccess will keep them from accessing pages but they still hit Apache.

FreeBSD it is:

ipfw add deny tcp from i.p.add.ress to any 80 in

Linux:

iptables -D INPUT -s 25.55.55.55 -j DROP --- which would drop connections to all ports... or:
iptables -A INPUT -s 25.25.25.25 -p tcp –destination-port 80 -j DROP

The second drops connections for the specified IP to port 80

To make it permanent:


vi /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -s OFFENDING-IP -j DROP
-A RH-Firewall-1-INPUT -s OFFENDING-SUBNET-BLOCK -j DROP

/etc/init.d/iptables restart

In FreeBSD it is a little more in depth as it depends on what you are calling as your firewall configuration but you would edit that file and add in something like:



eval ipfw add deny tcp from ip.add.re.ss to any 80 in

zirkov
November 18th, 2007, 15:46
I'm using Debian, I will try it to my server. I hope my server going normal again

arizonadream
November 19th, 2007, 03:18
If you are using iptables, you can use the scripts
#!/bin/bash
sudo iptables -I INPUT -s $1 -j DROP
sudo bash -c "iptables-save > /etc/network/iptables.save"
Then you run

block xxx.xx.xxx.xx

and in your /etc/network/interfaces file add at the bottom post-up iptables-restore /etc/network/iptables.save

zirkov
November 20th, 2007, 09:58
I have question again. I want to know how to limit download connection per IP ?

serverorigin
November 20th, 2007, 17:31
On Debian and most any linux that doesn't use ipfw -- it is stupidly difficult.

Check out: http://www.knowplace.org/pages/howtos/traffic_shaping_with_linux.php

Plenty of information and examples. I would suggest if you want simple traffic shaping and such - use FreeBSD.