Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently my Debian-based machine returns whatever name was used to ping it, as it's name when answering to ping:

 - saturn:~$ ifconfig | grep "inet addr"
          inet addr:  Bcast:  Mask:
          inet addr:  Mask:
 - saturn:~$ ping -c 1 | grep from
64 bytes from icmp_req=1 ttl=64 time=0.094 ms
 - saturn:~$ ping -c 1 localhost | grep from
64 bytes from localhost ( icmp_req=1 ttl=64 time=0.081 ms
 - saturn:~$ ping -c 1 saturn | grep from
64 bytes from saturn ( icmp_req=1 ttl=64 time=0.079 ms
 - saturn:~$

I would like to to always return "saturn". There is no DNS, this is on a local LAN with DHCP. I have read a question regarding DNS but here there is no PTR record to configure. How can I have all pings return the name "saturn"?


share|improve this question
Could you please tell us what your final purpose is? – quanta Aug 3 '12 at 9:43
My final purpose is to know which machines I am communicating with if I address them by IP. If I want to know which machine is answering to it would be nice if the ping returned "jupiter". Yes, there are eight machines! – dotancohen Aug 3 '12 at 10:16
Downvoters, please point out what is wrong with this question so that I might improve it. If you downvoted please leave a comment as to why. Thanks. – dotancohen Aug 3 '12 at 10:17
Setup a local DNS using dnsmasq maybe is what you're looking for. – quanta Aug 3 '12 at 10:22
up vote 1 down vote accepted

Do you have a valid reason to want this? This would be non-standard behaviour.

Ping (and other tools) looks up what the IP resolves to according to /etc/nsswitch.conf. That's usually set to "files dns" for "hosts", meaning it will first look at /etc/hosts and then use DNS if that doesn't contain any useful info.

share|improve this answer
Thank you, I did not realise that this is nonstandard. Tell me, then, what determines what address is seen when pinging? For instance, when pinging I see Is there no way to configure that on a LAN with no DNS? – dotancohen Aug 3 '12 at 10:23
Well, without DNS, every machine would have to have some other way to resolve IPs to names. Most likely: /etc/hosts (*nix) or %windir%\system32\drivers\etc\hosts (Windows). As to your example: try host and then host (that's the output from the first execution of host). This should be enlightening? :) – Gnarfoz Aug 3 '12 at 10:47
I see. So when we ping, the information is provided by DNS, and not by the server answering the ping? And if there is no DNS, then that information is provided by the local Hosts file? – dotancohen Aug 4 '12 at 7:48
Quite so, yes. :-) – Gnarfoz Aug 6 '12 at 8:04
Thanks, Gnarfoz. – dotancohen Aug 6 '12 at 9:38

For the local machine to return saturn, put this in /etc/hosts:       saturn localhost       saturn localhost   saturn


To use mDNS in linux, you need the avahi-daemon... I run this at home... this is what happens when I login to my debian server from my wife's ubuntu laptop which is also running avahi-daemon..

[mpenning@tsunami ~]$ who
mpenning pts/0        2012-08-03 05:23 (jennykan-thinkpad-t61.local) <<<
mpenning pts/1        2012-08-02 01:16 (mpenning-vista.local)
[mpenning@tsunami ~]# ping jennykan-thinkpad-t61.local
PING jennykan-thinkpad-t61.local ( 56(84) bytes of data.
64 bytes from jennykan-ThinkPad-T61.local ( icmp_req=1 ttl=64 time=0.892 ms
64 bytes from jennykan-ThinkPad-T61.local ( icmp_req=2 ttl=64 time=1.06 ms
--- jennykan-thinkpad-t61.local ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.892/0.979/1.067/0.092 ms
[mpenning@tsunami ~]$

This also assumes your network will pass multicast correctly... if you have a single Vlan, it shouldn't be a problem.

share|improve this answer
Localhost should probably not resolve to an IP not on the loopback interface. (The loopback one should match first, of course, but then, even putting it on the 192.* line would be pointless.) – Gnarfoz Aug 3 '12 at 9:43
fair point... thank you – Mike Pennington Aug 3 '12 at 9:44
Thank you. My point isn't that when pinging oneself he should get "saturn" but rather that when another machine on the LAN pings he should see "saturn". – dotancohen Aug 3 '12 at 10:20
Please see my edit – Mike Pennington Aug 3 '12 at 10:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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