0

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:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
 - saturn:~$ ping -c 1 192.168.0.103 | grep from
64 bytes from 192.168.0.103: icmp_req=1 ttl=64 time=0.094 ms
 - saturn:~$ ping -c 1 localhost | grep from
64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.081 ms
 - saturn:~$ ping -c 1 saturn | grep from
64 bytes from saturn (127.0.1.1): 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"?

Thanks.

dotancohen
  • 2,610
  • Could you please tell us what your final purpose is? – quanta Aug 03 '12 at 09: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 192.168.0.105 it would be nice if the ping returned "jupiter". Yes, there are eight machines! – dotancohen Aug 03 '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 03 '12 at 10:17
  • 2
    Setup a local DNS using dnsmasq maybe is what you're looking for. – quanta Aug 03 '12 at 10:22

2 Answers2

2

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

127.0.0.1       saturn localhost
127.0.1.1       saturn localhost
192.168.0.103   saturn

EDIT

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 (172.16.1.74) 56(84) bytes of data.
64 bytes from jennykan-ThinkPad-T61.local (172.16.1.74): icmp_req=1 ttl=64 time=0.892 ms
64 bytes from jennykan-ThinkPad-T61.local (172.16.1.74): icmp_req=2 ttl=64 time=1.06 ms
^C
--- 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.

  • 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 03 '12 at 09:43
  • Thank you. My point isn't that when pinging oneself he should get "saturn" but rather that when another machine on the LAN pings 192.168.0.103 he should see "saturn". – dotancohen Aug 03 '12 at 10:20
  • Please see my edit – Mike Pennington Aug 03 '12 at 10:40
1

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.

Gnarfoz
  • 737
  • 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 doorlinux.com I see shared02.exascale.co.uk. Is there no way to configure that on a LAN with no DNS? – dotancohen Aug 03 '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 doorlinux.com and then host 178.239.170.13 (that's the output from the first execution of host). This should be enlightening? :) – Gnarfoz Aug 03 '12 at 10:47
  • 1
    I see. So when we ping doorlinux.com, the information shared02.exascale.co.uk 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 04 '12 at 07:48
  • Quite so, yes. :-) – Gnarfoz Aug 06 '12 at 08:04