# Assistance with iRule using port ranges

**URL:** <https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718>\
**Category:** Technical Forums\
**Tags:** application-delivery\
**Created:** [December 21, 2023, 8:22pm UTC](https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718 "2023-12-21T20:22:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JP-814](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jp-814/32/18153_2.png) [@JP-814](https://community.f5.com/u/JP-814)\
**Post date:** [December 21, 2023, 8:22pm UTC](https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718/1 "2023-12-21T20:22:37Z")

</div>

Hello all!

I currently have a VIP that is listening over various ports, 4400-4699. The owner of the app is having the client statically set a port when connecting to the VIP and would like to load balance to a particular member based on the port entered.

I built out an iRule for this and I am getting an error stating undefined procedure:tcp::local\_port. Can I get some advice on what I am doing wrong here? Thanks in advance!

when CLIENT\_ACCEPTED {  
if { ( [TCP::local\_port] \> 4399 ) or ( [TCP::local\_port] \< 4499 ) } {  
pool hjapp.portlist.pool member 10.11.20.52:0  
} elseif { ( [tcp::local\_port] \> 4500 ) or ( [tcp::local\_port] \< 4700 ) } {  
pool hjapp.portlist.pool member 10.11.20.58:0  
}  
}

---

<div class="post-metadata">

**Author:** ![zamroni777](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/zamroni777/32/1473_2.png) [@zamroni777](https://community.f5.com/u/zamroni777)\
**Post date:** [December 22, 2023, 2:49am UTC](https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718/2 "2023-12-22T02:49:04Z")

</div>

it seems because you define the tcp port as …:0 instead of&nbsp;

> **[pool](https://clouddocs.f5.com/api/irules/pool.html)**

it will be tidier if you put .52 and and .58 in separate pools so you dont need to define pool member in the irule.  
you can use pool’s priority group activation in each pool if you want both to be members.

btw, it’s better to use gui based traffic policy to avoid scripting typo

 ![zamroni777_0-1703213054147.png](https://d20hrnpixdzcsd.cloudfront.net/original/2X/a/a2648a1d66396778f46a79849cb33250fd917856.png)

---

<div class="post-metadata">

**Author:** ![JP-814](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jp-814/32/18153_2.png) [@JP-814](https://community.f5.com/u/JP-814)\
**Post date:** [December 22, 2023, 12:19pm UTC](https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718/3 "2023-12-22T12:19:55Z")

</div>

Oh wow, I didn’t consider policy for this effort. That makes much more sense, thank you for that info! 😄

---

<div class="post-metadata">

**Author:** ![Michael\_Saleem](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/michael_saleem/32/7239_2.png) [@Michael\_Saleem](https://community.f5.com/u/Michael_Saleem)\
**Post date:** [December 24, 2023, 1:30pm UTC](https://community.f5.com/t/assistance-with-irule-using-port-ranges/73718/4 "2023-12-24T13:30:10Z")

</div>

BTW, your iRule was 99% correct; it just had a slight typo:

You just needed to amend the TCP::local\_port command as it is case sensitive i.e:

**FROM**  
tcp::local\_port

**TO**  
TCP::local\_port
