22

I'm trying to understand IPv6 better.

Firstly, I try ifconfig, and I get the following:

eth0      Link encap:Ethernet  HWaddr XXXXXXX
          inet addr:X.X.X.X  Bcast:X.X.X.X  Mask:XXXXXXXXX
          inet6 addr: XXXX::XXXX:XXX:XXXX:XXX/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:138752772 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67894054 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:67347428211 (67.3 GB)  TX bytes:168368922639 (168.3 GB)
          Interrupt:43

So from the above I can assume IPv6 is enabled (correct me if I'm wrong here).

Now if I use ping localhost I get:

64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.019 ms
64 bytes from localhost (127.0.0.1): icmp_req=3 ttl=64 time=0.025 ms
...

But when I use ping6 localhost I get:

unknown host

How do I use ping6? Or more specifically, what changes needs to be done to make ping6 localhost work (if possible at all)?

  • 3
    If you're on Linux, you should generally avoid ifconfig and route – prefer ip addr and ip route, which support more networking features and have a more consistent output. – user1686 Nov 25 '15 at 14:41
  • @grawity thx for the tip mate, very useful – nafas Nov 26 '15 at 11:10
16

Short answer [rcf4291]

ping6 ip6-localhost    # Or the alias you have in /etc/hosts file (See below)
ping6 0:0:0:0:0:0:0:1  # Similar to `ping 127.0.0.1` with 7 `:` instead of 4 `.`
ping6 ::1              # The used analogous of `ping 127.0.0.1`

Changes to make working ping6 localhost

If you want to set localhost as alias for both ping and ping6 and it is not already so on your machine, it is enough to write in /etc/hosts file both the lines:

127.0.0.1       localhost
# ... and below
::1             localhost ipv6-localhost ipv6-loopback

For what it concerns the alias currently used on your system you can check your hosts file, /etc/hosts [1] or in a different place if on a different system [2] .
You may find ip6-localhost,ip6-loopback,ipv6-localhost,ipv6-loopback or localhost itself...


Some words more

I understand your confusion indeed for what I read from the rfc6761 about "Special-Use Domain Names" 6.3 [3], about the name localhost,

Users may assume that IPv4 and IPv6 address queries for localhost names will always resolve to the respective IP loopback address.

so it should be expected as default but:

  • On the current updated and untouched Ubuntu 14.04.3 LTS /etc/hosts I found the following section with ip6-localhost, ip6-loopback

    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    
  • On a Suse Enterprise 10 system I found localhost, ipv6-localhost,ipv6-loopback

    # special IPv6 addresses
    ::1             localhost ipv6-localhost ipv6-loopback
    
  • On an old Debian GNU/Linux 8.2 system localhost, ip6-localhost, ip6-loopback

    # The following lines are desirable for IPv6 capable hosts
    ::1     localhost ip6-localhost ip6-loopback
    

That means that, in my limited experience, you should look in your /etc/host file and modify it or use what will you find doing, for example,

ping6 ipv6-localhost   # On some systems (maybe on Suse) 
ping6 ip6-localhost    # On some systems (maybe on Debian/*buntu)
| improve this answer | |
  • very detailed answer thanks, what worries me atm, we will be required to use ipv6 very soon and yet, there are so much obstacle ( it couldn't get any simpler than localhost really) and there is no standarizations. I guess we won't do anything about it until, it causes soo much troubles... – nafas Nov 26 '15 at 13:05
  • As you have seen ::1 works on each of those machines... "The nice thing about standards is that you have so many to choose from." A.S.Tanenbaum [ 1] :-) A solution will be found... maybe the wrong one! ;) – Hastur Nov 26 '15 at 13:23
  • ,I totally get it mate. ::1 is the ip(v6), where as localhost is the hostname. entirely my opinion but I believe if we don't keep the standard as are, we'll face many issues in near future. I really hope that once ipv6 overtakes we don't have to type e.g. ipv6.google.com instead of google.com – nafas Nov 26 '15 at 13:31
  • 1
    It was clear that you get it :-) ... BTW RFC 6761 (Special-Use Domain Names) achieved the Proposed Standard maturity level in February, 2013.... so there is still time to hope to see it as standard before it will be too late. – Hastur Nov 26 '15 at 13:48
  • 1
    @nafas They have added IPv6 to google.com. – Matt Nordhoff Nov 27 '15 at 9:20
24

Try:

ping6 ::1

The result would look like:

# ping6 ::1
PING ::1(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.040 ms
(...)
64 bytes from ::1: icmp_seq=9 ttl=64 time=0.037 ms
^C
--- ::1 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 7998ms
rtt min/avg/max/mdev = 0.035/0.042/0.055/0.011 ms

Ubuntu 14.04.1 LTS (Trusty Tahr):

# ping ::1
ping: unknown host ::1
# ping -6 ::1
ping: invalid option -- '6'
Usage: ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
        [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
        [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
        [-w deadline] [-W timeout] [hop1 ...] destination
# ping -V
ping utility, iputils-s20121221

(The same for ping6 -V.)

| improve this answer | |
  • 6
    Newer versions of iputils have no separate ping6 utility, it got merged with ping. For those versions, use ping -6 ::1 or (since ::1 is not an IPv4 address) ping ::1. – Lekensteyn Nov 25 '15 at 15:58
  • 1
    @Lekensteyn Which? Latest version, -6 is not even recognized. – edmz Nov 25 '15 at 17:05
  • @black: Which version do you consider "latest"? ping and ping6 were merged in iputils-s20150815 (check ping -V). Your distro might not have upgraded yet. (And BSDs have their own software and don't use iputils.) – user1686 Nov 26 '15 at 5:46
  • @grawity: I do have the latest version, though it's not the actual latest version and it's indeed OOD, even on Arch Linux (20140519). – edmz Nov 26 '15 at 11:48
  • @black: "Latest but not the actual latest"?... Anyway, Arch has had iputils-20150815 in [testing] for over a month, although I've no idea when it's going to be moved to stable. – user1686 Nov 26 '15 at 11:55
9

localhost is the hostname that resolves to the 127.0.0.1 address. Your /etc/hosts file should have a separate entry for ::1, likely localhost6. So try these:

ping6 ::1
ping6 localhost6
| improve this answer | |
  • 7
    A hostname can resolve to multiple addresses at once – especially if they're from different protocols. Most systems alias localhost to both 127.0.0.1 and ::1. – user1686 Nov 25 '15 at 14:40
  • 1
    @grawity None of the systems I checked use localhost for IPv6. The names I found used for ::1 were ip6-localhost, ip6-loopback, localhost6, and localhost6.localdomain6. – kasperd Nov 25 '15 at 21:43
  • 3
    @kasperd, from a Gentoo /etc/hosts: 127.0.0.1 localhost, ::1 localhost; Windows Vista is identical (except for putting the file in C:\Windows\System32\drivers\etc). MacOSX 10.9.5 adds fe80::1%lo0 localhost as a third name for it. – Mark Nov 25 '15 at 21:59
  • 3
    @kasperd: You haven't used many systems then. Windows, Arch, CentOS, Ubuntu all map localhost to ::1. (I think this is going to be even more common as distros adopt systemd and enable nss_myhostname.) – user1686 Nov 26 '15 at 5:45
  • 2
    CentOS 6 has ::1 as localhost6, though CentOS 7 has localhost for both. OpenWRT, Xenserver, and Solaris lack any IPv6 entries at all. – qasdfdsaq Nov 26 '15 at 13:25

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.