Forum Discussion
Destiny3986_116
Nimbostratus
Sep 02, 2017[Help] How to write iRule to select default gateway based source IP address?
Hi, all.
I have used BIG-IP LTM v12 and my information:
02 ISPs: 178.102.1.104 & 122.255.27.144 => 02 default gateway. 02 SMTP Servers: 192.168.10.101 & 192.168.10.102. BIG-IP is default...
Stanislas_Piro2
Cumulonimbus
Sep 02, 2017Hi,
you can use an irule like this one (rule edited after Kai comments about IP::addr performances):
when RULE_INIT {
array set static::SnatPolicy {
"10.1.1.1" {"Pool_ISP1" "178.102.1.105" ""}
"10.1.1.2" {"Pool_ISP1" "178.102.1.104" ""}
"default" {"default_gateway_pool" "178.102.1.104" "122.255.27.144"}
}
}
when CLIENT_ACCEPTED {
Check if destination address is local
if {[IP::addr [IP::local_addr] equals 192.168.0.0/16] || [IP::addr [IP::local_addr] equals 10.0.0.0/8] || [IP::addr [IP::local_addr] equals 172.16.0.0/12]} {
pool internal_router
} else {
if { [info exists static::SnatPolicy([IP::client_addr])]}{
set clientip [IP::client_addr]
} else {
set clientip "default"
}
pool [lindex $static::SnatPolicy($clientip) 0]
}
}
when LB_SELECTED {
if { [IP::addr [LB::server addr]/28 equals 178.102.1.96]} {
set link 1
} else {
set link 2
}
snat [lindex $static::SnatPolicy($clientip) $link]
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects