Search code examples
apacheip-blocking

Apache 2.4 - need to block a range but allow one IP address from the same range


I need to block a range of IP addresses in the /etc/apache2/ipblacklist.conf

The block is on 171.0.0.0/8 I do need to allow one IP address from the same range - 171.3.2.25/32

Trying to set it as below doesn't work - no matter the order. Each separate statement works fine

Require not ip 171.0.0.0/8
Require ip 171.3.2.25/32

Thanks ahead


Solution

  • Ok, after consulting couple of friends, the answer to do so is to break the allow/deny into separate blocks

    <RequireAny>
    <RequireAll>
        Require ip 171.3.2.25/32
    </RequireAll>
    <RequireAll>
        Require all granted
        Require not ip 171.0.0.0/8
    </RequireAll>
    </RequireAny>