Forum Discussion
URL rewrite through iRule
- Nov 11, 2013
Hi Sunnyman,
This will work;
if { [IP::addr [IP::client_addr] equals 1.1.1.1] || [IP::addr [IP::client_addr] equals 1.1.1.2} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_100 } elseif { [IP::addr [IP::client_addr] equals 1.1.1.11] || [IP::addr [IP::client_addr] equals 1.1.1.12} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_200 }
But that's not a very scalable way of doing it if your list is going to grow. If it's going to grow then use an address datagroup, with values snatpool names, which you can use like this
snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools]
or more correctly;
set snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools] if {$snatpool ne "") { snatpool $snatpool }
Hi Sunnyman,
No you are not quite right - while it's perfectly valid to include an IP/port number within a Host: header, this does not tell the F5 where to send the traffic. You need to use the node or pool command to inform TMOS where to send traffic. This is the most obvious way using node;-
if {[string tolower [HTTP::host]] starts_with "abc.com" && [string tolower[HTTP::path]] eq "/ukm"} {
HTTP::header replace Host "partner.abc.com"
node 1.1.1.1 8080
HTTP::uri "/xyz"
}
Now having said that, it's not the way I would do it. You should include member 1.1.1.1:8080 in a pool, ie pl_sunnyman_8080 with an appropriate healthcheck and then instruct the F5 to send to the pool;-
if {[string tolower [HTTP::host]] starts_with "abc.com" && [string tolower[HTTP::path]] eq "/ukm"} {
HTTP::header replace Host "partner.abc.com"
pool pl_sunnyman_8080
HTTP::uri "/xyz"
}
The reason this is better is that by having your server in a pool with an appropriate healthcheck, you can have multiple servers in the pool for backup, and also TMOS will already know the state of the servers in the pool, so will only choose one that is UP.
Recent Discussions
Related Content
* 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