{"id":2582,"date":"2021-10-04T05:29:02","date_gmt":"2021-10-04T05:29:02","guid":{"rendered":"https:\/\/ownwebservers.com\/kb\/?p=2582"},"modified":"2021-10-04T05:33:23","modified_gmt":"2021-10-04T05:33:23","slug":"2582","status":"publish","type":"post","link":"https:\/\/ownwebservers.com\/kb\/2582\/","title":{"rendered":"How to Block IP Addresses with .htaccess"},"content":{"rendered":"<p>In this tutorial we are going to see how to deny an IP address or how to allow only a particular IP address to access your web site. This is often very helpful to protect your web site from hackers or to block unwanted visitors.<\/p>\n<p>You need to create an .htaccess file in your public_html folder and based on your requirements add the lines as given below.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"primary\" class=\"site-content\">\n<div id=\"content\" role=\"main\">\n<p><a href=\"https:\/\/www.veerotech.net\/kb\/\">Knowledgebase Home<\/a>\u00a0\/\u00a0How to Block IP Addresses with .htaccess<\/p>\n<article id=\"post-2207\" class=\"post-2207 post type-post status-publish format-standard hentry category-how-to-guide category-networking category-reseller-hosting category-shared-hosting category-wordpress\">\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">How to Block IP Addresses with .htaccess<\/h1>\n<\/header>\n<div class=\"entry-content\">\n<p>This tutorial will explain how to deny an IP address or how to allow only a particular IP address to access your website. This is extremely useful to protect your website from hackers or to block unwanted visitors.<\/p>\n<p>You need to create an\u00a0<a href=\"https:\/\/codex.wordpress.org\/htaccess\">.htaccess file<\/a>\u00a0in your public_html folder and add these lines below, based on your requirements.<\/p>\n<div class=\"lwptoc lwptoc-autoWidth lwptoc-baseItems lwptoc-light lwptoc-notInherit\" data-smooth-scroll=\"1\" data-smooth-scroll-offset=\"24\" data-lwptoc-initialized=\"1\">\n<div class=\"lwptoc_i\">\n<div class=\"lwptoc_header\"><b class=\"lwptoc_title\">Contents<\/b>\u00a0<span class=\"lwptoc_toggle\">\u00a0<a class=\"lwptoc_toggle_label\" href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#\" data-label=\"show\">hide<\/a>\u00a0<\/span><\/div>\n<div class=\"lwptoc_items lwptoc_items-visible\">\n<div class=\"lwptoc_itemWrap\">\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#To_Deny_a_Specific_IP_Address\"><span class=\"lwptoc_item_number\">1<\/span>\u00a0<span class=\"lwptoc_item_label\">To Deny a Specific IP Address<\/span><\/a><\/div>\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#To_Deny_a_Specific_Domain\"><span class=\"lwptoc_item_number\">2<\/span>\u00a0<span class=\"lwptoc_item_label\">To Deny a Specific Domain<\/span><\/a><\/div>\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#To_Deny_Multiple_IPs_in_a_Single_Line_of_Code\"><span class=\"lwptoc_item_number\">3<\/span>\u00a0<span class=\"lwptoc_item_label\">To Deny Multiple IP\u2019s in a Single Line of Code<\/span><\/a><\/div>\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#To_Allow_Only_a_Single_IP\"><span class=\"lwptoc_item_number\">4<\/span>\u00a0<span class=\"lwptoc_item_label\">To Allow Only a Single IP<\/span><\/a><\/div>\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#To_Deny_a_Single_IPv6_Address\"><span class=\"lwptoc_item_number\">5<\/span>\u00a0<span class=\"lwptoc_item_label\">To Deny a Single IPv6 Address<\/span><\/a><\/div>\n<div class=\"lwptoc_item\"><a href=\"https:\/\/www.veerotech.net\/kb\/how-to-block-ips-with-htaccess\/#Our_Guiding_Principles\"><span class=\"lwptoc_item_number\">6<\/span>\u00a0<span class=\"lwptoc_item_label\">Our Guiding Principles<\/span><\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2><span id=\"To_Deny_a_Specific_IP_Address\">To Deny a Specific\u00a0IP Address<\/span><\/h2>\n<p>The below code will only deny one IP address from accessing the website.<\/p>\n<pre>\u200b\u200bDeny from 192.0.0.1<\/pre>\n<p>Just change the IP address to the IP address that you want to deny and paste it in the .htaccess file.<\/p>\n<h2><span id=\"To_Deny_a_Specific_Domain\">To Deny a Specific Domain<\/span><\/h2>\n<p>We can deny a specific domain from accessing our domains by adding the below line of code to your .htaccess file.<\/p>\n<pre>Deny from 192.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<h2><span id=\"To_Deny_Multiple_IPs_in_a_Single_Line_of_Code\">To Deny Multiple IP\u2019s in a Single Line of Code<\/span><\/h2>\n<p>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<h2><span id=\"To_Allow_Only_a_Single_IP\">To Allow Only a Single IP<\/span><\/h2>\n<p>The below set of .htaccess rule will deny access to the 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<h2><span id=\"To_Deny_a_Single_IPv6_Address\">To Deny a Single IPv6 Address<\/span><\/h2>\n<p>To block a IPV6 address via .htaccess, follow the syntax below:<\/p>\n<pre>Deny from 2001:cdba:0000:0000:0000:0000:3257:9652<\/pre>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we are going to see how to deny an IP address or how to allow only a particular IP address to access your web site. This is often very helpful to protect your web site from hackers or to block unwanted visitors. You need to create an .htaccess file in your public_html [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2582","post","type-post","status-publish","format-standard","hentry","category-reseller-hosting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v15.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Block IP Addresses with .htaccess - OWS KB<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ownwebservers.com\/kb\/2582\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Block IP Addresses with .htaccess - OWS KB\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we are going to see how to deny an IP address or how to allow only a particular IP address to access your web site. This is often very helpful to protect your web site from hackers or to block unwanted visitors. You need to create an .htaccess file in your public_html [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ownwebservers.com\/kb\/2582\/\" \/>\n<meta property=\"og:site_name\" content=\"OWS KB\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-04T05:29:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-04T05:33:23+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\">\n\t<meta name=\"twitter:data1\" content=\"admin\">\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data2\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"OWS KB\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/ownwebservers.com\/kb\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/2582\/#webpage\",\"url\":\"https:\/\/ownwebservers.com\/kb\/2582\/\",\"name\":\"How to Block IP Addresses with .htaccess - OWS KB\",\"isPartOf\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\"},\"datePublished\":\"2021-10-04T05:29:02+00:00\",\"dateModified\":\"2021-10-04T05:33:23+00:00\",\"author\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\"},\"breadcrumb\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/2582\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ownwebservers.com\/kb\/2582\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/2582\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/2582\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/2582\/\",\"name\":\"How to Block IP Addresses with .htaccess\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ba5db5841d48bd7517bb2583e13983e6d2fa56a4099a0b3c61ad2daefc321303?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/ownwebservers.com\/kb\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/2582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/comments?post=2582"}],"version-history":[{"count":2,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/2582\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/2582\/revisions\/2584"}],"wp:attachment":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/media?parent=2582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/categories?post=2582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/tags?post=2582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}