Edit $ vim /etc/docker/daemon.json configuration, add the following content at the end:

"ipv6": true,
"fixed-cidr-v6": "fd10::/80"

If this file does not exist, create it manually.

Add rules

Add two rules for configuring IPv6 NAT

# Temporary addition
$ ip6tables -t nat -A POSTROUTING -s fd00::/80 ! -o br+ -j MASQUERADE
$ ip6tables -t nat -A POSTROUTING -s fd10::/80 ! -o docker0 -j MASQUERADE

Test access

Reload the docker service

$ systemctl reload docker

Start a temporary container to ping Google's v6 address

$ docker run -it --rm registry.cn-hangzhou.aliyuncs.com/bohai_repo/dnsutils:1.3 ping -6 -c 4 google.com
PING google.com (2607:f8b0:4007:818::200e): 56 data bytes
64 bytes from 2607:f8b0:4007:818::200e: seq=0 ttl=116 time=8.250 ms
64 bytes from 2607:f8b0:4007:818::200e: seq=1 ttl=116 time=8.230 ms
64 bytes from 2607:f8b0:4007:818::200e: seq=2 ttl=116 time=8.187 ms
64 bytes from 2607:f8b0:4007:818::200e: seq=3 ttl=116 time=8.291 ms

After testing accessibility, you need to permanently save the previously added v6 nat rules. The specific steps are as follows

$ cat << EOF >> /etc/rc.d/rc.local
ip6tables -t nat -A POSTROUTING -s fd00::/80 ! -o br+ -j MASQUERADE
ip6tables -t nat -A POSTROUTING -s fd10::/80 ! -o docker0 -j MASQUERADE
EOF

$ chmod +x /etc/rc.d/rc.local 
Last modification:August 14, 2024
如果觉得我的文章对你有用,请随意赞赏