Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Web Servers»Apache»How To Block IP using .htaccess File in Apache

    How To Block IP using .htaccess File in Apache

    RahulBy RahulMarch 10, 20191 Min ReadUpdated:May 28, 2019

    This tutorial describes How To Block IP using .htaccess in Apache. The Apache users can easily block website access from specific IP addresses or any IP ranges using the .htaccess file. Make sure your Apache server is enabled to use a .htaccess file.

    Block IP using .htaccess

    Now, create a file named .htaccess in your website document root directory and add these example lines:

    1
    2
    3
    4
    5
    6
    7
    8
    <Files *>
       <RequireAll>
    Require all granted                #First allow all
    Require not ip 192.168.1.10        #Block single IP
    Require not ip 192.168.1.0/24      #Block IP range
    Require not ip 192.168.1.11 10.10.0.1/32    #Block mutile IPs and range
      </RequireAll>
    </Files>

    You are required to change the IP address to be blocked in the above configuration. Here you can block a single IP or IP ranges. You can also write one or more IPs in a single line with space separated.

    The user will see the following error message when tried to access from a blocked IP address.

    Block IP using .htaccess

    For more details visit the following link:

    https://httpd.apache.org/docs/2.4/howto/access.html

    Apache Block ip
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Generate a Random String using PHP
    Next Article How to Check Python Version in Linux Command Line

    Related Posts

    How To Install Apache Solr 9.0 on Fedora 36/35

    Updated:May 26, 20223 Mins Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    Common Apache Commands on Ubuntu & Debian

    4 Mins Read

    1 Comment

    1. Amrit on June 11, 2021 9:56 am

      Hey Rahul,

      I just blocked an ip which sends me 1423 requests every 15 minutes. The ip is showing as Googlebot. But it affects my loading speed. Sometimes my site is unable to access just for the only ip.

      So, I tried to block that ip. But after blocking the ip I got the forbidden message on my site. Can you please tell me what can I do?

      Best Regards,
      Amrit

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.