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

string map

command to make the replacement more dynamic

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

string map

command to make the replacement more dynamic

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
    }
}

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
    }
}

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

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

This is the iRule that I have mapped out, still does not work. :frowning: 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] } }

This is the iRule that I have mapped out, still does not work. :frowning: 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,

Are you sure that you resolve the new_host ?

when RULE_INIT {
    set static::dns "1.1.1.1"
}

when HTTP_REQUEST {
    if { [HTTP::host] contains "externaldomain.com" } {
        set new_host [string map {externaldomain internaldomain} [HTTP::host]]
        set ips [lindex [RESOLV::lookup @$static::dns -a $new_host] 0]
        node $ips [TCP::local_port]
    }
}

Hi,

Are you sure that you resolve the new_host ?

when RULE_INIT {
    set static::dns "1.1.1.1"
}

when HTTP_REQUEST {
    if { [HTTP::host] contains "externaldomain.com" } {
        set new_host [string map {externaldomain internaldomain} [HTTP::host]]
        set ips [lindex [RESOLV::lookup @$static::dns -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…

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

thanks again Yann… to ensure that DNS is not causing a issue I have put the hostname as a static host entry on the F5 itself.

thanks again Yann… to ensure that DNS is not causing a issue I have put the hostname as a static host entry on the F5 itself.

Interesting approach. You use

[RESOLV::lookup]

within an iRule to query a STATIC HOST entry. How about skipping

[RESOLV::lookup]

and putting the resolved IP directly into your iRule?

Cheers, Kai

Interesting approach. You use

[RESOLV::lookup]

within an iRule to query a STATIC HOST entry. How about skipping

[RESOLV::lookup]

and putting the resolved IP directly into your iRule?

Cheers, Kai

yes, it does seem that DNS is messgin up something here. I have commented the same below. Again, I would not know how to set the IP of the node with iRule. :frowning:

any comments there are well? Sorry for the bugging but trying to get the familiarity.

yes, it does seem that DNS is messgin up something here. I have commented the same below. Again, I would not know how to set the IP of the node with iRule. :frowning:

any comments there are well? Sorry for the bugging but trying to get the familiarity.

The DNS is just not responding. The queries resolve correctky when I do a lookup from the Linux Kernel and the TMSH. Could there be anything different the iRule needs?

The DNS is just not responding. The queries resolve correctky when I do a lookup from the Linux Kernel and the TMSH. Could there be anything different the iRule needs?