# Forward using hostname as node, not IP

**URL:** <https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [February 16, 2006, 2:20pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531 "2006-02-16T14:20:08Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [February 16, 2006, 2:20pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/1 "2006-02-16T14:20:08Z")

</div>

Hi,

I require the ability to create a forwarding server to forward traffic to a hostname rather than an IP address. A third party we are connecting to provides resilience to their systems by a DNS service, allowing them to provide a hostname rather than a string of potential IP addresses and such. Whilst I can add a node to the big-ip by using a hostname, the hostname is resolved to an IP at configuration time. Instead I require a DNS lookup to be performed on a regular basis when the virtual server is in active use. This does not seem possible within the 9.1.1 software, and would appreciate any information to the contrary, or potential workarounds if any are forthcoming.

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [February 16, 2006, 2:42pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/2 "2006-02-16T14:42:47Z")

</div>

We here at DevCentral are the folks who work on the API (iControl) and the onboard packet inspector/scripting language (iRules). If you have a question about building iControl apps or writing iRules, this is the place for you.

Unfortunately, this isn’t the place for product technical support. We simply aren’t staffed to handle that side of things. You’ll need to talk to the folks in our product support department for questions like these.

They can be easily contacted here: [Click here](https://websupport.f5.com/csp/logon.asp) - [https://websupport.f5.com/csp/logon.asp](https://websupport.f5.com/csp/logon.asp)

A good place to start looking for information is often [Click here](http://tech.f5.com/askf5/jsp/combined/index.jsp) - [http://tech.f5.com/askf5/jsp/combined/index.jsp](http://tech.f5.com/askf5/jsp/combined/index.jsp)

Best of luck,

-Colin

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [February 16, 2006, 2:59pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/3 "2006-02-16T14:59:47Z")

</div>

Sorry, i’d already contacted support and they directed me to you in the hope that an irule can help me out… i lazily pasted my support email largely verbatim. sorry if that was confusing, but i was going for an iRule angle here.

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [February 16, 2006, 3:24pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/4 "2006-02-16T15:24:04Z")

</div>

No problem…

Well, mmoeller is on the right track, if you’re looking to do hostname lookups in an iRule. The NAME::lookup command will allow you to do just that.

Something like:

```tcl
when RULE_INIT {
  set ::time [clock clicks -seconds]
}
when HTTP_REQUEST {
  if{ [expr {$::time + 30}] <= [clock clicks -seconds] } {
    NAME::lookup "hostnametobeused.com"
    set ::time [clock clicks -seconds]
  } else { 
    node $::node 80
  }
}
when NAME_RESOLVED {
  set ::node [NAME::response]
  node $::node 80
}

```

Would probably get you close to where you’re trying to go, but I’d be a little concerned about the overhead it would generate, since it would have to process the current time and compare it to the previous one plus the interval (30 in this case). You could possibly set it up so that it only checked every n connections (10, 50, 100, whatever), which might help circumvent this.

Is this the sort of thing you had in mind?

-Colin

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [February 16, 2006, 3:45pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/5 "2006-02-16T15:45:57Z")

</div>

That looks seriously useful now, great! And to think i was expecting to be dissapointed.

One thing though, if you are assigning a node there, where would i see statistics about the traffic sent to it? can it not be recorded?

Cheers

Chris

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [February 16, 2006, 5:05pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/6 "2006-02-16T17:05:49Z")

</div>

Well, assuming that the node in question is not a member of a pool on the BIG-IP, you’d have to log your own stats in the rule.

If the node IS a member of a pool, then you could replace the “node $::node 80” commands with “pool member $::node 80”, and you’d see the stats under the pool in question.

-Colin

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [March 9, 2006, 9:22pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/7 "2006-03-09T21:22:51Z")

</div>

Hi,

Thanks for the advice so far, but something is not working right. My iRule as it stands reads like this:

when RULE\_INIT {

set ::hostname “[example.com](http://example.com)”

set ::max 10

set ::count 0

set ::server\_ip “192.168.0.1”

}

when CLIENT\_ACCEPTED {

node $::server\_ip 80

incr ::count

if { $::count == $::max } {

set ::count 0

NAME::lookup $::hostname

}

}

when NAME\_RESOLVED {

log local0. “NAME\_RESOLVED: [NAME::response]”

set ::server\_ip [NAME::response]

}

It works fine to start with, and after the max limit is reached the lookup fires off. I then get the NAME\_RESOLVED event, yet NAME::response returns nothing, and the whole thing chokes. i can dig the destination hostname on the box no problem, so would assume that there is no inherent problem on the box in terms of dns resources. Additionally i would assume that that event would only be triggered on a valid resolution, not every single return value. Any clues guys?

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![Ethan\_Erchinger](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Ethan\_Erchinger](https://community.f5.com/u/Ethan_Erchinger)\
**Post date:** [March 10, 2006, 5:27pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/8 "2006-03-10T17:27:06Z")

</div>

I was just experimenting with this, but I can’t seem to get it to resolve. Anyone know if I need to restart something after modifying tmm\_base.tcl?

---

<div class="post-metadata">

**Author:** ![Ethan\_Erchinger](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Ethan\_Erchinger](https://community.f5.com/u/Ethan_Erchinger)\
**Post date:** [March 10, 2006, 5:53pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/9 "2006-03-10T17:53:38Z")

</div>

Ok, sorry, I did a “bigstart restart tmm”, and it all works. Thx.

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [March 10, 2006, 9:26pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/10 "2006-03-10T21:26:59Z")

</div>

I think i’m missing something here…

firstly that code doesn’t seem to be intended to fix what i was after. It certainly looks interesting but am not sure that it relates to what i need. I’ve added to the tmm\_base (although the tmm\_init.tcl customizatin file seems liek a much nicer place to make additions. and then I commented those three lines in named.conf (it was just those 3 right?) and restarted both tmm and named via bigstart… nothing. same blank response.

From my issues, i do appear to be using the (undocumented) NAME::response command wrong, as the example uses [NAME::response address 0] to obtain the actual IP address. but still… no change.

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [March 11, 2006, 12:09pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/11 "2006-03-11T12:09:43Z")

</div>

Hi,

seems i needed to list my forwarding addresses in named.conf and enable recursion there too, and it’s now working, which is great, thanks a lot guys. Should i have to add the forwarders in there though? i’d rather not if i don’t have to, and the above exmaple doesn’t. my name servers are listed in resolv.conf in linux land… can we just refer to them implicitly rather than explicitly listing them?

This raise a question I have in generally… If you guys are saying we need to do x, y or z outside of an irule to achieve this, is this not invalidating my commercial support with F5? Also the fact that I have had intimate changes to bind on each box is pretty invisible to anyone else. If i end up using these changes, i will naturally document them, but when i come to upgrade… all changes will be lost right?

Thanks again

Chris

---

<div class="post-metadata">

**Author:** ![Ethan\_Erchinger](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@Ethan\_Erchinger](https://community.f5.com/u/Ethan_Erchinger)\
**Post date:** [March 12, 2006, 2:25am UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/12 "2006-03-12T02:25:59Z")

</div>

For completeness.

I’ve captured some data from this thread and from another thread, that are related, in the Codeshare available at:

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

Also, the other article I speak of, listed below, talks about a small bug in the above code. See the post from “3/11/2006 7:21 PM”.

> **[DevCentral - An F5 Technical Community](https://community.f5.com/?tabid=28&forumid=5&view=topic&postid=6899)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [March 12, 2006, 6:03am UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/13 "2006-03-12T06:03:32Z")

</div>

you can make sure the changes survive an upgrade by adding whatever system files you change to the cs.dat file in /usr/libdata/configsync. After you’ve specified the files here (check first to make sure they aren’t already included), they will be backed up when you do a bigpipe config save (and when you do a sync)

Note that there is a problem with adding /etc/syslog-ng/syslog-ng.conf to cs.dat if you are upgrading, search [ask.f5.com](http://ask.f5.com) for the details.

---

<div class="post-metadata">

**Author:** ![Anthony\_Gerace](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@Anthony\_Gerace](https://community.f5.com/u/Anthony_Gerace)\
**Post date:** [March 17, 2006, 7:31pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/14 "2006-03-17T19:31:11Z")

</div>

This looks really interesting. What versions of LTM is this supported in?

Thanks.

Anthony

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [March 20, 2006, 6:25pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/15 "2006-03-20T18:25:50Z")

</div>

Should be 9.0.2 and after.

-Colin

---

<div class="post-metadata">

**Author:** ![Chris\_Phillips](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Chris\_Phillips](https://community.f5.com/u/Chris_Phillips)\
**Post date:** [March 20, 2006, 6:40pm UTC](https://community.f5.com/t/forward-using-hostname-as-node-not-ip/49531/16 "2006-03-20T18:40:50Z")

</div>

i’m personally testing this under 9.1.1 with sucess so far.
