Score:1

ModSecurity: Block all IPs except for a list of defined IPs

us flag

I have an apache server with ModSecurity. I need to block all IPs except for a few ones.

The list of IPs is like this:

194.83.128.0/21
191.143.32.0/19
145.126.72.0/21
101.28.248.0/22
40.64.64.0/22
180.11.124.0/22
190.230.64.0/18
109.154.0.0/16
42.60.0.0/16
43.223.0.0/16
2a03:e980::/29

Right now I applied this rule:

SecRule REMOTE_ADDR "@ipMatch 194.83.128.0/21,191.145.32.0/19,145.126.72.0/21,101.28.248.0/22,40.64.64.0/22,180.11.124.0/22,190.230.64.0/18,109.154.0.0/16,42.60.0.0/16,43.223.0.0/16,2a03:e980::/29" "id:162"

But the rule above seems to be doing a whitelist rather than blocking all IPs except for the ones defined in the rule.

I'm not sure how to achieve blocking all IPs except the ones on my list. Most of the documentation I have found is related to blocking or adding IPs to a deny list, when some action happens, like constantly accessing 404 pages.

Is there a way to block by default all the IPs, except the ones defined in my list?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.