{"id":2780,"date":"2014-07-31T02:08:09","date_gmt":"2014-07-31T02:08:09","guid":{"rendered":"http:\/\/www.deuzebranaweb.com.br\/?p=2780"},"modified":"2014-07-31T02:08:09","modified_gmt":"2014-07-31T02:08:09","slug":"como-bloquear-ou-liberar-um-ip-de-acessar-um-site-pelo-htaccess","status":"publish","type":"post","link":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/2014\/07\/31\/como-bloquear-ou-liberar-um-ip-de-acessar-um-site-pelo-htaccess\/","title":{"rendered":"Como bloquear ou liberar um IP de acessar um site pelo .htaccess?"},"content":{"rendered":"<div class=\"entry-content\" style=\"color: #373737;\">\n<p style=\"font-weight: inherit; font-style: inherit;\">Algumas vezes durante testes locais ou at\u00e9 mesmo em produ\u00e7\u00e3o surge a necessidade de limitar o acesso ao servidor HTTP de alguma forma.<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\">Se o servidor der suporte ao\u00a0<strong style=\"font-style: inherit;\">.htaccess<\/strong>\u00a0(<strong style=\"font-style: inherit;\">apache<\/strong>\u00a0por exemplo) essa acaba sendo uma forma interessante de se chegar ao objetivo.<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\"><strong style=\"font-style: inherit;\">Para bloquear um IP espec\u00edfico<\/strong><\/p>\n<div class=\"wp_syntax\" style=\"font-weight: inherit; font-style: inherit; color: #110000;\">\n<table style=\"font-weight: inherit; font-style: inherit;\">\n<tbody style=\"font-weight: inherit; font-style: inherit;\">\n<tr style=\"font-weight: inherit; font-style: inherit;\">\n<td class=\"code\" style=\"font-style: inherit;\">\n<pre class=\"xml\">Order Allow,Deny\nDeny from 192.168.1.10\nAllow from all<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-weight: inherit; font-style: inherit;\">Note que voc\u00ea precisa negar o acesso ao IP indesejado e permitir os demais por causa do\u00a0<i>Order<\/i>\u00a0colocado anteriormente.<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\"><strong style=\"font-style: inherit;\">Para dar acesso apenas a um IP espec\u00edfico<\/strong><\/p>\n<div class=\"wp_syntax\" style=\"font-weight: inherit; font-style: inherit; color: #110000;\">\n<table style=\"font-weight: inherit; font-style: inherit;\">\n<tbody style=\"font-weight: inherit; font-style: inherit;\">\n<tr style=\"font-weight: inherit; font-style: inherit;\">\n<td class=\"code\" style=\"font-style: inherit;\">\n<pre class=\"xml\">Order Deny,Allow\nDeny from all\nAllow from 192.168.1.10<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-weight: inherit; font-style: inherit;\">Perceba agora a sutil diferen\u00e7a nos par\u00e2metros do\u00a0<em style=\"font-weight: inherit;\">Order<\/em>. Isso far\u00e1 com que primeiro todos os ips sejam negados e depois aquele espec\u00edfico liberado.<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\">H\u00e1 outras possibilidades ainda, como por exemplo permitir ranges de IP. Substituindo o IP 192.168.1.10 por 192.168.1 far\u00e1 com que todos os IPs iniciados daquela forma sejam considerados.<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\">http:\/\/www.como-faz.net\/apache\/como-bloquear-ou-liberar-um-ip-de-acessar-um-site-pelo-htaccess\/<\/p>\n<p style=\"font-weight: inherit; font-style: inherit;\">http:\/\/blog.thiagobelem.net\/bloqueando-ips-no-apache-com-htaccess\/<\/p>\n<\/div>\n<footer class=\"entry-meta\" style=\"color: #666666;\">This entry was posted in\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" title=\"View all posts in Apache\" href=\"http:\/\/www.como-faz.net\/categorias\/apache\/\" rel=\"category tag\">Apache<\/a>\u00a0and tagged\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/tags\/bloquear-ip\/\" rel=\"tag\">bloquear ip<\/a>,\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/tags\/bloquear-ip-htaccess\/\" rel=\"tag\">bloquear ip htaccess<\/a>,\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/tags\/bloquer-ip-apache\/\" rel=\"tag\">bloquer ip apache<\/a>,\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/tags\/permitir-ip\/\" rel=\"tag\">permitir ip<\/a>,\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/tags\/permitir-ip-apache\/\" rel=\"tag\">permitir ip apache<\/a>\u00a0by\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" href=\"http:\/\/www.como-faz.net\/author\/daniel\/\">Daniel<\/a>. Bookmark the\u00a0<a style=\"font-weight: bold; font-style: inherit; color: #1982d1;\" title=\"Permalink to Como bloquear ou liberar um IP de acessar um site pelo .htaccess?\" href=\"http:\/\/www.como-faz.net\/apache\/como-bloquear-ou-liberar-um-ip-de-acessar-um-site-pelo-htaccess\/\" rel=\"bookmark\">permalink<\/a>.<\/footer>\n<footer class=\"entry-meta\" style=\"color: #666666;\"><\/footer>\n<footer class=\"entry-meta\" style=\"color: #666666;\"><\/footer>\n<footer class=\"entry-meta\" style=\"color: #666666;\"><\/footer>\n<footer class=\"entry-meta\" style=\"color: #666666;\">\n<header class=\"entry-header\" style=\"color: #444444;\">\n<h1 class=\"entry-title\">Bloqueando IPs no Apache com .htaccess<\/h1>\n<\/header>\n<div class=\"entry-content\" style=\"color: #444444;\">\n<p>Hoje vou falar sobre um assunto muito importante relacionado a seguran\u00e7a: como bloquear IPs no seu servidor [Apache] utilizando o seu arquivo\u00a0<strong>.htaccess<\/strong>.<\/p>\n<p>A meses que pessoas t\u00eam tentado invadir o meu blog e, como eu estava sempre conseguindo \u201cpegar\u201d os invasores, me diverti por um tempo com essas tentativas\u2026 Mas resolvi tomar uma provid\u00eancia e bloqueei os IPs que continuam tentando invadir o blog.<\/p>\n<p>Aproveitei o ritmo e resolvi ensinar \u00e0 voc\u00eas como fazer isso\u2026 J\u00e1 falei antes sobre\u00a0<a style=\"color: #21759b;\" title=\"Bloqueando visitantes pelo IP com MySQL e PHP\" href=\"http:\/\/blog.thiagobelem.net\/mysql\/bloqueando-visitantes-pelo-ip-com-mysql-e-php\/\">como bloquear visitantes pelo IP utilizando PHP e MySQL<\/a>\u00a0s\u00f3 que o bloqueio com\u00a0<strong>.htaccess<\/strong>\u00a0\u00e9 muito mais eficiente pois ele bloqueia logo no come\u00e7o da requisi\u00e7\u00e3o e exibe uma p\u00e1gina de erro das mais feias.<\/p>\n<h3>Bloqueando IPs<\/h3>\n<p>Edite (ou crie) o arquivo\u00a0<strong>.htaccess<\/strong>\u00a0na ra\u00edz do seu servidor e coloque o seguinte c\u00f3digo:<\/p>\n<div id=\"highlighter_518398\" class=\"syntaxhighlighter  \">\n<div class=\"lines\">\n<div class=\"line alt1\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>1<\/code><\/td>\n<td class=\"content\"><code class=\"comments\" style=\"color: #008200 !important;\"># Bloqueia uma lista de IPs<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"line alt2\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>2<\/code><\/td>\n<td class=\"content\"><code class=\"plain\">order allow, deny<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"line alt1\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>3<\/code><\/td>\n<td class=\"content\"><code class=\"plain\">deny from 210.140.98.160<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"line alt2\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>4<\/code><\/td>\n<td class=\"content\"><code class=\"plain\">deny from 69.197.132.70<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"line alt1\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>5<\/code><\/td>\n<td class=\"content\"><code class=\"plain\">deny from 74.14.13.236<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"line alt2\">\n<table style=\"color: #757575;\">\n<tbody>\n<tr>\n<td class=\"number\" style=\"color: #afafaf !important;\"><code>6<\/code><\/td>\n<td class=\"content\"><code class=\"plain\">allow from all<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>Perceba a lista de IPs que temos, para cada novo IP que voc\u00ea deseja bloquear \u00e9 s\u00f3 colocar mais uma linha com \u201cdeny from\u00a0<strong>{IP}<\/strong>\u201d e esse IP n\u00e3o conseguir\u00e1 acessar mais nada no seu site!<\/p>\n<p>&nbsp;<\/p>\n<p>http:\/\/blog.thiagobelem.net\/bloqueando-ips-no-apache-com-htaccess\/<\/p>\n<\/div>\n<\/footer>\n","protected":false},"excerpt":{"rendered":"<p>Algumas vezes durante testes locais ou at\u00e9 mesmo em produ\u00e7\u00e3o surge a necessidade de limitar o acesso ao servidor HTTP de alguma forma. Se o servidor der suporte ao\u00a0.htaccess\u00a0(apache\u00a0por exemplo) essa acaba sendo uma forma interessante de se chegar ao objetivo. Para bloquear um IP&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_angie_page":false,"page_builder":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-2780","post","type-post","status-publish","format-standard","hentry","category-apache2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/2780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=2780"}],"version-history":[{"count":0,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/2780\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=2780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=2780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=2780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}