How do I ping localhost using IPv6?
Solution 1
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)
Solution 2
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
.)
Solution 3
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
Related videos on Youtube
nafas
Updated on September 18, 2022Comments
-
nafas over 1 year
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 makeping6 localhost
work (if possible at all)?-
user1686 over 8 yearsIf you're on Linux, you should generally avoid
ifconfig
androute
– preferip addr
andip route
, which support more networking features and have a more consistent output. -
nafas over 8 years@grawity thx for the tip mate, very useful
-
-
user1686 over 8 yearsA hostname can resolve to multiple addresses at once – especially if they're from different protocols. Most systems alias
localhost
to both127.0.0.1
and::1
. -
Lekensteyn over 8 yearsNewer versions of
iputils
have no separateping6
utility, it got merged withping
. For those versions, useping -6 ::1
or (since::1
is not an IPv4 address)ping ::1
. -
edmz over 8 years@Lekensteyn Which? Latest version,
-6
is not even recognized. -
kasperd over 8 years@grawity None of the systems I checked use
localhost
for IPv6. The names I found used for::1
wereip6-localhost
,ip6-loopback
,localhost6
, andlocalhost6.localdomain6
. -
Mark over 8 years@kasperd, from a Gentoo
/etc/hosts
:127.0.0.1 localhost
,::1 localhost
; Windows Vista is identical (except for putting the file inC:\Windows\System32\drivers\etc
). MacOSX 10.9.5 addsfe80::1%lo0 localhost
as a third name for it. -
user1686 over 8 years@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 over 8 years@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.) -
kasperd over 8 years@grawity That's not correct. In
/etc/hosts
on Ubuntu I find this:::1 ip6-localhost ip6-loopback
-
user1686 over 8 years@kasperd: Really.
-
kasperd over 8 years@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
. -
edmz over 8 years@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).
-
user1686 over 8 years@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.
-
edmz over 8 years@grawity It is indeed the latest you can get from [core] (because it's OOD), but the actual latest version is only in [testing].
-
nafas over 8 yearsvery 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...
-
Hastur over 8 yearsAs 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! ;) -
qasdfdsaq over 8 yearsCentOS 6 has ::1 as localhost6, though CentOS 7 has localhost for both. OpenWRT, Xenserver, and Solaris lack any IPv6 entries at all.
-
nafas over 8 years,I totally get it mate.
::1
is the ip(v6), where aslocalhost
is thehostname
. 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 ofgoogle.com
-
Hastur over 8 yearsIt 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.
-
kasperd over 8 yearsNewest Ubuntu LTS has iputils-s20121221, which does not support
ping -6
. -
Matt Nordhoff over 8 years@nafas They have added IPv6 to
google.com
. -
Lekensteyn over 8 years@black This was iputils 20150815.1c59920-3 on Arch Linux
-
kasperd over 5 years@nafas
google.com
has had an IPv6 address since 2012-06-06.