Pinging an IP address responds with different IP
When I try to ping the IP address 10.10.208.57
I have no response since nothing exist in the network with that IP address.
However if I try to ping 10.10.208.
057
instead another IP address responds:
root@everest:/root# ping 10.10.208.057
PING 10.10.208.057 (10.10.208.47) 56(84) bytes of data.
64 bytes from 10.10.208.47: icmp_seq=1 ttl=253 time=0.732 ms
64 bytes from 10.10.208.47: icmp_seq=2 ttl=253 time=0.695 ms
64 bytes from 10.10.208.47: icmp_seq=3 ttl=253 time=0.659 ms
64 bytes from 10.10.208.47: icmp_seq=4 ttl=253 time=0.705 ms
Considering that 10.10.208.47
is a Lexmark E120n printer what could be the origin of this strange problem?
That behavior is actually due to a normal feature of ping and has no relation to your actual hardware.
Indeed, prefixing the IP address (or part of it) with a leading zero will cause the number to be interpreted as octal.
So 057
means 57
in base 8 which is 47. Thus ping will send the ICMP query to the machine located at address 10.10.208.47
and therefore get an answer from it.
Note that you can also ping adresses in hexadecimal, by using the 0x prefix instead of just 0.
Edit : As many comments suggest, this feature is actually not specific to ping
and can be found in many CLI softwares manipulating IP addresses.
Ping, like many other unix programs, use the C libraries on your unix system for name resolution. One of the functions used is inet_aton
.
The man page for inet_aton
says:
All numbers supplied as ``parts'' in a `.' notation may be decimal, octal, or hexadecimal, as specified in the C language (i.e., a leading 0x or 0X implies hexadecimal; otherwise, a leading 0 implies octal; otherwise, the number is interpreted as decimal).
So when you're using a leading zero, the number is interpreted as a octal. Thus, 57 = 047 = 0x39.