ip address - Why can I ping 127.1?

07
2014-07
  • Alexandre de Verteuil

    I know IPv6 allows consecutive zeros to be omitted. But how about IPv4? I haven't found any reference to this on the Internet, including Wikipedia and RFC 791 – Internet Protocol. This document suggests that "Leading zeros can be omitted" in an IPv4 address (search for the term 'omitted'). Not specific enough.

    Check out this shell session:

    [~]$ ping -c 1 127.1
    PING 127.1 (127.0.0.1) 56(84) bytes of data.
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.040 ms
    
    --- 127.1 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.040/0.040/0.040/0.000 ms
    [~]$ ping -c 1 127.0.1
    PING 127.0.1 (127.0.0.1) 56(84) bytes of data.
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.044 ms
    
    --- 127.0.1 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.044/0.044/0.044/0.000 ms
    [~]$ ssh 127.1 :
    The authenticity of host '127.1 (127.0.0.1)' can't be established.
    ECDSA key fingerprint is 04:48:fa:f2:ef:95:7c:35:46:39:2e:d3:89:dd:cd:87.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '127.1' (ECDSA) to the list of known hosts.
    [email protected]'s password: 
    

    Clearly, both ping and ssh understand 127.1 and 127.0.1 to be the same as 127.0.0.1. Where is this specified?

  • Answers
  • nerdwaller

    There's a Stack Overflow post from about a year ago asking something similar (this post).

    The main reason is how inet_aton() (man page) converts the octets into the binary address.

    a.b.c.d

    Each of the four numeric parts specifies a byte of the address; the bytes are assigned in left-to-right order to produce the binary address.

    a.b.c

    Parts a and b specify the first two bytes of the binary address. Part c is interpreted as a 16-bit value that defines the rightmost two bytes of the binary address. This notation is suitable for specifying (outmoded) Class B network addresses.

    a.b

    Part a specifies the first byte of the binary address. Part b is interpreted as a 24-bit value that defines the rightmost three bytes of the binary address. This notation is suitable for specifying (outmoded) Class C network addresses.

    a

    The value a is interpreted as a 32-bit value that is stored directly into the binary address without any byte rearrangement.

    This isn't defined by POSIX.anything - but it is available pretty widely.

  • David Schwartz

    It's a relic from the old days of classful addressing. 127.1 means network 127, host 1. (And, yes, 127.257 is legal because network 127 can have more than 256 hosts.


  • Related Question

    Ping [computer] get strange IP address
  • wbeard52

    On my local network, I have multiple computers that I connect to. I don't typically remember the IP address nor do I care. This morning, I went to RDP put "Sam" in the field and pressed enter. It wouldn't connect so I opened up a command prompt to see if I could ping her computer and got something I have never seen before.

    C:\Documents and Settings\wbeard52>ping sam  
    Pinging sam.WORKGROUP [67.215.65.132] with 32 bytes of data:  
    Reply from 67.215.65.132: bytes=32 time=51ms TTL=56
    

    Obviously, I have a computer named "sam" on the local network and I cam RDP into her computer with her IP address (not the one listed here). I don't have anything in the routing table that I can see.

    wbeard52>route print
    ===========================================================================  
    Interface List  
    0x1 ........................... MS TCP Loopback interface  
    0x2 ...00 0e 35 a5 6f b2 ...... Intel(R) PRO/Wireless 2200BG Network Connection  
    - Packet Scheduler Miniport  
    ===========================================================================  
    ===========================================================================  
    Active Routes:  
    Network Destination        Netmask          Gateway       Interface  Metric  
              0.0.0.0          0.0.0.0   192.168.52.208  192.168.52.152       10  
            127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1  
         192.168.52.0    255.255.255.0   192.168.52.152  192.168.52.152       10  
       192.168.52.152  255.255.255.255        127.0.0.1       127.0.0.1       10  
       192.168.52.255  255.255.255.255   192.168.52.152  192.168.52.152       10  
            224.0.0.0        240.0.0.0   192.168.52.152  192.168.52.152       10  
      255.255.255.255  255.255.255.255   192.168.52.152  192.168.52.152       1  
    Default Gateway:    192.168.52.1  
    ===========================================================================  
    Persistent Routes:  
      None  
    

    What would be causing the ping to be sent to an IP address in San Francisco?


  • Related Answers
  • BillP3rd

    I'm pretty sure that @hyperslug has hit it on the head. When using OpenDNS as your DNS provider, if you try to resolve an unknown name, they'll return an IP address that "redirects" your browser to their branded "results" page. You'll never see a "404" page when using OpenDNS.

    If you were to use your ISPs DNS servers and you tried to PING sam, you'd get:

    C:\>ping sam
    Ping request could not find host sam. Please check the name and try again.
    

    To fix this (assuming that you want to resolve sam by name and not have to type in an IP address), you'll need to place an entry in your HOSTS file for 'sam'.

    From your routing table, I can see that you are on network 192.168.52.x, and that your computer is 192.168.52.152. I can also see that your default gateway is 192.168.52.1. You haven't mentioned what the IP address of sam is. For the purposes of this exercise, we'll assume that sam is 192.168.52.201.

    I'm assuming that your environment is Windows for what follows. You'll want to edit the file %windir%\system32\drivers\etc\hosts. If you've never used the hosts file, you'll probably first have to rename %windir%\system32\drivers\etc\hosts.sam to %windir%\system32\drivers\etc\hosts.

    Open the file in your favorite text editor (such as Notepad) and you'll see something very similar to:

    # Copyright (c) 1993-1999 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host
    
    127.0.0.1       localhost
    

    At the end of the hosts file, add a line:

    192.168.52.201  sam
    

    Save the file and you're done.

  • sabre23t

    What's the setting for your WINS server? An "IPCONFIG /ALL" command should show your Windows WINS settings. I understand "ping sam" would trigger your WINS server rather than your DNS server.

  • Kurt Pfeifle

    pathping 67.215.65.132 and pathping sam can help you identify which network route the packets take.

    nslookup sam will determine which DNS server is pointing you to that IP adress.

    nslookup 67.215.65.132 checks the reverse way of DNS lookup (check if it matches!).

    nslookup <DNS-server-ip-addres> and nslookup <DNS-server-name> checks the supposed DNS server. Does it belong to OpenDN?

    nbtstat -n shows local NetBIOS names.

    nbtstat -r shows names resolved by broadcast and/or WINS.

    nbtstat -S and nbtstat -s show session tables (with target IP adresses or names).

    nbtstat -RR refreshes your WINS by first releasing names.