Forum Discussion

Ajit's avatar
Ajit
Icon for Altostratus rankAltostratus
Mar 24, 2017

iRule to load balance between different nodes on different ports in the same pool & single VIP.

Hello All-

 

I need a iRule to make something work for me. I need a VIP listening on a single port to be able to pass traffic to different nodes on different ports for the same instance of application.

 

eg: VIP --> 10.10.10.10 Port : 32077 Pool Members --> 10.10.1.1 Port:32077,10.10.1.1 Port:62077,10.10.1.2 Port:32077,10.10.1.2 Port:62077,

 

I am still a learner in iRules. Any help would be greatly appreciated.

 

Thanks in advance ! Regards, AS

 

2 Replies

  • You don't need an iRule for this. Add the 4 servers (with the correct port) to the LB pool and attach the pool to your VS.

     

    The BIG-IP will perform port translation for the 2 servers listening on port 62077.

     

    Cheers,

     

    Kees

     

  • Hello Ajit,

    Both 32077 and 62077 are non-standard ports. I would expect the URL to look something like http://domain.com:32077/ which means the host header would be domain.com:32077.

    Based on comments you gave, it's not that the F5 isn't sending the request to the correct port, it's that the server is not responding to the request properly. Perhaps the server is expecting a different port in the host header?

    I'm making a lot of assumptions, but could you try something like this?

    Change port in host header
    when HTTP_REQUEST_SEND {
        clientside {
            set HOST [getfield [HTTP::host] : 1]
            set PORT [getfield [HTTP::host] : 2]
    
            if {($PORT ne "") && ($PORT != [TCP::server_port])} {
                 port is different, change the port in the Host Header
                HTTP::header replace Host "${HOST}:[TCP::server_port]"
            }
    
             clean up variables
            unset HOST PORT
        }
    }
    
    Notes
    1. I chose
      HTTP_REQUEST_SEND
      because it fires after the server connection allowing reliable use of the
      TCP::server_port
      command. Technically
      LB::server port
      should also work based on the scenario you described (i.e. pool members are configured with actual ports 32077/62077).
    2. Because
      HTTP_REQUEST_SEND
      is a server-side event, any changes to the request need to be done in a
      clientside
      context.
    3. The rule is checking to see if the port exists in the host header
      ($PORT ne "")
      , this may not be needed in your scenario.

    If it turns out the port is the issue, more action may be necessary to account for any HTML content in the server's response that are not relative and have full URLs containing

    domain:port
    .