How do I ping localhost using IPv6?
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 withip6-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)
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
.)
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