How do I ping localhost using IPv6?

22

7

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)?

nafas

Posted 2015-11-25T14:09:04.060

Reputation: 409

3If 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 – 2015-11-25T14:41:57.763

@grawity thx for the tip mate, very useful – nafas – 2015-11-26T11:10:55.743

Answers

15

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)

Hastur

Posted 2015-11-25T14:09:04.060

Reputation: 15 043

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 – 2015-11-26T13:05:48.737

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 – 2015-11-26T13:23:30.490

,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 – 2015-11-26T13:31:28.190

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 – 2015-11-26T13:48:14.527

1@nafas They have added IPv6 to google.com. – Matt Nordhoff – 2015-11-27T09:20:42.243

@nafas google.com has had an IPv6 address since 2012-06-06. – kasperd – 2018-11-17T23:15:34.833

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.)

Archemar

Posted 2015-11-25T14:09:04.060

Reputation: 1 547

6Newer 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 – 2015-11-25T15:58:17.463

1@Lekensteyn Which? Latest version, -6 is not even recognized. – edmz – 2015-11-25T17:05:22.570

@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 – 2015-11-26T05:46:21.203

@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 – 2015-11-26T11:48:39.403

@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 – 2015-11-26T11:55:01.403

@grawity It is indeed the latest you can get from [core] (because it's OOD), but the actual latest version is only in [testing]. – edmz – 2015-11-26T12:37:28.083

Newest Ubuntu LTS has iputils-s20121221, which does not support ping -6. – kasperd – 2015-11-26T16:44:49.723

@black This was iputils 20150815.1c59920-3 on Arch Linux – Lekensteyn – 2015-11-27T22:55:47.387

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

gogators

Posted 2015-11-25T14:09:04.060

Reputation: 1 183

7A 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 – 2015-11-25T14:40:43.493

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 – 2015-11-25T21:43:23.883

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 – 2015-11-25T21:59:15.893

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 – 2015-11-26T05:45:22.787

@grawity That's not correct. In /etc/hosts on Ubuntu I find this: ::1 ip6-localhost ip6-loopback – kasperd – 2015-11-26T07:16:14.737

@kasperd: Really.

– user1686 – 2015-11-26T07:48:55.270

@grawity That information is outdated. I found some older media with Ubuntu 9.10 and 10.04. Those versions have ::1 localhost ip6-localhost ip6-loopback, but on 12.04 and 14.04 it says ::1 ip6-localhost ip6-loopback. – kasperd – 2015-11-26T09:02:48.440

2CentOS 6 has ::1 as localhost6, though CentOS 7 has localhost for both. OpenWRT, Xenserver, and Solaris lack any IPv6 entries at all. – qasdfdsaq – 2015-11-26T13:25:13.063