File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes how to find dns name or server name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to find dns name or server name" Watch "how to find dns name or server name" New topic

how to find dns name or server name

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I am trying to get the dns name of a linux sever. I tried with which prints as below:

I can use perl regexx to get the server name/dns name from the above command. Is there any other easy way to grab the dns name? Thanks.
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
uname -n?
Otherwise 'uname -n|sed -e "s/\..*//g"'

SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

"hostname" is what's usually used, but that isn't necessarily "the" DNS name or even "a" DNS name, since the hostname is often set from a config file before network services boot up.

I put "the" in quotes, since a server can and often does have multiple DNS names. For example is also and once was as well.

Most commonly for remote users, reverse DNS lookup is used. That is, if you do a DNS lookup on, say,, a properly configured DNS system will return the preferred DNS name for the machine with that IP address.

An IDE is no substitute for an Intelligent Developer.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks for the suggestions.
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

Tim's right, a reverse DNS may get you the DNS binding, but not always.
For example, big sites often have something like a BigIP or ServIron that does load balancing. So there are lots of computers that DNS claims are, but its unlikely that any computer really has that as its name.

Why do you want this? In most production environments, the DNS naming is completely independent of the box, the box's internal names, etc. And of course, NAT makes IP address of questionable value as well
I agree. Here's the link:
subject: how to find dns name or server name
It's not a secret anymore!