# Limit IPv4/24 connections

**URL:** <https://www.ruby-forum.com/t/limit-ipv4-24-connections/215747>\
**Category:** NGINX\
**Created:** [January 14, 2012, 2:43pm UTC](https://www.ruby-forum.com/t/limit-ipv4-24-connections/215747 "2012-01-14T14:43:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 14, 2012, 2:43pm UTC](https://www.ruby-forum.com/t/limit-ipv4-24-connections/215747/1 "2012-01-14T14:43:11Z")

</div>

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:

> **[Limit IPv4/24 connections](https://forum.nginx.org/read.php?2,221225,221225#msg-221225)**
>
> 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 connectiont

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 14, 2012, 3:04pm UTC](https://www.ruby-forum.com/t/limit-ipv4-24-connections/215747/2 "2012-01-14T15:04:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 14, 2012, 3:12pm UTC](https://www.ruby-forum.com/t/limit-ipv4-24-connections/215747/3 "2012-01-14T15:12:16Z")

</div>

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
