# IRULE syntax

**URL:** <https://community.f5.com/t/irule-syntax/3925>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [June 17, 2005, 5:47pm UTC](https://community.f5.com/t/irule-syntax/3925 "2005-06-17T17:47:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Omaljev](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Michael\_Omaljev](https://community.f5.com/u/Michael_Omaljev)\
**Post date:** [June 17, 2005, 5:47pm UTC](https://community.f5.com/t/irule-syntax/3925/1 "2005-06-17T17:47:35Z")

</div>

looking to modify an Irule. Basically we have a solution with an I rule that deals with a source ip that talks to a vip and the destination servers that are loadbalanced exist in the same subnet as the source. I am trying to modify this script if there is more then 1 source server (server A proxy). Not sure what the syntax would be.

so If I have an additional source server 192.168.1.23 how would I add it to this Irule? what is the syntax? What is the syntax if I want to use the entire 192.168.1.X subnet ?

thanks

MO

when CLIENT\_ACCEPTED {

if {[IP::addr “[IP::client\_addr]” equals “192.168.1.22”]} {

snat automap

}

}

---

<div class="post-metadata">

**Author:** ![Joe\_Pruitt](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/joe_pruitt/32/8438_2.png) [@Joe\_Pruitt](https://community.f5.com/u/Joe_Pruitt)\
**Post date:** [June 17, 2005, 6:27pm UTC](https://community.f5.com/t/irule-syntax/3925/2 "2005-06-17T18:27:00Z")

</div>

For more than one address, you are going to have to use multiple if/elseif’s or the **matchclass** command with an address class (data group). You can then create a class list with the addresses you want to match on. Search the forums for **matchclass** and you should find plenty of examples.

For an entire subnet you can use the optional mask parameter to the IP::addr command to match to an entire subnet.

IP::addr [mask]

Give this a shot

```tcl
when CLIENT_ACCEPTED { 
   log "client addr: [IP::client_addr]" 
   log "mask addr: [IP::addr [IP::client_addr] mask "255.255.255.0"]" 
   
   if { [IP::addr [IP::client_addr] mask "255.255.255.0"] equals "192.168.1.0" } { 
     log local0. "match!" 
   } else { 
     log local0. "Not a match!"   
   } 
 }

```

-Joe

---

<div class="post-metadata">

**Author:** ![unRuleY\_95363](https://avatars.discourse-cdn.com/v4/letter/u/58f4c7/32.png) [@unRuleY\_95363](https://community.f5.com/u/unRuleY_95363)\
**Post date:** [June 17, 2005, 6:58pm UTC](https://community.f5.com/t/irule-syntax/3925/3 "2005-06-17T18:58:20Z")

</div>

Um, that’s not quite right…

Try this:

```tcl
when CLIENT_ACCEPTED {  
    if {[IP::addr "[IP::client_addr]/24" equals "192.168.1.0/24"]} {  
       snat automap  
    }  
 }

```
