Forum Discussion

Mohanad's avatar
Mohanad
Icon for Cirrostratus rankCirrostratus
Jul 30, 2019
Solved

iRule for Conditional SNAT

i need to configre iRule for Conditional SNAT while (10.10.10.1 & 10.10.10.2) connecting to the VS SNAT will be 10.214.214.148 and the rest of clients the SNAT will be 10.214.214.147 current setup...
  • cjunior's avatar
    Jul 30, 2019

    Hi,

    Do you really need the SNAT pool, or you just need to definean IP address to SNAT on iRule?

    e.g.

    # Classic syntax
    when CLIENT_ACCEPTED {
        if { [IP::client_addr] eq "10.10.10.1" || [IP::client_addr] eq "10.10.10.2" } {
            snat 10.214.214.148
        } else {
            snat 10.214.214.147
        }
    }
     
    # Short way
    when CLIENT_ACCEPTED {
        if { "10.10.10.1, 10.10.10.2" contains [IP::client_addr] } {
            snat 10.214.214.148
        } else {
            snat 10.214.214.147
        }
    }
     
    # Expansive way, increase list when needed
    when CLIENT_ACCEPTED {
        switch [IP::client_addr] {
            10.10.10.1 -
            10.10.10.2 {
                snat 10.214.214.148
            }
            default {
                snat 10.214.214.147
            }
        }
    }

    You must change line from "snat <IP ADDR>" to "snatpool <POOLNAME>" if you need to use a SNAT pool.

    I hope it helps.