Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to find dns name or server name

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uname -n?
Otherwise 'uname -n|sed -e "s/\..*//g"'
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 www2.mousetech.com is also ftp.mousetech.com and once was cvs.mousetech.com as well.

Most commonly for remote users, reverse DNS lookup is used. That is, if you do a DNS lookup on, say, 192.168.100.7, a properly configured DNS system will return the preferred DNS name for the machine with that IP address.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 www.google.com, 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic