Forum Discussion

Matthew_M_23576's avatar
Matthew_M_23576
Icon for Nimbostratus rankNimbostratus
Oct 25, 2018

Odd/Even IP address iRule

I have a VIP with 2 backend nodes, and I am trying to create an iRule that will forward traffic based on whether the last octet of the source IP address is an odd or even number (e.g. for ip_addr 10.10.10.x, if x is odd forward to node 1 or if even forward to node 2). Would that be possible via an iRule? I am still learning tcl, so any help would be appreciated.

 

1 Reply

  • Try this iRule - let me know how you get on

    when CLIENT_ACCEPTED {
        set lastOctet [getfield [IP::client_addr] "." 4]
        if {($lastOctet % 2) == 0} {
            log local0. "$lastOctet is even"
            node 10.10.10.2
        } else {
            log local0. "$lastOctet is odd"
            node 10.10.10.1
        }
    }