For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Allanwynn_16283's avatar
Allanwynn_16283
Icon for Nimbostratus rankNimbostratus
Oct 18, 2015

irule for rewrite

Hi Everyone,

So we have a setup where the user access the VS of F5 "https://my.url.com".

Our current setup is using client source IP based for load balancing (odd-even):

when HTTP_REQUEST {

set lastoctet [lindex [split [IP::client_addr] .] 3]

if { [expr $lastoctet % 2] == 1 } {
    HTTP::respond 301 Location "https://our.url1.com" 
} else {
    HTTP::respond 301 Location "https://our.url2.com"
}

}

My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also?

i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to and he will see that url ( on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to and he will see that url ( on his browser

WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to and but he will see on his url is https://my.url.com on his browser

Is this possible?

11 Replies

  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    Yes. Rewrite the HTTP Host header as it is proxied from client-side request to server-side request:

    when HTTP_REQUEST {
        if { [getfield [IP::client_addr] . 4] & 0x01 == 1 } {
            HTTP::host "our.url1.com"
        }
        else {
            HTTP::host "our.url2.com"    
        }
    }
    
    • Allanwynn_16283's avatar
      Allanwynn_16283
      Icon for Nimbostratus rankNimbostratus
      hi? can you help me with my question? My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also? i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and he will see that url (https://our.url2.com) on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and he will see that url (https://our.url1.com) on his browser WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
    • Vernon_97235's avatar
      Vernon_97235
      Historic F5 Account
      I apologize if I missed something you wanted (e.g., @stanislas's pool selection) but I do believe that this accomplishes what you request. I altered the mechanism for octet extraction and odd/even selection in order to make it more compact and slightly faster. More to the point, server virtual host selection is generally a function of the submitted HTTP Host header value. Changing that in HTTP_REQUEST will change it between the BIG-IP and the Pool Member only. Thus, the client will not "know" that a change was made at all (and as such, the originally selected URL will remain unaltered in the user-agent/browser).
    • Allanwynn_16283's avatar
      Allanwynn_16283
      Icon for Nimbostratus rankNimbostratus
      Hi, thank you for your feedback. But what if we have an issue with the communication between F5 big ip and the servers, wherein creating basic load balancing setup: VS 443 and pool is port 80, so we decided just to redirect it with the server itself. Can we use this for this setup for added security? WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
  • Yes. Rewrite the HTTP Host header as it is proxied from client-side request to server-side request:

    when HTTP_REQUEST {
        if { [getfield [IP::client_addr] . 4] & 0x01 == 1 } {
            HTTP::host "our.url1.com"
        }
        else {
            HTTP::host "our.url2.com"    
        }
    }
    
    • Allanwynn_16283's avatar
      Allanwynn_16283
      Icon for Nimbostratus rankNimbostratus
      hi? can you help me with my question? My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also? i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and he will see that url (https://our.url2.com) on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and he will see that url (https://our.url1.com) on his browser WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
    • VernonWells's avatar
      VernonWells
      Icon for Employee rankEmployee
      I apologize if I missed something you wanted (e.g., @stanislas's pool selection) but I do believe that this accomplishes what you request. I altered the mechanism for octet extraction and odd/even selection in order to make it more compact and slightly faster. More to the point, server virtual host selection is generally a function of the submitted HTTP Host header value. Changing that in HTTP_REQUEST will change it between the BIG-IP and the Pool Member only. Thus, the client will not "know" that a change was made at all (and as such, the originally selected URL will remain unaltered in the user-agent/browser).
    • Allanwynn_16283's avatar
      Allanwynn_16283
      Icon for Nimbostratus rankNimbostratus
      Hi, thank you for your feedback. But what if we have an issue with the communication between F5 big ip and the servers, wherein creating basic load balancing setup: VS 443 and pool is port 80, so we decided just to redirect it with the server itself. Can we use this for this setup for added security? WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
  • Hi Allanwynn,

    to display the user must request https://my.url.com.

    So, the solution is to not redirect users to https://my.url1.com or https://my.url2.com but assign pool member different and rewrite host header.

    when HTTP_REQUEST {
        set lastoctet [lindex [split [IP::client_addr] .] 3]
    
        if { [expr $lastoctet % 2] == 1 } {
            pool pool1
            HTTP::host "our.url1.com"
        } else {
            pool pool2
            HTTP::host "our.url2.com"
        }
    }
    
  • the irule provided does not redirect user to url1 or url2 but forward the request to the right pool with host header rewriting (maybe useless).

     

    Why are you using odd-even load balancing instead of builtin load balancing method?

     

  • If you have issues with direct load balancing, this may be a persistence issue.

     

    did you try to resolve it before trying to change behavior to redirect with 2 urls?