# Selective SNAT setup

**URL:** <https://community.f5.com/t/selective-snat-setup/59606>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [August 23, 2007, 3:27pm UTC](https://community.f5.com/t/selective-snat-setup/59606 "2007-08-23T15:27:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Nail](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@Kevin\_Nail](https://community.f5.com/u/Kevin_Nail)\
**Post date:** [August 23, 2007, 3:27pm UTC](https://community.f5.com/t/selective-snat-setup/59606/1 "2007-08-23T15:27:48Z")

</div>

Thanks for reading, any help would be appreciated. Here is my setup

US based LTM in DMZ

pool AMK\_US

member 192.168.x.x (behind the local LTM)

member 192.55.x.x (on a server in Singapore)

Virtual server

192.55.x.x

We have a vlan called internal\_5 setup with an ip of 192.168.x.x on the LTM.

Here is what we want to do:

1. When a request comes in from a business partner in the US, if the US pool member is up, traffic is sent to it.

2. If that pool member is down then the traffic will be routed to Singapore.

We have added a static route to the LTM to use the 192.168.x.x IP as it’s route to get out. Problem is that we need to have that and only that traffic SNAT’d so that it returns to the LTM. There is also another default SNAT in place for other internal nodes on the LTM.

How can we create an iRule that will SNAT traffic that comes in the 192.55.x.x VIP and leaves for 192.55.a.x via the 192.168.x.x IP without affecting anything else?

Also the question comes to mind, should the iRule be applied to the 192.55.x.x VIP only and on what interface (external - to outside or internal - to behind LTM)

Thanks,

Kevin

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [August 23, 2007, 4:32pm UTC](https://community.f5.com/t/selective-snat-setup/59606/2 "2007-08-23T16:32:32Z")

</div>

Hi,

You can write a rule and apply it only to the 192.55.21.x VIP that looks for requests being load balanced to one remote node and applies SNAT automap. Here is an example:

```tcl
when LB_SELECTED {
   if {[IP::addr [LB::server addr] equals 192.55.17.x]}{
      snat automap
   }
}

```

[LB::server addr] returns the IP address for the node which has been selected to receive the request.

You can check the ‘snat’ command for more examples: ([Click here](http://devcentral.f5.com/Wiki/default.aspx/iRules.snat))

Aaron

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [August 23, 2007, 6:01pm UTC](https://community.f5.com/t/selective-snat-setup/59606/3 "2007-08-23T18:01:57Z")

</div>

I think the concern was that only those requests that arrive on the internal\_5 vlan would be snatted, but I couldn’t quite tell. I was trying to get LINK::vlan\_id to return something, but haven’t been able to on my lab pair (9.4.2 beta) I was thinking of setting a variable in the CLIENT\_ACCEPTED event with the link vlan ID so it could be ANDed with the remote server IP before snatting, but I’ve never used that before and wanted to test prior to posting.

---

<div class="post-metadata">

**Author:** ![Kevin\_Nail](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@Kevin\_Nail](https://community.f5.com/u/Kevin_Nail)\
**Post date:** [August 23, 2007, 6:30pm UTC](https://community.f5.com/t/selective-snat-setup/59606/4 "2007-08-23T18:30:17Z")

</div>

Thanks,

I will give that a try…
