# iRule & SNAT

**URL:** <https://community.f5.com/t/irule-snat/2886>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [December 1, 2008, 1:37pm UTC](https://community.f5.com/t/irule-snat/2886 "2008-12-01T13:37:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_16019](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@chris\_16019](https://community.f5.com/u/chris_16019)\
**Post date:** [December 1, 2008, 1:37pm UTC](https://community.f5.com/t/irule-snat/2886/1 "2008-12-01T13:37:20Z")

</div>

Hi - I was hoping someone may be able to offer some assistance or point me at a URL that will help with some configuration work that is required.

Background - I have a backend server that has multiple IP addresses for SSL certificate purposes. I have added a new virtual server address that points to the backend server, however I am unable to add a SNAT for outgoing traffic to be hidden behind this virtual server address as the real address of the server already exists in the address pool of a different virtual server SNAT.

A pool is no good as I need a different SNAT for different website communications from the same server. So I’m thinking I need to use an iRule to change the SNAT based on a unique characteristic within the packet, something like the URL. However after a few hours searching the only previous examples I can find all relate to IP addresses. Is it a case of amending something like the below to have URL instead of IP address within the text, and if so is anyone able to offer some syntax assistance.

when CLIENT\_ACCEPTED { if { [IP::addr [IP::local\_addr] equals “A.A.A.A”] } {

use snat Z.Z.Z.Z

} elsif { [IP::addr [IP::local\_addr] equals “B.B.B.B”] } {

use snat Y.Y.Y.Y

} else { use snat X.X.X.X

}

Many thanks.

Chris

---

<div class="post-metadata">

**Author:** ![naladar\_65658](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@naladar\_65658](https://community.f5.com/u/naladar_65658)\
**Post date:** [December 2, 2008, 2:21pm UTC](https://community.f5.com/t/irule-snat/2886/2 "2008-12-02T14:21:49Z")

</div>

I am far from being an expert on such things… that being said. You might try just turning on some logging and then throw some traffic at it. That way you can see if it is even being executed.

when CLIENT\_ACCEPTED {

log local0. “[IP::local\_addr]:[TCP::local\_port]: Client Accepted”

if { [IP::addr [IP::local\_addr] equals “A.A.A.A”] } {

log local0. “[IP::local\_addr]:[TCP::local\_port]: Using the A.A.A.A SNAT”

use snat Z.Z.Z.Z

} elsif { [IP::addr [IP::local\_addr] equals “B.B.B.B”] } {

log local0. “[IP::local\_addr]:[TCP::local\_port]: Using the B.B.B.B SNAT”

use snat Y.Y.Y.Y

} else {

log local0. “[IP::local\_addr]:[TCP::local\_port]: Using the Default X.X.X.X SNAT”

use snat X.X.X.X

}

Also, I do not believe it is possible to use the f5 to modify/change or even read traffic going over SSL when the f5 is not holding the SSL keys. So if your offloading all the SSL stuff to a different device I believe you are limited in what you can do with that traffic.

---

<div class="post-metadata">

**Author:** ![chris\_16019](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@chris\_16019](https://community.f5.com/u/chris_16019)\
**Post date:** [December 4, 2008, 12:56pm UTC](https://community.f5.com/t/irule-snat/2886/3 "2008-12-04T12:56:04Z")

</div>

The SSL is offloaded to the F5, and it’s client SSL so is unencrypted on the server side.

When I try :

when CLIENT\_ACCEPTED {

I am then unable to use

if { [HTTP::host] equals “[www.test.com](http://www.test.com)” } {

use snat 10.92.116.77

Any ideas on how this should be phrased so that I can direct requests containing specific URLs to a specific SNAT?

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![dennypayne](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/dennypayne/32/1364_2.png) [@dennypayne](https://community.f5.com/u/dennypayne)\
**Post date:** [December 4, 2008, 3:21pm UTC](https://community.f5.com/t/irule-snat/2886/4 "2008-12-04T15:21:25Z")

</div>

[HTTP::host] is only valid within an HTTP\_REQUEST event. If your virtual server does not have an http profile attached you will not be able to use any HTTP iRule events. So you first need to replace CLIENT\_ACCEPTED with HTTP\_REQUEST and then make sure your vip has an http profile. Not sure if ‘use snat’ is correct either, I think it’s just ‘snat x.x.x.x’.

EDIT: if you’re offloading SSL most likely you do have an http profile on the vip already…

Denny
