Forum Discussion

Piyush_72418's avatar
Piyush_72418
Icon for Nimbostratus rankNimbostratus
Feb 24, 2009

check

If I have a Geo IP based domain resolution @ DNS.

 

like based on Geo location abc.com will be resolved to either a.b.c.d (if US) and e.f.g.h (if from India)

 

Can I write a iRule on BigIP F5 LTM to have following functionality :

 

whenver request resolved from DNS to a.b.c.d redirect to http://abc.com/home_us.html

 

and when resolved to e.f.g.h redirect to http://abc.com/home_in.html

 

 

 

Thanks

 

Piyush

10 Replies

  • Hi Piyush,

    Yes this is possible, but it would be more or less looking up the known addresses found on the GEO-IP

     
     when CLIENT_ACCEPTED { 
       if { [IP::addr [IP::client_addr] equals a.b.c.d/8] } { 
          HTTP::redirect "http://abc.com/home_us.html" 
       } elseif {[IP::addr [IP::client_addr] equals e.f.g.h/8] } { 
          HTTP::redirect "http://abc.com/home_in.html" 
       } 
     } 
     

    Of if you have multiple address blocks within India and USA (which you will) then you I suggest using class objects

     
     class usa{ 
     a.b.c.d 255.255.0.0 
     m.n.o.p 255.0.0.0 
     } 
      
      
     class india { 
     e.f.g.h 255.255.0.0 
     i.j.k.l 255.0.0.0 
     } 
      
     when CLIENT_ACCEPTED { 
       if { [matchclass [IP::client_addr] equals $::usa] } { 
          HTTP::redirect "http://abc.com/home_us.html" 
       } elseif {[matchclass [IP::client_addr] equals $::india] } { 
          HTTP::redirect "http://abc.com/home_in.html" 
       } 
     } 
     

    Hope this helps

    CB

  • Hi CB,

     

     

    Getting following ERROR while creating iRule

     

     

    01070151:3: Rule [test_iRule] error:

     

    line 3: [command is not valid in current event context (CLIENT_ACCEPTED)] [HTTP::redirect "http://www.example.com" ]

     

     

    Any suggestions please..??
  • Also IP::client_addr is the IP address of the Client Connected (User)

     

     

    What I need to check is the DNS IP to which the DNS request from the client is resolved.

     

     

    I have a Geo IP based domain resolution @ DNS.

     

     

    like based on Geo location abc.com will be resolved to either a.b.c.d (if US) and e.f.g.h (if from India)

     

     

    Can I write a iRule on BigIP F5 LTM to have following functionality :

     

     

    whenever request resolved from DNS to a.b.c.d redirect to http://abc.com/home_us.html

     

     

    and when resolved to e.f.g.h redirect to http://abc.com/home_in.html
  • You can change the event from CLIENT_ACCEPTED to HTTP_REQUEST. In this case, CLIENT_ACCEPTED is triggered when the client establishes a TCP connection with the VIP. The HTTP headers have not been parsed at this point. HTTP_REQUEST is when the HTTP headers have been parsed. You can't send an HTTP redirect in CLIENT_ACCEPTED, but can in HTTP_REQUEST.

    Also, the format for the address type datagroup should be. Or you can create the datagroup under Local Traffic >> iRules >> Datagroup List >> Create >> Type: address.

     
     class my_address_datagroup { 
        network 10.10.0.0/16 
        host 192.168.0.11 
     } 
     

    Aaron
  • Posted By hoolio on 02/24/2009 11:43 PM

    You can change the event from CLIENT_ACCEPTED to HTTP_REQUEST. In this case, CLIENT_ACCEPTED is triggered when the client establishes a TCP connection with the VIP. The HTTP headers have not been parsed at this point. HTTP_REQUEST is when the HTTP headers have been parsed. You can't send an HTTP redirect in CLIENT_ACCEPTED, but can in HTTP_REQUEST.

    Also, the format for the address type datagroup should be. Or you can create the datagroup under Local Traffic >> iRules >> Datagroup List >> Create >> Type: address.

      
     class my_address_datagroup {  
     network 10.10.0.0/16  
     host 192.168.0.11  
     }  
     

    Aaron

    But what should I check in place of IP::client_addr ..??

    Any variable which gives the IP address resolved by DNS to a client..??
  •  

    What I need to check is the DNS IP to which the DNS request from the client is resolved.

     

     

     

     

    Assuming you're not using NAT between the client and the BIG-IP, this should be the VIP address then. Or if you are using NAT, the IP you'd want to check would still be the VIP address (even though that might not be the IP the client made the request to). So you can change IP::client_addr to IP::local_addr in the example CB posted.

     

     

    Aaron
  • Hi Piyush,

    I think I gave an incorrect suggestion. Does something like this sound correct to you?

    For VIP1, check if the requested path is /. If so, redirect the request to http://abc.com/home_india.html. Else, directly select VIP2 as the destination for the request.

     
     when HTTP_REQUEST { 
      
         Check if requested path is / 
        if {[HTTP::path] eq "/"}{ 
      
            Redirect client to initial page 
           HTTP::redirect "http://abc.com/home_india.html" 
        } else { 
      
            Send to VIP2 (where VIP2 is the name of the second VIP) 
           virtual VIP2 
        } 
     } 
     

    For VIP2, check if the requested path is /. If so, redirect the request to http://abc.com/home_us.html. Else, select VIP2's pool as the destination for the request.

     
     when HTTP_REQUEST { 
      
         Check if requested path is / 
        if {[HTTP::path] eq "/"}{ 
      
            Redirect client to initial page 
           HTTP::redirect "http://abc.com/home_us.html" 
        } 
         Default action is to use the default pool on the VIP 
     } 
     

    Aaron
  • Thanks Aaron !!

     

     

    The solution suggested by you worked perfectly fine!

     

     

    Thanks

     

    Piyush