Forum OpenACS Q&A: script to modify the hostname and address in nsd.tcl

I am using OpenAcs on a system with Dynamic ip address. This isn't a big problem as I only use OpenAcs for learning (at the moment).
I wonder whether there is a way to automate a little routine I am doing before working with OpenACS.
I do an ifconfig to find out my ip address, and then nslookup [ip address] to get the hostname. Then I modify the set hostname and set address entries in my nsd.tcl so they point to (in my case) host[some ip-address] and [some ip-address] respectively.
Is it possible to include the automation of above into the nsd.tcl script ? ...and how?


Paul - without actually answering your question, let me recommend  For $30 (ONCE, not per year) they'll do DNS for a dynamic IP.  I do this with a server connected via ISDN line, with updates by ddclient.  It works great.  (Or anyway, it works as well as using an ISDN line could be expected to work.  The site is down a few minutes per week as my router redials and DNS propagates.)

Actually, you can do the same thing for FREE (since you're just learning) with an address like hostname.xxxxx.dom (where xxxxx.dom is one of several choices).  I tried a different dynamic DNS service before ( but wasn't happy with them. is great, and the price is right.

AOLserver doesn't really need to know what its IP address, and in your scenario, you'd need to restart AOLserver (I think) every time your IP changed.  I think it'll be much easier telling AOLserver ONE name and sticking with it.

Hope that helps!

p.s. If you'd like to see sites running on a dynamic IP -,, and are all sharing one dynamic IP.


You can have this in your nsd.tcl (I think this is how the sample nsd.tcl on the openacs documentation does it actually):

set hostname              [ns_info hostname]
set address                [ns_info address]

Then use the $hostname and $address Tcl variables everywhere they are needed. Notice that you'll have to restart aolserver for new addresses to work.

However, you could have AOLserver always listening on localhost/ and your dynamic IP wouldn't matter.

Roberto, those are indeed the default settings ([ns_info hostname] and [ns_info address]). But for some reason they don't seem to work on my machine. I have to specify a valid ip address and a valid hostname in the nsd.tcl file. Is ns_info looking into the etc/hosts file to extract the information?... or where?
This is not really something that stops me using OpenACS, is just that I am really keen to know more about what's happening behind the scenes.
Ah, I'm not sure why you would want to use [ns_info address] in your nsd.tcl config file. I admit I haven't tried doing it that way myself, but nsd.tcl is where ns_info gets its configuration information, so I don't see the sense of using that command there. If it does work at all, I'd suspect that must mean you're essentially telling AOLserver to use some sort of default value for the IP address and port to bind to. And hopefully AOLserver gets that default IP address by asking the OS what the IP address is for the eth0 interface or something like that. But I've never tried it or looked at the code to see what it actually does.

I've always simply directly specified the IP address info in my nsd.tcl, something like this:

set  ip_address(dev)  {}
set        port(dev)  9876

ns_section ns/server/$server_name($which)/module/nssock

  ns_param timeout   120
  ns_param Address   $ip_address($which)
  ns_param Hostname  $hostname($which)
  ns_param Port      $port($which)
I haven't looked at the AOLserver code either, but AFAIK it's smart enough to know it's initializing, and hence shouldn't look at its own config values.

On the machines where I have AOLserver and use the [ns_info] shortcuts, it works just fine. They bind to the correct address in eth0, and correct hostname. I'm using AOLserver 3.3ad13.

it could be that I have an usb modem rather than an ethernet one?... anyway... I know I still have a great deal more to learn... 😉
Does ns_info pull configuration information from the command line?

You can bind to the address (all local addresses) if this is the only AOLserver running or it has a unique port.  There shouldn't be any need to change your config file in this case.

Thanks Stephen,

ns_info at the command line only gives ns_info: command not found.
(aolserver is of course running)

I am really curious now how can I find out what ns_info hostname and ns_info address is actually returning. As I mentioned above is doesn't work issusing the command from the console.
Cathy's advice works a treat. I am just keeping my fingers crossed that the registrar transfer I have initiated now will work ok.
If you just want to see what's actually returned from "ns_info", and aolserver is running you can write a little test.tcl script:
ns_return 200 text/plain "hostname: [ns_info hostname]

address: [ns_info address]"
Put it under the page root and visit ...
Does that help?
Thanks Ola, that was great.
Here is the code I use to retrieve the IP address of eth0 in nsd.tcl

set my_ip [exec "/sbin/ifconfig" "eth0" "|" "grep" "inet addr" "|" "awk" "{print $2}" "|" "sed" "-e" "s/.*://"] is probably a better choice for a dynamic IP so you don't have to restart aolserver when your IP changes. (I think that is how it works anyways)

I recommend setting ForceHostP to 0 in parameters/.tcl if you have a dynamic IP so the hostname setting won't affect you.