如何使用 IPv6 ping 本地主机?

如何使用 IPv6 ping 本地主机?

我试图理解IPv6更好的。

首先,我尝试是否配置,我得到以下结果:

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

因此,从上面我可以假设 IPv6 已启用(如果我错了,请纠正我)。

现在如果我使用,ping localhost我会得到:

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

但是当我使用时ping6 localhost我得到:

unknown host

我如何使用ping6?或者更具体地说,需要做哪些改变才能工作ping6 localhost(如果可能的话)?

答案1

简短回答[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`

改变工作方式ping6 localhost

如果你想要localhost同时设置为ping和的别名ping6而且您的机器上还没有这样,只需在/etc/hosts文件中写入以下两行即可:

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

对于当前使用的别名您可以在系统上检查 hosts 文件,/etc/hosts [1] 或以其他方式地方如果在不同的系统上[2] .
您可能会发现,,,ip6-localhost或者其本身...ip6-loopbackipv6-localhostipv6-loopbacklocalhost


多说几句

我确实理解你的困惑,因为我读到rfc6761关于“特殊用途域名”6.3 [3],关于名字本地主机

用户可能会认为 IPv4 和 IPv6 地址查询本地主机名将始终解析为相应的 IP 环回地址

所以它应该是默认的 但:

  • 在当前更新和未受影响的Ubuntu 14.04.3 LTS /etc/hosts我找到了以下部分ip6-localhostip6-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
    
  • Suse Enterprise 10我发现的系统localhost,,ipv6-localhostipv6-loopback

     # special IPv6 addresses
     ::1             localhost ipv6-localhost ipv6-loopback
    
  • 在一个古老的 Debian GNU/Linux 8.2 系统localhostip6-localhostip6-loopback

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

这意味着,根据我有限的经验,您应该查看文件/etc/host并进行修改,或者使用您发现的方法,例如,

ping6 ipv6-localhost   # On some systems (maybe on Suse) 
ping6 ip6-localhost    # On some systems (maybe on Debian/*buntu)

答案2

尝试:

ping6 ::1

结果如下:

# 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

( 也一样ping6 -V。)

答案3

localhost是解析为地址的主机名127.0.0.1。您的/etc/hosts文件应该有一个单独的条目::1,可能是localhost6。所以试试这些:

ping6 ::1
ping6 localhost6

相关内容