Forum Discussion

Osiolek_69514's avatar
Osiolek_69514
Icon for Nimbostratus rankNimbostratus
Aug 02, 2010

Is something like that do-able?

Hi all,

 

 

I have three DNS records:

 

a.x.com --> 1.1.1.1

 

b.x.com --> (alias) --> a.x.com

 

c.x.com --> 2.2.2.2

 

 

As you can see both a.x.com and b.x.com point to the same Virtual Server (1.1.1.1). I want to create an iRule which will do the following:

 

1) if someone enters a.x.com, I want to update the URL to c.x.com and redirect him VS 2.2.2.2.

 

2) if someone enters b.x.com, I want to preserve the url (b.x.com), but still redirect him to VS 2.2.2.2

 

 

I do not have problem implementing (1), but I am stuck on how to achieve (2).

 

 

Please advise.

6 Replies

  • Hi Osiolek,

    I haven't tried this but if you are running LTM on v9.4 or above you can try the following example iRule.

    
    when HTTP_REQUEST {
         switch -glob [HTTP::host] {
           "a.x.com" { 
                     HTTP::redirect "http://c.x.com"
                    }
          "b.x.com" {
                    virtual 
                  }
         }
    }
    

    I hope this helps

    Bhattman

  • Thanks for answering my questions.

     

     

    Yes, I am running v9+. However, I should have been more clear. I was wondering weather it is possible to redirect to c.x.com (preserving the URL) without the need to specify the "virtual" keyword. My understanding is that virtual works similarly to "pool", but instead you use the VS name?

     

    I was thinking that something like shown below is do-able:

     

    - request arrived for b.x.com --> needs to go to the IP address of c.x.com (store the IP address of c.x.com)

     

    - redirect to IP address of c.x.com (and change the URL back to b.x.com, if got updated)

     

     

    Is it possible to make it work without hard coding the IP address or pool/virtual name of c.x.com? Or is this simply "too hcomplex" and would require one to use GTM iRules?
  • You can resolve a host name to an IP address using NAME::lookup in 9.x or RESOLV::lookup in 10.1 and higher.

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/name__lookup

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/resolv__lookup

     

     

    There's an example using NAME::lookup in the Codeshare:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/DestinationSnatUsingDNS.html

     

     

    If you want to rewrite the hostname and/or URI, you could use "HTTP::header replace Host $new_host" and/or "HTTP::uri $new_uri"

     

     

    You can check the ProxyPass iRule for a very comprehensive example of this:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/proxypass

     

     

    Aaron
  • It sounds like what you want is for the client to still see b.x.com in their browser bar but connect to the IP address of c.x.com instead, correct?

     

     

    The problem with your example is that the translation of that host name to an IP address is up to the user to perform. If you redirect over to the IP address of the VIP for c.x.com then the user will see the IP address on their browser, and while you can rewrite the host header on the way back to the servers the user is still going to see the IP address in the address bar. If you try and send them to b.x.com again then the client will just do another IP lookup and send the requests back to your original b.x.com IP address.

     

     

    I think your best bet would be to either use that VIP to VIP iRule like Hoolio suggested or to just duplicate the config of VIP c onto VIP b.

     

     

    In that case you'd have two VIPs setup pointing to the same pools and with the same configuration, but they would be on their own IPs. Then you'd just have the redirect for a.x.com to the c.x.com VIP on the b.x.com VIP, and you're customers would see the same thing as if they were connected to c.x.com.

     

     

    Really though, Hoolio's answer is probably the best way to simply management of the config and get you the same behavior as my alternate config. You can't really make them have the hostname of b.x.com show up in their browser and go to the IP of c.x.com unless you alter the DNS records.

     

     

    Why not just make b.x.com a CNAME for c.x.com instead of a.x.com? That way the browser uses the IP of the c VIP for the b.x.com and you don't even have the issue.

     

  • Thank you gents. I will investigate both solutions.

     

     

    One more question on the solution proposed by Bhattman. It looked to me that if one uses the "virtual " statement, for some reason iRules that are applied to itself are not applied when redirecting traffic to this VS. Have I missed something ot is this by design?
  • iRules should trigger regardless of whether the virtual command is used. I'd try adding debug logging to both iRules and check the output in /var/log/ltm. If you want help diagnosing the issue post anonymized copies of the two rules, virtual server definitions and logs. Or you could open a case with F5 Support.

     

     

    Aaron