Forum Discussion
Ajit
Altostratus
Oct 19, 2014Add 2 source ip addresses to switch in irule
I need to add two more src ip addresses 1.1.1.1 & 2.2.2.2 along with 66.78.30.7 so that if traffic comes from any of these src ip addresses it should be redirected to the same pool. Can anyone help m...
Hannes_Rapp
Nimbostratus
Oct 19, 2014If you want to keep the iRule as it is, just add the new IP addresses as below:
when HTTP_REQUEST {
set srcip [IP::client_addr]
set host [string tolower [HTTP::host]]
switch $srcip {
"1.1.1.1" -
"2.2.2.2" -
"66.78.30.7" {
switch $host {
"xyz.abc.net" {
pool xyz.abc.net-ggi-https
}
}
}
}
}
However, your current solution needs some improvements. I'd recommend something as below that does the exact same job:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] == "xyz.abc.net" } {
switch [IP::client_addr] {
"1.1.1.1" -
"2.2.2.2" -
"66.78.30.7" {
pool xyz.abc.net-ggi-https
}
}
}
}
Recommendations: 1 - Don't define variables, unless you really have to (waste of memory) 2 - Use of the IF-statement is preferred in case of a single condition. SWITCH-statement is better when you have 3 or more conditions.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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