{"id":21573,"date":"2016-07-08T03:01:59","date_gmt":"2016-07-07T17:01:59","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=21573"},"modified":"2016-06-21T18:18:58","modified_gmt":"2016-06-21T08:18:58","slug":"apache-ip-blocking-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/apache-ip-blocking-primer-tutorial\/","title":{"rendered":"Apache IP Blocking Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Apache\/block_htaccess.jpg\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Apache IP Blocking Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Apache\/block_htaccess.jpg\" title=\"Apache IP Blocking Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Apache IP Blocking Primer Tutorial<\/p><\/div>\n<p>With Apache web servers you can use <i>.htaccess<\/i> files at the document root directory corresponding to website URLs to control various aspects to do with access to that website, or even directory of website.<\/p>\n<p>Some preparatory matters generic to <i>.htaccess<\/i> usage that would happen within the Apache configuration file called <i>httpd.conf<\/i> would be useful before us explaining how to use them to block access to <a target=_blank href='https:\/\/en.wikipedia.org\/wiki\/IP_address' title='Internet Protocol address information from Wikipedia'>IP<\/a> or IP ranges from access to directories &#8230;<\/p>\n<ul>\n<li><i>AccessFileName &#8220;access.config&#8221;<\/i> &#8230; would rename the <i>.htaccess<\/i> file naming convention to <i>access.config<\/i> (for our example)<\/li>\n<li><i>AllowOverride All<\/i> &#8230; allows <i>.htaccess<\/i> usage to be allowed versus <i>\tAllowOverride All|None|directive-type [directive-type]<\/i><\/li>\n<li>Directory by directory determination of <i>.htaccess<\/i> usage &#8230;<br \/>\n<code><br \/>\n&lt;Directory \"\/www\/htdocs\/usehtaccess\"&gt;<br \/>\n    AllowOverride All<br \/>\n&lt;\/Directory&gt;<br \/>\n<b><\/b><br \/>\n&lt;Directory \"\/www\/htdocs\/donotusehtaccess\"&gt;<br \/>\n    AllowOverride None<br \/>\n&lt;\/Directory&gt;<br \/>\n<\/code><\/li>\n<\/ul>\n<p>Okay, so now we are ready to talk about blocking an IP or IP range from accessing an Apache web server directory. Below is a <i>.htaccess<\/i> blocking IP addresses <i>xx.xx.xxx.110<\/i> and <i>xx.xx.xxx.112<\/i> &#8230;<\/p>\n<p><code><br \/>\nOrder Deny,Allow<br \/>\nDeny from xx.xx.xxx.110<br \/>\nDeny from xx.xx.xxx.112<br \/>\n<\/code><\/p>\n<p>If you&#8217;re worried about the syntax run the scenario through this <a target=_blank title='IP .htaccess blocking checker' href='http:\/\/www.htaccesstools.com\/block-ips\/'>link<\/a>.<\/p>\n<p>Take a look at this <i>ls -la .htaccess<\/i> &#8230;<\/p>\n<p><code><br \/>\n-rw-r--r-- 1 root root 852 Apr 23 07:56 .htaccess<br \/>\n<\/code><\/p>\n<p> &#8230; these are suitable permissions for a <i>.htaccess<\/i> file &#8230; perhaps your <i>owner<\/i> and <i>group<\/i> may be different, but <i>chmod 644 .htaccess<\/i> gives recommended permissions as above.<\/p>\n<p><a target=_blank title='Google search useful link' href='https:\/\/www.google.com.au\/#q=apache+access+log+file&#038;gws_rd=cr'>This link<\/a> and <a target=_blank title='Useful link' href='http:\/\/unix.stackexchange.com\/questions\/38978\/where-are-apache-file-access-logs-stored'>this<\/a> gave us good advice regarding checking Access Logs before or after this work to check things out (that is, if you don&#8217;t use the <a target=_blank title='cPanel Apache Status report' href='https:\/\/documentation.cpanel.net\/display\/1142Docs\/Apache+Status'>cPanel Apache Status report<\/a> option) &#8230;<\/p>\n<blockquote><p>\nLook for CustomLog directives in your Apache configuration, see the manual for examples. A typical location for all log files is \/var\/log and subdirectories. Try \/var\/log\/apache\/access.log or \/var\/log\/apache2\/access.log . If the logs aren&#8217;t there, try running locate access.log\n<\/p><\/blockquote>\n<p>We leave you with a very useful <a target=_blank title='Apache .htaccess information' href='https:\/\/httpd.apache.org\/docs\/current\/howto\/htaccess.html'>webpage<\/a> regarding the topic of <i>.htaccess<\/i> files, generally.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#21573' onclick='var dv=document.getElementById(\"d21573\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/OTblog\/tag\/apache\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d21573' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>With Apache web servers you can use .htaccess files at the document root directory corresponding to website URLs to control various aspects to do with access to that website, or even directory of website. Some preparatory matters generic to .htaccess &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/apache-ip-blocking-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,25,37],"tags":[42,85,149,249,1862,707,1764,1114,1319,1339,1411],"class_list":["post-21573","post","type-post","status-publish","format-standard","hentry","category-elearning","category-networking","category-tutorials","tag-htaccess","tag-apache","tag-blocking","tag-configuration","tag-http-config","tag-linux","tag-reporting","tag-security","tag-tutorial","tag-unix","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21573"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=21573"}],"version-history":[{"count":2,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21573\/revisions"}],"predecessor-version":[{"id":21575,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21573\/revisions\/21575"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=21573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=21573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=21573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}