• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

How to block a ip ?

zirkov

New Member
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 ?
 
if your server has .htaccess support, put this in the web root folder.

Code:
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
 
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...
 
Depends on the OS...That .htaccess will keep them from accessing pages but they still hit Apache.

FreeBSD it is:
Code:
ipfw add deny tcp from i.p.add.ress to any 80 in
Linux:
Code:
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:
Code:
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:

Code:
eval ipfw add deny tcp from ip.add.re.ss to any 80 in
 
Last edited:
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
 
Last edited:
Back
Top