Home -- Michael's Blog :: Just Do IT -- Manuals

24.10. IPv6

原始作者:Aaron Kaplan. 重新组织和增加:Tom Rhodes. 中文翻译: 张 雪平. Extended by Brad Davis.

IPv6(也叫IPng ``IP下一代'')是著名的IP协议(也叫 IPv4)的新版。象其它当前的*BSD系统一样,FreeBSD包括了KAME IPv6相关工具。因此你的FreeBSD系统事带有所有你在体验IPv6时所需要的。这部分主要集中在IPv6的配置和运行上。

在二十世纪90年代早期,人们开始当心迅速缩小的IPv4地址空间。根据互联网的膨胀率,有两点需要考虑:

IPv6解决这些和其它许多的问题:

IPv6还有其它许多有用的功能,如:

要更多信息,请查看:

24.10.1. 关于IPv6地址的背景知识

有几种不同类型的IPv6地址:Unicast,Anycast 和 Multicast。

Unicast地址是为人们所熟知的地址。一个被发送到unicast地址的包实际上会到达属于这个地址的接口。

Anycast地址语义上与unicast地址没有差别,只是它们强调一组接口。指定为anycast地址的包会到达最近的(以路由为单位) 接口。Anycast地址可能只被路由器使用。

Multicast地址标识一组接口。指定为multicast地址的包会到达属于multicast组的所有的接口。

注: IPv4广播地址(通常为xxx.xxx.xxx.255) 由IPv6的multicast地址来表示。

表格 24-2. 保留的IPv6地址

IPv6 地址 预定长度(bits) 描述 备注
:: 128 bits 未指定 类似 IPv4 中的 0.0.0.0
::1 128 bits 环回地址 类似 IPv4 中的 127.0.0.1
::00:xx:xx:xx:xx 96 bits 嵌入的 IPv4 低 32 bits 是 IPv4 地址。这也称作 ``IPv4 兼容 IPv6 地址''
::ff:xx:xx:xx:xx 96 bits IPv4 影射的 IPv6 地址 低的 32 bits 是 IPv4 地址。 用于那些不支持 IPv6 的主机。
fe80:: - feb:: 10 bits 链路环回 类似 IPv4 的环回地址。
fec0:: - fef:: 10 bits 站点环回  
ff:: 8 bits 多播  
001 (base 2) 3 bits 全球多播 所有的全球多播地址都指定到这个地址池中。 前三个二进制位是 ``001''。

24.10.2. IPv6地址的读法

规范形式被描述为:x:x:x:x:x:x:x:x,每一个``x''就是一个16位的16进制值。当然,每个十六进制块以三个``0''开始头的也可以省略。如FEBC:A574:382B:23C1:AA49:4592:4EFE:9982

通常一个地址会有很长的子串全部为零,因此每个地址的这种子串常被简写为``::''。例如:fe80::1对应的规范形式是fe80:0000:0000:0000:0000:0000:0000:0001

第三种形式是以众所周知的用点``.''作为分隔符的十进制 IPv4 形式,写出最后 32 Bit 的部分。 例如 2002::10.0.0.1 对应的十进制正规表达方式是 2002:0000:0000:0000:0000:0000:0a00:0001 它也相当于写成 2002::a00:1.

到现在,读者应该能理解下面的内容了:

# ifconfig
rl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 inet 10.0.0.10 netmask 0xffffff00 broadcast 10.0.0.255 inet6 fe80::200:21ff:fe03:8e1%rl0 prefixlen 64 scopeid 0x1 ether 00:00:21:03:08:e1 media: Ethernet autoselect (100baseTX ) status: active

fe80::200:21ff:fe03:8e1%rl0是一个自动配置的链路环回地址。它作为自动配置的一部分由MAC生成。

关于IPv6地址的结构的更多信息,请参看RFC3513

24.10.3. 进行连接

目前,有四种方式可以连接到其它IPv6主机和网络:

这里我们就讨论如何连接到6bone,因为它目前看来是最流行的一种方式。

首先看一下6bone网站,并找出离你最近的6bone连接。给某位值得信赖的人写信过去,如果运气好,你就会得到关于如何设置你的连接的指导。通常这包括了设置GRE (gif) 通道。

这里有一个典型的关于设置gif(4)通道的例子。

# ifconfig gif0 create # ifconfig gif0 gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 # ifconfig gif0 tunnel MY_IPv4_ADDR  HIS_IPv4_ADDR # ifconfig gif0 inet6 alias MY_ASSIGNED_IPv6_TUNNEL_ENDPOINT_ADDR

把大写字母换成你从上一级6bone节点收到的信息。

这样就建立了通道。通过ping6(8) ff02::1%gif0,检查通道是否工作。你应该会收到两个ping回应。

注: 或许你会对地址ff02:1%gif0感上兴趣,它是一个multicast地址。%gif0表明在网络接口gif0上的multicast地址已经用上了。因为我们ping一个multicast地址的时候,通道的另一端也应该会回应。

到现在,设置一个到6bone上级连接的路由应该是相当简单了。

# route add -inet6 default -interface gif0 # ping6 -n MY_UPLINK
# traceroute6 www.jp.FreeBSD.org (3ffe:505:2008:1:2a0:24ff:fe57:e561) from 3ffe:8060:100::40:2, 30 hops max, 12 byte packets 1  atnet-meta6  14.147 ms  15.499 ms  24.319 ms 2  6bone-gw2-ATNET-NT.ipv6.tilab.com  103.408 ms  95.072 ms * 3  3ffe:1831:0:ffff::4  138.645 ms  134.437 ms  144.257 ms 4  3ffe:1810:0:6:290:27ff:fe79:7677  282.975 ms  278.666 ms  292.811 ms 5  3ffe:1800:0:ff00::4  400.131 ms  396.324 ms  394.769 ms 6  3ffe:1800:0:3:290:27ff:fe14:cdee  394.712 ms  397.19 ms  394.102 ms

这个输出可能随机器而不同。到现在,你应该可以到达 IPv6 站点www.kame.net,并看到那只正跳舞的乌龟 -- 如果你有一个支持IPv6的浏览器,如www/mozillaKonquerorx11/kdebase3的一部分)或www/epiphany

24.10.4. IPv6世界里的DNS

对于IPv6有两种类型的DNS记录:IETF已经宣布A6是过时标准;现行的标准是AAAA记录。

使用AAAA记录是很简单的。通过增加下面内容,给你的主机分配置你刚才接收到的新的IPv6地址:

MYHOSTNAME           AAAA    MYIPv6ADDR

到你的主域DNS文件里,就可以完成。要是你自已没有DNS域服务,你可以询问你的DNS提供商。目前的bind版本(version 8.3 与 9)和dns/djbdns(含IPv6补丁)支持AAAA记录。

24.10.5. Applying the needed changes to /etc/rc.conf

24.10.5.1. IPv6 Client Settings

These settings will help you configure a machine that will be on your LAN and act as a client, not a router. To have rtsol(8) autoconfigure your interface on boot all you need to add is:

ipv6_enable="YES"

To statically assign an IP address such as 2001:471:1f11:251:290:27ff:fee0:2093, to your fxp0 interface, add:

ipv6_ifconfig_fxp0="2001:471:1f11:251:290:27ff:fee0:2093"

To assign a default router of 2001:471:1f11:251::1 add the following to /etc/rc.conf:

ipv6_defaultrouter="2001:471:1f11:251::1"

24.10.5.2. IPv6 Router/Gateway Settings

This will help you take the directions that your tunnel provider, such as the 6bone, has given you and convert it into settings that will persist through reboots. To restore your tunnel on startup use something like the following in /etc/rc.conf:

List the Generic Tunneling interfaces that will be configured, for example gif0:

gif_interfaces="gif0"

To configure the interface with a local endpoint of MY_IPv4_ADDR to a remote endpoint of REMOTE_IPv4_ADDR:

gif_config_gif0="MY_IPv4_ADDR REMOTE_IPv4_ADDR"

To apply the IPv6 address you have been assigned for use as your IPv6 tunnel endpoint, add:

ipv6_ifconfig_gif0="MY_ASSIGNED_IPv6_TUNNEL_ENDPOINT_ADDR"

Then all you have to do is set the default route for IPv6. This is the other side of the IPv6 tunnel:

ipv6_defaultrouter="MY_IPv6_REMOTE_TUNNEL_ENDPOINT_ADDR"

24.10.6. Router Advertisement and Host Auto Configuration

This section will help you setup rtadvd(8) to advertise the IPv6 default route.

To enable rtadvd(8) you will need the following in your /etc/rc.conf:

rtadvd_enable="YES"

It is important that you specify the interface on which to do IPv6 router solicitation. For example to tell rtadvd(8) to use fxp0:

rtadvd_interfaces="fxp0"

Now we must create the configuration file, /etc/rtadvd.conf. Here is an example:

fxp0:\
    :addrs#1:addr="2001:471:1f11:246::":prefixlen#64:tc=ether:

Replace fxp0 with the interface you are going to be using.

Next, replace 2001:471:1f11:246:: with the prefix of your allocation.

If you are dedicated a /64 subnet you will not need to change anything else. Otherwise, you will need to change the prefixlen# to the correct value.

Michael's Blog :: Just Do IT -- manuals