1834752 Members
3044 Online
110070 Solutions
New Discussion

Command To Return Alias

 
Mike_21
Frequent Advisor

Command To Return Alias

Is there a simple command to return just the alias of a machine?

Trying DNS
Name: mike.bla.com
Address: 1.2.3.4
Aliases: dogs.bla.com

In the above example, I would like to return just "dogs".

Thanks
5 REPLIES 5
Stefan Farrelly
Honored Contributor

Re: Command To Return Alias


I dont think there is an option to nslookup to do what you want.

You'll have to do something more complex;

nslookup | grep Alias | awk '{print $2}'

Im from Palmerston North, New Zealand, but somehow ended up in London...
Klaus Crusius
Trusted Contributor

Re: Command To Return Alias


try the command:

# nslookup mike |
awk '$1 == "Aliases:" { print $2 }'
There is a live before death!
Volker Borowski
Honored Contributor

Re: Command To Return Alias

I guess, you might need to write a program.

gethostent

would be the systemcall of you choice.
Basic problem is, that there might be more than one alias, and which one would you focus on.

man gethostent

shows the datastructures for this. The only thing you need to decide is how to process the char-array of the alias entries -> may be "return all up to the first dot in the first alias" or so.

This should fit onto one screen page.

Hope this helps
Volker
harry d brown jr
Honored Contributor

Re: Command To Return Alias

Well, "dogs" is not an alias for dogs.bla.com, but dogs.bla.com is an alias for mike.bla.com. If you want to strip the domain name from the alias name, then do this:

nslookup | cut -d"." -f1
Live Free or Die
Wodisch
Honored Contributor

Re: Command To Return Alias

Hello Mike,

"dogs" alone may not work (depending on the contents of your "/etc/resolv.conf"), so you will have to show the FQDN, not just the "shortname"...
Have you tried some newer commands instead of "nslookup", like they are used for BIND9?
Have a look at the BIND9 documentation and have a look at the home-page of "Men&Mice", as they do a lot of work (and docu) on and about DNS and see especially Cricket Liu's corner (the one who did the O'Reilly book!):
http://www.menandmice.com/9000/9300_DNS_Corner.html

HTH,
Wodisch