iRule Example

1. PoolRedirectHTTP iRule
-Prepare 2 pools PoolWWW and PoolWWW2
PoolWWW
Health Monitor http
Members: WWW1 10.0.20.51 80
WWW2 10.0.20.52 80
PoolWWW2
Health Monitor http
Members: WWW3 10.0.20.53 80
WWW4 10.0.20.54 80

-Prepare 1 Virtual Server VsWWW
VsWWW
Destination Address: 10.0.15.50
Service Port: 80 HTTP
Protocol: TCP
Protocol Profile (Client): tcp
Protocol Profile (Server): (Use Client Profile)
HTTP Profile: None
VLAN and Tunnel Traffic: All VLANs and Tunnels
Source Address Translation: Auto Map
click Resources
Default Pool: PoolWWW

Download and install F5 iRule Editor from
https://devcentral.f5.com/d/irule-editor
Launch iRule Editor
Hostname: F5ipaddress 443
Endpoint: /iControl/iControlPortal.cgi
Username: admin
Password:
click OK
click File/New
Name: PoolRedirectHTTP

when CLIENT_ACCEPTED {
if { [IP::addr [IP::client_addr] equals “10.0.10.110”] } {
pool PoolWWW }
else {
pool PoolWWW2 }
}

-Assign PoolRedirectHTTP iRule into VsWWW Virtual Server
click Virtual Servers VsWWW
click Resources
click iRules/Manage
Enabled PoolRedirectHTTP
click Finished

-Test
Now when you access http://10.0.15.50 from your browser and your ip is 10.0.10.110, you will get pool PoolWWW, otherwise PoolWWW2

2. Redirect2HTTPS iRule
-Prepare 2 pools PoolWWW and PoolWWWS2
PoolWWW
Health Monitor http
Members: WWW1 10.0.20.51 80
WWW2 10.0.20.52 80
PoolWWWS2
Health Monitor https
Members: WWW3 10.0.20.53 443
WWW4 10.0.20.54 443

-Prepare 1 Virtual Server VsWWW
VsWWW
Destination Address: 10.0.15.50
Service Port: 0 *All Ports
Protocol: TCP
Protocol Profile (Client): tcp
Protocol Profile (Server): (Use Client Profile)
HTTP Profile: None
VLAN and Tunnel Traffic: All VLANs and Tunnels
Source Address Translation: Auto Map
click Resources
Default Pool: PoolWWW

run F5 iRule Editor
click File/New
Name: Redirect2HTTPS
when CLIENT_ACCEPTED {
if {[TCP::local_port] == 80} {
pool PoolWWW
}
elseif { [TCP::local_port] == 443 } {
pool PoolWWWS2
}
}

-Assign Redirect2HTTPS iRule into VsWWW
click Virtual Servers VsWWW
click Resources
click iRules/Manage
Enabled Redirect2HTTPS
click Finished

-Tes
Now when you access http://10.0.15.50 from your browser, you will get pool PoolWWW
If using https://10.0.15.50, you will get PoolWWWS2

3. RedirectPoolText iRule
-Prepare 2 pools PoolWWW and PoolWWW2
PoolWWW
Health Monitor http
Members: WWW1 10.0.20.51 80
               WWW2 10.0.20.52 80
PoolWWWS2
Health Monitor http
Members: WWW3 10.0.20.53 80
               WWW4 10.0.20.54 80

-Prepare file.txt in WWW3 web folder
The file content is “This is test file SERVER3”

-Prepare file.txt in WWW4 web folder
The file content is “This is test file SERVER4”

-Prepare 1 Virtual Server VsWWW
VsWWW
Destination Address: 10.0.15.50
Service Port: 0 *All Ports
Protocol: TCP
Protocol Profile (Client): tcp
Protocol Profile (Server): (Use Client Profile)
HTTP Profile: http
VLAN and Tunnel Traffic: All VLANs and Tunnels
Source Address Translation: Auto Map
click Resources
Default Pool: PoolWWW

run F5 iRule Editor
click File/New
Name: RedirectPoolText
when HTTP_REQUEST {
if {[HTTP::uri] ends_with “txt”} {
pool PoolWWW2
}
else { pool PoolWWW }
}

-Assign RedirectPoolText iRule into VsWWW
click Virtual Servers VsWWW
click Resources
click iRules/Manage
Enabled RedirectPoolText
click Finished

-Test
Now when you access http://10.0.15.50/file.txt from your browser, you will get pool PoolWWW2
If using http://10.0.15.50, you will get PoolWWW
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s