{"id":1237,"date":"2019-02-20T00:44:32","date_gmt":"2019-02-19T19:14:32","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=1237"},"modified":"2019-03-11T10:29:05","modified_gmt":"2019-03-11T04:59:05","slug":"block-ip-addresses-htaccess-file","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/","title":{"rendered":"Steps to Block IP Addresses with .htaccess file."},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/#Steps_to_Block_IP_Addresses_with_htaccess_file\" >Steps to Block IP Addresses with .htaccess file<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/#To_Deny_a_Specific_IP_Address\" >To Deny a Specific&nbsp;IP Address<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/#To_Deny_a_Specific_Domain\" >To Deny a Specific Domain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/#To_Deny_Multiple_IPs_in_a_Single_Line_of_Code\" >To Deny Multiple IP\u2019s in a Single Line of Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/block-ip-addresses-htaccess-file\/#To_Allow_Only_a_Single_IP\" >To Allow Only a Single IP<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Steps_to_Block_IP_Addresses_with_htaccess_file\"><\/span><span style=\"text-decoration: underline;\">Steps to Block IP Addresses with .htaccess file<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Here in this post i am going to explain how to deny an IP address or how to allow only a particular IP address to access your site<\/p>\n<p>This will helps and useful for you to protect your <a  href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/easy-way-to-config-local-mail-server-using-post-fix-dovecot-and-squirrel-mail-on-cent-os-6\/\" title=\"websites\" alt=\"websites\">websites<\/a> from hackers or to block any unwanted visitors.<\/p>\n<p>For this you need to create an .htaccess file in your public_html folder and add these lines below, based on your requirements.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"To_Deny_a_Specific_IP_Address\"><\/span>To Deny a Specific&nbsp;IP Address<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Type the below code it will only <a  href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/easy-steps-to-install-and-configure-lamp-in-centos-7\/\" title=\"deny\" alt=\"deny\">deny<\/a> one IP address from accessing the website.<\/p>\n<pre>\u200b\u200bDeny from 185.0.0.1<\/pre>\n<p>Just change the above IP address to the IP address that you want to deny and paste it in the .htaccess file.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"To_Deny_a_Specific_Domain\"><\/span>To Deny a Specific Domain<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>We can able to deny a specific domain from accessing our <a href=\"https:\/\/www.squarebrothers.com\/domain-registration-india\/\" rel=\"nofollow noopener\" target=\"_blank\">domains<\/a> by adding the below line of code to your .htaccess file.<\/p>\n<pre>Deny from 185.0.0.1\/255.255.255.0<\/pre>\n<p>You need to change the IP address and netmask value to match the domain that you want to block.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"To_Deny_Multiple_IPs_in_a_Single_Line_of_Code\"><\/span>To Deny Multiple IP\u2019s in a Single Line of Code<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>For this you leave a blank space with each IP for separation.<\/p>\n<pre>\u200bDeny from 111.111.111.111 222.222.222.222 333.333.333.333<\/pre>\n<p>All you need to do is replace the IPs that you want to deny and paste it in the .htaccess file.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"To_Allow_Only_a_Single_IP\"><\/span>To Allow Only a Single IP<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The below set of .htaccess rule will deny access to your website from every IP address expect the IP address mentioned in the rule.<\/p>\n<pre>Order Deny,Allow\r\nDeny from all\r\nAllow from 111.111.111.111<\/pre>\n<p>Here we first deny all visitors, and then allow only the visitor from the IP address specified above.<\/p>\n<p>To check log entries for total no of connections to a Port From an IP Address.<a href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/making-log-entries-for-total-no-of-connections-to-a-port-from-an-ip-address\/\">click<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps to Block IP Addresses with .htaccess file Here in this post i am going to explain how to deny an IP address or how to allow only a particular IP address to access your site This will helps and useful for you to protect your websites from hackers or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1254,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[17,3,1],"tags":[132,134,130],"class_list":["post-1237","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","category-linux","category-latest","tag-htaccess","tag-deny","tag-ip-addresses"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2019\/02\/IP-address.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-jX","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1237"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1237\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1254"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}