Forum Discussion

scott_doty_2411's avatar
scott_doty_2411
Icon for Nimbostratus rankNimbostratus
Sep 27, 2006

Redirect to VIP based on source IP

Is it possible with iRules to redirect traffic destined for one VIP to a different VIP based on the source IP address of the traffic. In other words if 10.10.10.10 is connecting to VIP "VIP1" redirect him to "VIP2". All other traffic allow to pass normally... Any help you folks could give would be greatly appreciated!!
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    If you want to redirect a single client to a different URL (or VIP), you can use a rule like this:

    
    when HTTP_REQUEST {
       if { [IP::addr [IP::remote_addr] equals 10.0.0.10] } {
          HTTP::redirect "http://my.vip.example.com/"
       }
    }

    Or if you want to make the decision based on multiple hosts or networks, you can use a class (called a datagroup in the GUI) and a rule that references it:

    Datagroup definition:

    
    class my_hosts_networks_class  {
       network 10.0.0.0 mask 255.0.0.0
       host 192.168.0.100
    }

    And rule:

    
    when HTTP_REQUEST {
       if { [matchclass [IP::remote_addr] equals $::my_hosts_networks_class] } {
          HTTP::redirect "http://my.vip.example.com/"
       }
    }

    Note: to create the datagroup in the GUI, navigate to Local Traffic >> iRules and then click on the Datagroup tab. Enter the hosts/networks in the datagroup and then create the rule which references it.

    Aaron
  • Thanks hoolio. I get an error when trying to do the first option below:

     

     

     

    01070151:3: Rule [tst] error:

     

    line 3: [command is not valid in current event context (CLIENT_ACCEPTED)] [HTTP::redirect "http://adsearcher_testing.target.com/"]
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Ah, you caught me! I had a couple of logic and syntax errors in the first post, that I edited shortly thereafter.

     

     

    If you test the current rules in my first post, it should work.

     

     

    I originally posted an example which was triggered on the CLIENT_ACCEPTED event. If you're using an HTTP command, it needs to be done in an HTTP event. I also left off a closing double quote in the redirect.

     

     

    Let me know if you retest using the updated rule above and have any problems.

     

     

    Thanks,

     

    Aaron
  • Unfortunately this did not work. I point http traffic at the VIP that this iRule sits on from the source address specified in the rule, but the traffic is not redirected at all--it simply passes through to the pool. Any thoughts?