# Virtual Server multiple service ports

**URL:** <https://community.f5.com/t/virtual-server-multiple-service-ports/14247>\
**Category:** Technical Forums\
**Tags:** design, config\
**Created:** [November 20, 2008, 3:54pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247 "2008-11-20T15:54:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkSideOfTheQ](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DarkSideOfTheQ](https://community.f5.com/u/DarkSideOfTheQ)\
**Post date:** [November 20, 2008, 3:54pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/1 "2008-11-20T15:54:14Z")

</div>

Hello,

I am new to F5 devices and load balancers in general, only having limited exposure to some Foundry devices until now. I am curious about what I’ve read and seen thus far about creating a virtual server and the ports it will allow connections on. Do I really need to create a new virtual server for each port that I want available or am I overlooking something and creating more work for myself?

Thanks,

DarkSide

---

<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:** [November 20, 2008, 4:07pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/2 "2008-11-20T16:07:10Z")

</div>

You can configure a VIP on port 0 (any port) and then use an iRule or IP filters to restrict which destination ports can be used. Here is an example iRule which drops requests outside of a range of ports:

```tcl
when CLIENT_ACCEPTED { 
  
     Check if requested port is outside 1000 - 2000 
    if { [TCP::client_port] < 1000 or [TCP::client_port] > 2000}{ 
  
        Drop request 
       drop 
    } 
 }

```

Aaron

---

<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:** [November 20, 2008, 4:13pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/3 "2008-11-20T16:13:03Z")

</div>

In general the LTM is default-deny device, so yes if you do not configure a virtual for each port you need then the traffic will be blocked. That being said, you can create virtuals and pools on port 0 (any port). That will allow all ports to communicate on that virtual.

The downside is that you have to create custom monitors for health checks on the pool, because the default monitors are set up to check whatever port the pool members are configured on. Since you can’t health check port 0, you have to define a custom monitor that explicitly calls the port you need to check on the servers.

So if you only need 3 or 4 ports, I would recommend going ahead and configuring one vip per port, that way you can take advantage of the granularity to be able to tweak settings as you wish (and see separate statistics). If on the other hand you have an application that might open up 100 different ports, then I’d advise using a wildcard port 0 vip and creating a custom health monitor.

Denny

---

<div class="post-metadata">

**Author:** ![DarkSideOfTheQ](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DarkSideOfTheQ](https://community.f5.com/u/DarkSideOfTheQ)\
**Post date:** [November 20, 2008, 5:16pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/4 "2008-11-20T17:16:39Z")

</div>

Aaron - I am just begining to learn the iRules and have only created simple HTTP/HTTPS redirects thus far. Your example sounds interesting and I’ll have to play around some.

Denny - I am indeed only concerned with a few ports, mostly HTTP, HTTPS, SSH, FTP for various hosts. The mention of the statistics, was not something I had thought about and with that in mind, can see the benefit of having the different virtuals setup.

I really appreciate the replies and am glad to see that there is a good community that I can turn to with what I am sure is just the first of many questions…after I RTFM of course. 🙂

---

<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:** [November 20, 2008, 5:22pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/5 "2008-11-20T17:22:08Z")

</div>

If it’s only a few ports and the protocol isn’t the same, I agree with Denny that it’s better to configure individual VIPs. As he suggested, this allows you to configure protocol-specific profiles and tweak the settings according to the protocol. The port range option is better if it’s a lot of ports--particularly if it’s the same protocol.

Aaron

---

<div class="post-metadata">

**Author:** ![Josh\_41258](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@Josh\_41258](https://community.f5.com/u/Josh_41258)\
**Post date:** [September 24, 2009, 2:31pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/6 "2009-09-24T14:31:18Z")

</div>

Sorry for the bump, but could someone help me out with the proper syntax for something like:

```tcl
when CLIENT_ACCEPTED {  
  
      Check if requested port is outside 1000 - 2000  
     if { [TCP::client_port] < 1000 or [TCP::client_port] > 2000 or [TCP::client_port] not 3389 or [TCP::client_port] not 1500 or [TCP::client_port] not 161 }{  
  
         Drop request  
        drop  
     }

```

I’m trying to allow a range (12000-13000) and several individual ports, but drop/reject the rest.

Thanks,

Josh

---

<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:** [September 28, 2009, 6:20am UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/7 "2009-09-28T06:20:43Z")

</div>

Hi Josh,

My original post should have used TCP::local\_port to check the destination port on the client’s packet--not the source port. I think this should do what you’re looking for:

```tcl
when CLIENT_ACCEPTED { 
  
     Check if requested port is outside 1000 - 2000 
    if { not (([TCP::local_port] > 1000 and [TCP::local_port] < 2000) or [TCP::local_port] == 3389 or [TCP::local_port] == 1500 or [TCP::local_port] == 161) }{ 
        Drop request 
       drop 
    } 
 }

```

Aaron

---

<div class="post-metadata">

**Author:** ![Dilip\_bhapkar06](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@Dilip\_bhapkar06](https://community.f5.com/u/Dilip_bhapkar06)\
**Post date:** [January 21, 2010, 8:17am UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/8 "2010-01-21T08:17:17Z")

</div>

Hi ,I am just begin to learn F5 device.I want to open 7 ports ( Mail Related) in F5 for same virtual Server.

I have created 7 virtual server for same IP and 7 different pools and add the Actual Mail server in that Pool.

what is the easiest way for this case.

How will open multiple ports in a single virtual server

---

<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:** [January 21, 2010, 3:01pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/9 "2010-01-21T15:01:00Z")

</div>

using port zero will listen for all ports, then you could use a switch statement to handle the ports you want with a default condition of discard.

---

<div class="post-metadata">

**Author:** ![kamals\_48971](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@kamals\_48971](https://community.f5.com/u/kamals_48971)\
**Post date:** [August 31, 2014, 2:46pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/10 "2014-08-31T14:46:20Z")

</div>

but if I have to allow different range of address like 19000-20000 and 30000 - 30999 then I tried this but now sure if it is correct b rule tcp\_port '{ when CLIENT\_ACCEPTED { Check if requested port is outside 18000 - 20999 ,30000 - 30999 if { [TCP::client\_port] \< 19000 or [TCP::client\_port] \< 30000 or [TCP::client\_port] \> 20999 or [TCP::client\_port] \> 30999

}{

```tcl
Drop request 
   drop 
}

```

} }’

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [August 31, 2014, 2:55pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/11 "2014-08-31T14:55:51Z")

</div>

is it source port (client port) or destination port (virtual server port)? if it is destination, it is TCP::local\_port.

```tcl
when CLIENT_ACCEPTED { 
   Check if requested port is outside 18000 - 20999, 30000 - 30999 
  if { not ( [TCP::local_port] >= 18000 and [TCP::local_port] <= 20999 ) and 
       not ( [TCP::local_port] >= 30000 and [TCP::local_port] <= 30999 ) } {
     Drop request 
    drop 
  } 
}

```

TCP::local\_port

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

---

<div class="post-metadata">

**Author:** ![kamals\_48971](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@kamals\_48971](https://community.f5.com/u/kamals_48971)\
**Post date:** [September 1, 2014, 2:52pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/12 "2014-09-01T14:52:24Z")

</div>

this is destination port. And I need to accept traffic for 19000 - 20999 and 30000 and 30999, the above I rule will drop all the traffic greater than 18000 and less then 20999. Also for 30000 to 30999

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [September 1, 2014, 2:55pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/13 "2014-09-01T14:55:13Z")

</div>

there is “not” in expression, isn’t it?

---

<div class="post-metadata">

**Author:** ![kamals\_48971](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@kamals\_48971](https://community.f5.com/u/kamals_48971)\
**Post date:** [September 1, 2014, 9:42pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/14 "2014-09-01T21:42:21Z")

</div>

Thanks a lot , I will try tomorrow and let you know. Kamal

---

<div class="post-metadata">

**Author:** ![Desai\_124243](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@Desai\_124243](https://community.f5.com/u/Desai_124243)\
**Post date:** [October 20, 2015, 6:19pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/15 "2015-10-20T18:19:48Z")

</div>

Hi,

I like to allow only TCP 80, TCP 443, UDP 500 & UDP 4500 on 0 port Virtual . Is below IRULE configuration right?

when CLIENT\_ACCEPTED { Check if requested port is allowing only TCP 443, TCP 80, UDP 4500 and UDP 500 if { ( [TCP::client\_port] != 443 or [TCP::client\_port] != 80 or [UDP::client\_port] != 500 or [UDP::client\_port] != 4500 ) } { Drop request drop } }

Thanks

---

<div class="post-metadata">

**Author:** ![kamal\_48965](https://avatars.discourse-cdn.com/v4/letter/k/ac8455/32.png) [@kamal\_48965](https://community.f5.com/u/kamal_48965)\
**Post date:** [October 21, 2015, 6:21pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/16 "2015-10-21T18:21:01Z")

</div>

Please add not after if statement

if { not ( [TCP::client\_port] != 443 or [TCP::client\_port] != 80 or [UDP::client\_port] != 500 or [UDP::client\_port] != 4500 ) } { Drop request drop } } drop } }

---

<div class="post-metadata">

**Author:** ![kamal\_48965](https://avatars.discourse-cdn.com/v4/letter/k/ac8455/32.png) [@kamal\_48965](https://community.f5.com/u/kamal_48965)\
**Post date:** [October 22, 2015, 3:03pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/17 "2015-10-22T15:03:40Z")

</div>

???

---

<div class="post-metadata">

**Author:** ![Desai\_124243](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@Desai\_124243](https://community.f5.com/u/Desai_124243)\
**Post date:** [October 22, 2015, 6:35pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/18 "2015-10-22T18:35:55Z")

</div>

Its works.

Thanks for helping

---

<div class="post-metadata">

**Author:** ![Jason\_Hawke](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jason\_Hawke](https://community.f5.com/u/Jason_Hawke)\
**Post date:** [November 30, 2016, 6:29pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/19 "2016-11-30T18:29:27Z")

</div>

You can configure one virtual server for all ports but that creates a security vulnerability. Its better to have a virtual server for each application service port you need - that way you are limiting your network exposure to just those known ports.

The other advantage to having multiple virtual servers for each port is it allows you to have better insight as to the health and availability of your application. You will know if a particular component is down or not (HTTPS is up on the web server but the app server is down for instance).

Lastly, each virtual server will have corresponding profiles that can help in logging events. If you’re using AVR (which I hope you are) or at least request logging then you can see each transaction as it transverses both the F5 and your application.

---

<div class="post-metadata">

**Author:** ![ShakeelRashid](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@ShakeelRashid](https://community.f5.com/u/ShakeelRashid)\
**Post date:** [September 19, 2017, 2:07pm UTC](https://community.f5.com/t/virtual-server-multiple-service-ports/14247/20 "2017-09-19T14:07:33Z")

</div>

Guys,

Is it possible to use a data group list to list the port numbers? i.e. something like the below where Defined\_Ports references an integer or string Data Group List?

when CLIENT\_ACCEPTED {

if { not ([matchclass [TCP::local\_port] equals Defined\_Ports]) }{ log local0. “Invalid Port: [TCP::local\_port] - discarding” discard } }

[Next page](https://community.f5.com/t/virtual-server-multiple-service-ports/14247.md?page=2)
