Considering that I'm in a LAN that assigns IP addresses using DHCP (and that I'm not its administrator), how do I set things up such that when I ping <hostname> (instead of ping <IP address>, I do get something back, without having added the match in "/etc/hostname")? Would I need to do this change in separate places for the web- and for ssh-server?

I'm wondering because I think there was a time when I could do this without any fiddling with "/etc/hosts" (or am I mistaken?). The problem with that file is that I would have to do it on every client that wants to use the name-to-IP mapping, and to have to continually change it if some IP address changes.

The question really is: is there's a tool that can do network discovery of hostnames (matched to their IP addresses of course).

4 Answers 4


Ideally, your sysadmin would have set up the network with a DNS server, and that DNS server would be dynamically updated with host names from DHCP.

You might try to use the ICMP domain name messages to reap them, but I don't think that is widely implemented.

Another, older method is NIS server. But these are not very common any more. You can try ypcat hosts and see if that returns you something.

Another is zeroconf, where hosts that support it broadcast their name and you can run a service that caches them (the Avahi package does this. If you have it set up then a ping <hostname>.local may work for you already. But not every node will support this either. you can also try querying with the avahi tools: avahi-resolve-host-name <hostname>.local and writing a script that updates /etc/hosts for you if the normal resolver doesn't work.

So there is no other "magic" place to get host names from. Somebody is going to have to define that mapping, or make it dynamically discoverable. If your sysadmin did not or will not, then you have to do it. And the only place you can do it for your local machine is the /etc/hosts file. So if none of the above methods work then you're stuck with that. Sorry.


Were you perhaps thinking of zeroconf? Zeroconf is a suite of protocols to establish an IP link between two or more machines and discover services. Unfortunately, there are several name resolution protocols in the zeroconf realm, so its goal of being completely cross-platform is not fully realized. But if all machines run the same operating system, this isn't a problem. The primary target use case of zeroconf is two machines connected by a crossover cable, but it also works on a local switched network.

The most common implementation of zeroconf on Linux is Avahi. On Debian or Ubuntu, installing the avahi-daemon package should be enough to get going. Other packages may be useful as well (in particular avahi-autoipd if you want to negotiate IP addresses in a network that isn't running a DHCP server, avahi-discover to view available services).


A DNS server would help you here. You could set clients to get an IP from DHCP and use dynamic dns to let the clients update the DNS server when they get a new IP.

See the following link for an example with the BIND dns server

  • Doesn't let the clients update the DNS server imply that I have to be network admin?
    – tshepang
    Jul 18, 2011 at 21:07

while not 100% you can try.

ping <hostname>.local

I know this works when seeking OSX or Ubuntu hosts.

  • works not here :(
    – tshepang
    Jul 19, 2011 at 4:32
  • This only works in combination with zeroconf. See answers from Gilles or Keith for full explanations.
    – Caleb
    Jul 19, 2011 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.