Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-17-2009, 08:31 AM   #1
LQ Newbie
Registered: Apr 2009
Location: Houston, TX
Posts: 26

Rep: Reputation: 0
how to lookup a hostname of a networked computer

is there a command or terminal app that can lookup the hostname of a networked computer? doesn't matter to me if its by mac or ip.
I'm using ubuntu
Old 06-17-2009, 08:50 AM   #2
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,867
Blog Entries: 27

Rep: Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163Reputation: 2163

Welcome to LQ!

You could 'arp';

excerpt from 'man arp';
arp - Linux ARP kernel module.
This kernel protocol module implements the Address Resolution Protocol defined in RFC 826. It is used to convert between Layer2 hardware addresses and IPv4 protocol addresses on directly connected networks. The user normally doesn't interact directly with this module except to configure it; instead it provides a service for other protocols in the kernel.

A user process can receive ARP packets by using packet(7) sockets. There is also a mechanism for managing the ARP cache in user-space by using netlink(7) sockets. The ARP table can also be controlled via ioctl (2) on any PF_INET socket.

The ARP module maintains a cache of mappings between hardware addresses and protocol addresses. The cache has a limited size so old and less frequently used entries are garbage-collected. Entries which are marked as permanent are never deleted by the garbage-collector. The cache can be directly manipulated by the use of ioctls and its behaviour can be tuned by the sysctls defined below.

When there is no positive feedback for an existing mapping after some time (see the sysctls below) a neighbour cache entry is considered stale. Positive feedback can be gotten from a higher layer; for example from a successful TCP ACK. Other protocols can signal forward progress using the MSG_CONFIRM flag to sendmsg(2). When there is no forward progress ARP tries to reprobe. It first tries to ask a local arp daemon app_solicit times for an updated MAC address. If that fails and an old MAC address is known an unicast probe is send ucast_solicit times. If that fails too it will broadcast a new ARP request to the network. Requests are only send when there is data queued for sending.

Linux will automatically add a non-permanent proxy arp entry when it receives a request for an address it forwards to and proxy arp is enabled on the receiving interface. When there is a reject route for the target no proxy arp entry is added.
BTW, 'arp -a' will provide you with information for your LAN in a 'BSD' format.
Old 06-17-2009, 09:11 AM   #3
LQ Newbie
Registered: Apr 2009
Location: Houston, TX
Posts: 26

Original Poster
Rep: Reputation: 0
awesome thanks onebuck that was exactly what I was looking for. I knew about arp command, but never noticed it returned the hostname. I was using nmap -PN | grep -e 'Interesting ports on' | awk '{print $4}' but it was very slow
Old 06-17-2009, 10:02 AM   #4
LQ Newbie
Registered: Apr 2009
Location: Houston, TX
Posts: 26

Original Poster
Rep: Reputation: 0
arp -a only seems to have entries after I scan the ip with nmap, but has nothing before the scan...
Old 06-17-2009, 10:21 AM   #5
LQ Guru
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,239
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
reverse lookup if you have DNS running on your network..

dig -x


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hostname lookup failure chandrait2004 Linux - Newbie 3 06-23-2011 03:23 PM
Lookup hostname from IP address Geneset Linux - Networking 5 08-26-2008 05:03 AM
Odd hostname lookup problem max_sipos Linux - Networking 3 11-15-2004 11:29 AM
Problem with networked printing with CUPS-- hostname showing up where it shouldn't pingswept Linux - General 1 06-29-2004 09:38 PM
Networked computer can't see page served from other Networked computer Travis86 Linux - Networking 2 12-30-2002 01:38 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration