[sf-perl] Re: hostname "unknown"
David Alban
extasia at gmail.com
Sun Mar 13 15:06:28 PST 2005
Greetings,
I find myself in the position of having written a tool or two to be
run both on machines getting their IP info using dhcp and machines not
doing so. The machines in question happen to be running solaris. I
get the following for hostname on the dhcp clients:
Sys::Hostname::hostname(): unknown
Net::Domain::hostfqdn(): unknown.my.domain
Net::Domain::hostname(): unknown
"unknown" is unacceptable because if more than one machine "uses" it,
we don't have unique hostfqdn's. One solution is to use a machine's
hostid as its hostname.
Another option, which is what I did, also used hostid. Say my current
host, a dhcp client, has hostid "8012abcd". I check for the existence
of $ENV{ _0812abcd }. If defined, I use its value as hostname. If it
isn't defined, or if I can't determine the hostid of the current host,
the hostname remains "unknown".
Heh heh. As soon as I write this, I realize that what I *should* have
done is: if I can get a hostid but the appropriate $ENV{ _nnnnnnnn }
variable isn't set, I should have used the hostid as the hostname.
And if I couldn't get a hostid, I should have (it would be O.K. for my
application) had the the tool die. Hmmm... Maybe I'll fix it.
The reason I look for a $ENV{ _nnnnnnnn } environment variable is that
some of the hosts running dhcp clients have informal hostnames. For
instance, we might think of a host as "foobarbat" even though it's
hostname() returns "unknown". If $_nnnnnnnn is set to "foobarbat" in
the environment, then my tool can report foobarbat as the host's
hostname.
I don't mean to present my solution as good, bad, or ugly, but for the
sake of discussion, I thought it might be interesting to see if others
had been in the situation where they didn't want to use "unknown" as a
hostname for dhcp clients, and to see what they did.
Thanks,
David
--
Live in a world of your own, but always welcome visitors.
More information about the SanFrancisco-pm
mailing list