Blocking IP addresses
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:30:00
Is there a way to block a certain IP address from accessing your domain?
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:30:00
Is there a way to block a certain IP address from accessing your domain?
Posted by: rlparker
Posted on: 2008-02-02 20:37:00
Yes. You can do it using an .htaccess file:
http://wiki.dreamhost.com/KB_/_Unix_/_.htaccess_files#Deny.2FAllow_Certain_IP_Addresses
--rlparker
Posted by: scjessey
Posted on: 2008-02-02 20:40:00
In reply to:Is there a way to block a certain IP address from accessing your domain?
Indeed their is. If you don't already have one, create an .htaccess in your domain folder. You can block access to specific IP addresses by adding the following line:
deny from xxx.xxx.xxx.xxx
You can have as many of these as you like, but bear in mind that IP addresses often change and they can sometimes be shared by thousands of users; therefore, you may wish to review the blocks after a certain period of time has passed.
-- si-blog --
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:44:00
Thank you for the reply.
Pardon all the questions, but the only .htaccess files I have created is just password-protecting a subfolder. I'm not sure where to put the 'deny from [IP address]' line. I looked at the wiki, but the how-to looked really complicated for creating a .htaccess file on a Mac. Is there a simple way to create one?
Edited by wastedlifeofjack on 02/02/08 08:46 PM (server time).
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:45:00
Thank you for the reply.
Does creating a .htaccess file on Windows work the same as on a Mac? The Wiki article said to just open a text editing program and copy that line of text in there and upload it to the domain. Am I understanding that correctly?
Posted by: rlparker
Posted on: 2008-02-02 20:50:00
Yep. That's about all there is to it! ![]()
--rlparker
Posted by: scjessey
Posted on: 2008-02-02 20:51:00
You can use any text editor to create the file (on any operating system). You must save the file as .htaccess (a period followed by "htaccess"). Some text editors automatically append .txt to the end of the filename, which would stop the file from working. You can always upload the file in that state and then rename it to the correct filename. Bear in mind that your FTP client may "hide" this type of file from a directory listing.
-- si-blog --
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:52:00
Thanks for all the help! :)
Posted by: wastedlifeofjack
Posted on: 2008-02-02 20:54:00
Thanks! I just uploaded it and renamed the file to .htaccess. It doesn't matter if there was already another .htaccess file there to begin with, does it? I have one there from when I password-protected the domain.
Edited by wastedlifeofjack on 02/02/08 08:54 PM (server time).
Posted by: rlparker
Posted on: 2008-02-02 21:56:00
In reply to:I just uploaded it and renamed the file to .htaccess. It doesn't matter if there was already another .htaccess file there to begin with, does it? I have one there from when I password-protected the domain.
Yikes! Yes, it *does* matter, very much, that there is already an .htaccess file already there!
As you can only have one .htaccess file in any directory, if you do that, the "new" one will "overwrite" the other one. In this case, that will "disable" your .htaccess based password protection.
Not to worry, there are (at least) two ways you can deal with this problem:
1) You can combine the contents of the two .htaccess files into a single .htaccess file
2) Since your first .htaccess file was designed to provide password protection for a directory, you can leave it in the directory you want protected (assuming that it is a subdirectory of your main site - as in yourdomain.tld/private) and place the .htaccess file that denies access to given IP addresses in the directory *above* that one (as in yourdomain.tld). That way, the .htaccess file in the subdirectory will provide password protection for the directory it is in, while the .htaccess file in the parent directory will prevent access to the whole site from those IP addresses.
--rlparker
Posted by: wastedlifeofjack
Posted on: 2008-02-02 23:43:00
Thank you! I got it sorted out. :)
Posted by: rlparker
Posted on: 2008-02-02 23:50:00
You're welcome, and congratulations! I'm really glad you have it working! ![]()
--rlparker
Posted by: wastedlifeofjack
Posted on: 2008-02-02 23:57:00
Me too! It's a huge weight off of my shoulders. Thanks again. :)