Configure IPv6 for OVH dedicated servers

English Version

OVH的机器默认给的是/128,但是其实整个/64都是可以用的,如果添加到网卡上是可以双向ping通的。

但是如果docker的bridge网络分配了一个IPv6,却无法ping通。喝了一瓶果汁之后我发现是因为没有向(OVH的)路由器发邻居发现协议包(NDP)。

辛酸历程

配置docker使用IPv6

参考docker官方文档,给dockerd的启动参数增加

–ipv6 –fixed-cidr-v6=aaaa:bbbb:cccc:dddd:1::/80

需要注意的是如果是Ubuntu用户,并且docker是从很早的版本(Ubuntu 16.04 LTS发布以前)一路升级上来的话,你可能去会更改/etc/default/docker。然而systemd并不会自动读取/etc/default/docker(见这个issue)。怎么想都是systemd的错。所以要么在/lib/systemd/system/docker.service中增加

要么直接修改/lib/systemd/system/docker.service,加上上面说的启动参数。

配置内核转发IPv6

参考docker官方文档,配置内核转发IPv6包,运行:

OVH不是用Router Advertisement来获得IPv6地址的,所以不需要配置net.ipv6.conf.eth0.accept_ra

配置内核转发NDP

其实就是为了告诉OVH的路由器,这个IPv6地址的包请让我来处理。

运行:

然后设置转发NDP,其中IP是容器的IPv6地址:

你一定觉得每个容器都要发一遍很烦吧,可以:

  1. 事先配置为aaaa:bbbb:cccc:dddd:1:242:ac11:0 – aaaa:bbbb:cccc:dddd:1:242:ac11:ffff发NDP。因为docker默认使用MAC地址来配置IPv6,根据这个文档,docker会使用的MAC为02:42:ac:11:00:00到02:42:ac:11:ff:ff。
  2. 安装ndppd,配置/etc/ndppd.conf,填写

proxy eth0 {
rule aaaa:bbbb:cccc:dddd:1::/80 {

}
}


OVH gives you a /128 block by default. But in fact you can use the whole /64. You can simply add a /64 address to eth0.

But if you activate IPv6 in docker and try to allocate an address in bridge network, you will find the address is not ping-able. The problem here is we should send a NDP notification to OVH router.

How it works

Configure docker to use IPv6

According to this docker document ,we should append these options to dockerd:

–ipv6 –fixed-cidr-v6=aaaa:bbbb:cccc:dddd:1::/80

If you are an Ubuntu user and upgrade from 14.04 to 16.04, you may be thinking to edit /etc/default/docker. But actually systemd will not read this file at all. Systemd is never wrong. So you may either add these lines to /lib/systemd/system/docker.service:

or edit /lib/systemd/system/docker.service directly.

Configure kernel to forward IPv6

According to docker document,run:

OVH does not use Router Advertisement to allocate IPv6, so we don’t need to touch net.ipv6.conf.eth0.accept_ra.

Configure kernel to proxy NDP

This is needed to tell the OVH router that please let me handle the packet with source or destination equal to this address. Run:

Then set to proxy NDP, the IPv6 address should be container’s IPv6 address.

You may find this annoying to set this every time for a new container. So you can:

  1. Set ndp proxy for aaaa:bbbb:cccc:dddd:1:242:ac11:0 – aaaa:bbbb:cccc:dddd:1:242:ac11:ffff in advance. That’s because docker uses MAC address to configure IPv6 by default, according to this document, docker will only use 02:42:ac:11:00:00 to 02:42:ac:11:ff:ff as MAC address for container.
  2. Install ndppd,create and edit /etc/ndppd.conf:

proxy eth0 {
rule aaaa:bbbb:cccc:dddd:1::/80 {

}
}