# irule for snat pool and data group and pool member

**URL:** <https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758>\
**Category:** Technical Forums\
**Tags:** irules, data-groups, application-delivery, ltm\
**Created:** [November 20, 2015, 8:48am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758 "2015-11-20T08:48:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allanwynn\_16283](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Allanwynn\_16283](https://community.f5.com/u/Allanwynn_16283)\
**Post date:** [November 20, 2015, 8:48am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/1 "2015-11-20T08:48:05Z")

</div>

Hi Everyone,

Can anyone help me to create an irule:

Pool Name: Pool\_Test Member: a. 10.10.10.2 port 0 (ALL) b. 20.20.20.2 port 0 (ALL)

Datagroup name: dg\_test

Snatpool: a. snat1 - 10.10.10.1 b. snat2 - 20.20.20.2

what i want is if the client ip is a member of the datagroup dg\_test, he will use pool\_test but will use the pool member 10.10.10.2 port 0 (ALL) and will be snat to snat1. then everything else will fall to pool\_test pool member 20.20.20.2 port 0 (ALL) and snat2

Please help me.

---

<div class="post-metadata">

**Author:** ![Brad\_Parker\_139](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Brad\_Parker\_139](https://community.f5.com/u/Brad_Parker_139)\
**Post date:** [November 20, 2015, 1:57pm UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/2 "2015-11-20T13:57:30Z")

</div>

Give this a whirl.

```tcl
when CLIENT_ACCEPTED {
    if { [class match [IP::client_addr] equals dg_test] }{
        pool pool_test member 10.10.10.2
        snat 10.10.10.1
    }
    else {
        pool pool_test member 20.20.20.2
        snat 20.20.20.1
    }
}

```

---

<div class="post-metadata">

**Author:** ![Brad\_Parker](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Brad\_Parker](https://community.f5.com/u/Brad_Parker)\
**Post date:** [November 20, 2015, 1:57pm UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/3 "2015-11-20T13:57:30Z")

</div>

Give this a whirl.

```tcl
when CLIENT_ACCEPTED {
    if { [class match [IP::client_addr] equals dg_test] }{
        pool pool_test member 10.10.10.2
        snat 10.10.10.1
    }
    else {
        pool pool_test member 20.20.20.2
        snat 20.20.20.1
    }
}

```

---

<div class="post-metadata">

**Author:** ![Allanwynn\_16283](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Allanwynn\_16283](https://community.f5.com/u/Allanwynn_16283)\
**Post date:** [November 21, 2015, 2:54am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/4 "2015-11-21T02:54:52Z")

</div>

is port not necessary on the configuration?

---

<div class="post-metadata">

**Author:** ![Allanwynn\_16283](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Allanwynn\_16283](https://community.f5.com/u/Allanwynn_16283)\
**Post date:** [November 21, 2015, 2:54am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/5 "2015-11-21T02:54:52Z")

</div>

is port not necessary on the configuration?

---

<div class="post-metadata">

**Author:** ![Brad\_Parker](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Brad\_Parker](https://community.f5.com/u/Brad_Parker)\
**Post date:** [November 21, 2015, 3:33am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/6 "2015-11-21T03:33:06Z")

</div>

Only if you plan on changing the port. Since you have 0 configured for the VIP and your pools there’s no need for port in the pool command.

---

<div class="post-metadata">

**Author:** ![Brad\_Parker\_139](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Brad\_Parker\_139](https://community.f5.com/u/Brad_Parker_139)\
**Post date:** [November 21, 2015, 3:33am UTC](https://community.f5.com/t/irule-for-snat-pool-and-data-group-and-pool-member/7758/7 "2015-11-21T03:33:06Z")

</div>

Only if you plan on changing the port. Since you have 0 configured for the VIP and your pools there’s no need for port in the pool command.
