Forum Discussion
iRule which strips of the domain name and replaces that with another domain name.
Team, Can anyone help me with an iRule which strips of the domain name and does a DNS query with some other domain name? e.g. The F5 intercepts a request on "xyz.externaldomain.com". F5 strips of the externaldomain.com and replaces this with "xyz.internaldomain.com" and does a lookup. The IP address returned in the lookup is used for the node in the VIP.
Thanks!! N.
Hi,
Maybe the following irule may help you :
when HTTP_REQUEST { if { [HTTP::host] contains "xyz.externaldomain.com" } { HTTP::header replace Host "xyz.internaldomain.com" } }
You may also use
command to make the replacement more dynamicstring map
Hi,
Maybe the following irule may help you :
when HTTP_REQUEST { if { [HTTP::host] contains "xyz.externaldomain.com" } { HTTP::header replace Host "xyz.internaldomain.com" } }
You may also use
command to make the replacement more dynamicstring map
Using string map :
when HTTP_REQUEST { if { [HTTP::host] contains "xyz.externaldomain.com" } { set new_host [string map {externaldomain internaldomain} [HTTP::host]] HTTP::header replace Host $new_host } }
- N_67263Nimbostratus
hey Yann....thanks a ton. I think the logic should work. However, we would like to use the new domain to do a lookup and what ever is the IP returned use that IP address in the node to forward the traffic.
Let me work on some extension of iRule with the logic you provided
- N_67263Nimbostratus
This is the iRule that I have mapped out, still does not work. :( any comments?
when HTTP_REQUEST { if { [HTTP::host] contains "externaldomain.com" } { set new_host [string map {externaldomain internaldomain} [HTTP::host]] set ips [lindex [RESOLV::lookup -a [$new_host]] 0] node $ips [TCP::local_port] } }
- Yann_Desmarest_Nacreous
Hi,
Maybe the following irule may help you :
when HTTP_REQUEST { if { [HTTP::host] contains "xyz.externaldomain.com" } { HTTP::header replace Host "xyz.internaldomain.com" } }
You may also use
command to make the replacement more dynamicstring map
- Yann_Desmarest_Nacreous
Using string map :
when HTTP_REQUEST { if { [HTTP::host] contains "xyz.externaldomain.com" } { set new_host [string map {externaldomain internaldomain} [HTTP::host]] HTTP::header replace Host $new_host } }
- N_67263Nimbostratus
hey Yann....thanks a ton. I think the logic should work. However, we would like to use the new domain to do a lookup and what ever is the IP returned use that IP address in the node to forward the traffic.
Let me work on some extension of iRule with the logic you provided
- N_67263Nimbostratus
This is the iRule that I have mapped out, still does not work. :( any comments?
when HTTP_REQUEST { if { [HTTP::host] contains "externaldomain.com" } { set new_host [string map {externaldomain internaldomain} [HTTP::host]] set ips [lindex [RESOLV::lookup -a [$new_host]] 0] node $ips [TCP::local_port] } }
Hi N,
please don't open multiple question for the same topic. It doesn't make sense if independent people spend their valuable time to answer your redundant questions over and over...
https://devcentral.f5.com/questions/understanding-the-host-in-the-http-request-55264
https://devcentral.f5.com/questions/node-autoselection-using-dns-55263
Note: I've already told you to add some error handles to your iRule, to become able to indentify where it breaks. In addition to that I've linked K12225 [click me] to make sure the DNS on your F5 allows recursive DNS queries. I've also speak out the recommendation to setup a DNS Virtual Server to become able to query a pool of redundant DNS servers.
Well, based on your latest requirements (added external / internal DNS domain conversation) the resulting iRule code would look like that...
when HTTP_REQUEST { if { [HTTP::host] eq "xyz.externaldomain.com" } then { set ips [lindex [RESOLV::lookup -a "[getfield [HTTP::host] "." 1].internaldomain.com"] 0] log local0.debug "Debug: Resolved address for \"[getfield [HTTP::host] "." 1].internaldomain.com\" = \"$ips\"" if { $ips ne "" } then { node $ips [TCP::local_port] } else { HTTP::respond 504 content "Bad Request - unknown HOST value" } } else { HTTP::respond 504 content "Bad Request - wrong HOST value" } }
Cheers, Kai
- Stanislas_Piro2Cumulonimbus
Hi,
You can define which dns server is used for DNS requests.
If you want to manage DNS servers, create a LTM pool including dns servers with dns monitor and use this irule. the dns pool name in this irule is
p_dns
when CLIENT_ACCEPTED { foreach dns [active_members -list p_dns] { Check if the first list element was empty if {[set dest [lindex [RESOLV::lookup @[lindex $dns 0] -a "www.abc.com";] 0]] ne ""} { Set Node IP based on DNS resolution node $dest 443 break } } }
- N_67263Nimbostratus
thanks all of you!! This helps me... :)
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com