Limit IPv4/24 connections

Hello,

I would like to limit the connections to 100 per 255.255.255.0
Is there a chance e.g. to zero the last byte of “$binary_remote_addr”?

Something like:
set $remote_addr_24 “/$remote_addr/.[0-9]*$/.0/”
limit_zone connectiontrack $remote_addr_24 16m;
limit_conn connectiontrack 100;

Thanks a lot
Markus

Posted at Nginx Forum:

On Saturday 14 January 2012 17:27:53 double wrote:

Hello,

I would like to limit the connections to 100 per 255.255.255.0
Is there a chance e.g. to zero the last byte of “$binary_remote_addr”?

Something like:
set $remote_addr_24 “/$remote_addr/.[0-9]*$/.0/”
limit_zone connectiontrack $remote_addr_24 16m;
limit_conn connectiontrack 100;

this captures only first 3 bytes of $binary_remote_addr:

if ($binary_remote_addr ~ “^(\C{3})”) {
set $remote_addr_24 $1;
}

wbr, Valentin V. Bartenev

On Saturday 14 January 2012 18:04:00 Valentin V. Bartenev wrote:

this captures only first 3 bytes of $binary_remote_addr:

if ($binary_remote_addr ~ “^(\C{3})”) {
set $remote_addr_24 $1;
}

or:

map $binary_remote_addr $remote_addr_24 {
default “”;
~^(?P\C{3}) $bytes;
}

wbr, Valentin V. Bartenev