Forum Discussion

JCMATTOS_41723's avatar
JCMATTOS_41723
Icon for Nimbostratus rankNimbostratus
Nov 21, 2008

Loadbalance using names?

Hello Everyone,

 

 

We are trying to loadbalance thru our LTM's using names instead of IP's. We contacted F5 support and they said there might be way using an iRule. Essentially, we are trying to loadbalance to an external site which changes IP's often and everytime they make a change it breaks our product. I should also mention we are using the proxypass irule to do header rewriting, not sure if it matters. Please help! Thx...

3 Replies

  • James_Quinby_46's avatar
    James_Quinby_46
    Historic F5 Account
    JC -

     

     

    There was a thread about this awhile back - take a look at the discussion here for some ideas:

     

     

    http://devcentral.f5.com/default.aspx?tabid=53&view=topic&forumid=5&postid=6546

     

     

    (corrected the link)

     

     

    JQ

     

  • I applied the irule and tmm/named.conf change and I keep getting this error? And I did restart the tmm...Still no luck! Does this work with 9.4.5? Thx!

     

     

    Mon Dec 1 11:22:16 PST 2008 tmm tmm[10220] 01220001 TCL error: ExampleDNS CLIENT_ACCEPTED - cant read ::server_ip: no such variable while executing node $::server_ip [TCP::local_port]

     

     

    iRule:

     

     

    when RULE_INIT {

     

    set ::hostname "example.com"

     

    set ::max 10

     

    set ::count 0

     

    }

     

     

    when CLIENT_ACCEPTED {

     

    node $::server_ip 80

     

    incr ::count

     

    if { $::count == $::max } {

     

    set ::count 0

     

    NAME::lookup $::hostname

     

    }

     

    }

     

     

    when NAME_RESOLVED {

     

    log local0. "NAME_RESOLVED: [NAME::response]"

     

    set ::server_ip [NAME::response]

     

    }

     

     

     

  • You're using $::server_ip before setting a value for it. Can you try the example below instead. Also, you might want to add some error handling if the name resolution doesn't return an IP address before trying to use it for the connection. You can use IP::addr (Click here) to do this:

     
     when RULE_INIT { 
      
         Hostname to resolve address for 
        set ::hostname "example.com" 
      
         Resolve the hostname every X connections 
        set ::max 10 
      
         Force a lookup on the first connection 
        set ::count 10 
     } 
      
     when CLIENT_ACCEPTED { 
      
         Increment the global count of TCP connections 
        incr ::count 
      
         If we're over the limit, try to resolve the hostname 
        if { $::count > $::max } { 
      
           NAME::lookup $::hostname 
      
        } else { 
      
            Under the max, so use the saved IP address for this connection 
           node $::server_ip 80 
        } 
     } 
      
     when NAME_RESOLVED { 
      
        set answer [NAME::response] 
        log local0. "Received answer for $::hostname: $answer" 
      
         Check if response is an IP address 
        if {[IP::addr $answer mask 255.255.255.255]}{ 
      
            Save the most recent answer for the hostname 
           set ::server_ip $answer 
      
            Reset the count as we've successfully resolved the name 
           set ::count 0 
      
            Specify the updated IP address for this connection 
           node $::server_ip 80 
      
         Current answer wasn't an IP address, so check if there is a previous valid IP 
        } elseif {[info exists ::server_ip] and [IP::addr $::server_ip mask 255.255.255.255]}{ 
      
            Specify the updated IP address for this connection 
           node $::server_ip 80 
      
         No valid IP address to use, so take some default action? 
        } else { 
           log local0. "[IP::client_addr]:[TCP::client_port]: Error: No valid IP address for $::hostname" 
        } 
     } 
     

    Aaron