{"id":667,"date":"2024-01-03T12:58:47","date_gmt":"2024-01-03T12:58:47","guid":{"rendered":"https:\/\/linuxresellerwebhosting.in\/blog\/?p=667"},"modified":"2024-01-03T13:04:07","modified_gmt":"2024-01-03T13:04:07","slug":"block-ip-addresses-htaccess-file","status":"publish","type":"post","link":"https:\/\/linuxresellerwebhosting.in\/blog\/block-ip-addresses-htaccess-file\/","title":{"rendered":"Step-by-step block IP addresses with .htaccess file."},"content":{"rendered":"<h2><span class=\"ez-toc-section\" id=\"Steps_to_Block_IP_Addresses_with_htaccess_file\"><\/span>Steps to Block IP Addresses with .htaccess file<span class=\"ez-toc-section-end\"><\/span><\/h2><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxresellerwebhosting.in\/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-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/block-ip-addresses-htaccess-file\/#To_Deny_a_Specific_IP_Address\" >To Deny a Specific\u00a0IP Address<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxresellerwebhosting.in\/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:\/\/linuxresellerwebhosting.in\/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:\/\/linuxresellerwebhosting.in\/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><\/nav><\/div>\n\n<p>Here in this post i am going to explain using .htacess file\u00a0 how to deny an IP address or how to allow only a particular IP address to access your site<\/p>\n<p>The .htaccess file is a configuration file used on web servers running the<a href=\"https:\/\/httpd.apache.org\/\" target=\"_blank\" rel=\"noopener\"> Apache web server<\/a> software.<\/p>\n<p>It allows you to make various configurations for your website at the directory level. If you want to block access from a specific IP address or a range of IP addresses, you can use the following directives in your .htaccess file<\/p>\n<p>This will helps and useful for you to protect your websites 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<h3><span class=\"ez-toc-section\" id=\"To_Deny_a_Specific_IP_Address\"><\/span>To Deny a Specific\u00a0IP Address<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Type the below code it will only deny one IP address from accessing the website.<\/p>\n<p>\u200b\u200bDeny from 185.0.0.1<\/p>\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<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-669 size-full\" src=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/01\/htaccess.png\" alt=\".htaccess file\" width=\"757\" height=\"378\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/01\/htaccess.png 757w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/01\/htaccess-300x150.png 300w\" sizes=\"auto, (max-width: 757px) 100vw, 757px\" \/><\/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 domains by adding the below line of code to your .htaccess file.<\/p>\n<p>Deny from 185.0.0.1\/255.255.255.0<\/p>\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<p>\u200bDeny from 111.111.111.111 222.222.222.222 333.333.333.333<\/p>\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<p>Order Deny,Allow<br \/>\nDeny from all<br \/>\nAllow from 111.111.111.111<\/p>\n<p>Here we first deny all visitors, and then allow only the visitor from the IP address specified above.<\/p>\n<p>Keep in mind that while using <code>.htaccess<\/code> for basic blocking can be effective, more advanced security measures may be required for comprehensive protection. Additionally,<\/p>\n<p>if you&#8217;re using a different web server software or hosting environment, the configuration method may differ.<\/p>\n<p>Mostly few websites are throws 403 forbidden error don&#8217;t get panic, <a href=\"https:\/\/linuxresellerwebhosting.in\/blog\/what-is-403-forbidden-error\/\">click here<\/a> to know more about.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps to Block IP Addresses with .htaccess file Here in this post i am going to explain using .htacess file\u00a0<\/p>\n","protected":false},"author":2,"featured_media":669,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[2,1],"tags":[24,25,30],"class_list":["post-667","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-uncategorized","tag-allow","tag-deny","tag-ip-address"],"_links":{"self":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=667"}],"version-history":[{"count":7,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":675,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/667\/revisions\/675"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/669"}],"wp:attachment":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}