本文最后更新于 334 天前,其中的信息可能已经有所发展或是发生改变。
sysctl设置IPV6的选项
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.eth0.accept_ra = 2
一键写入sysctl并且生效
cat >> /etc/sysctl.conf << EOF
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.accept_ra = 2
EOF
sysctl -p
开启内网IPV6
vim /etc/docker/daemon.json
添加下面的内容
- 请保证json格式的正确性
fd00::/64
为内网IP,类似于192.168.1.0/24
这样"ip6tables": true
这个设置涉及到 IPv6 的防火墙规则,其中 iptables 是 Linux 系统上用于配置 IPv4 防火墙规则的工具。ip6tables 则是用于配置 IPv6 防火墙规则的工具。通过将 "ip6tables" 设置为 true,表示启用了 IPv6 防火墙规则。"experimental": true
这个设置通常表示启用了实验性的功能或特性。在软件开发中,"experimental" 通常用于指示某些功能处于测试阶段,可能不稳定或不适用于生产环境。{ "ipv6": true, "fixed-cidr-v6": "fd00::/64", "ip6tables": true, "experimental": true }
重启docker
systemctl daemon-reload systemctl restart docker
检查IPV6
docker run -itd --name nginx -p 80:80 nginx
docker inspect nginx | grep -i "ipv6"
Result IPV6
root@debian201212:~# docker inspect nginx | grep -i "ipv6"
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "fd00::242:ac11:2",
"GlobalIPv6PrefixLen": 64,
"IPv6Gateway": "fd00::1",
"IPv6Gateway": "fd00::1",
"GlobalIPv6Address": "fd00::242:ac11:2",
"GlobalIPv6PrefixLen": 64,
添加独立IPV6
查看是否支持IPV6独立公网
- ::1/128 为回环地址,类似于127.0.0.1
- 2401:b60:1:ffff::fccd:f8d5/48 为独立IPV6并且为48位的段,可用的地址
- fe80::216:3eff:fe8c:f2b5/64 为内网地址,类似于 192.168.1.0/24
root@hytron-hk:/etc# ip a | grep -i inet6 inet6 ::1/128 scope host inet6 2401:b60:1:ffff::fccd:f8d5/48 scope global inet6 fe80::216:3eff:fe8c:f2b5/64 scope link
已知有可用的IPV6切段为48位
-
进入网址
https://www.site24x7.com/zhcn/tools/ipv6-subnetcalculator.html
-
如图所示,当前只有一个大段能使用我们要变成多个段分别给下去
-
下面所显示的就是一个网络可用划分出多少个子网,我们以/50举例
sysctl.conf 设置ndp
-
net.ipv6.conf.all.proxy_ndp
中的all更建议换成实际的网卡名 -
比如 网卡名为 ens5
sysctl net.ipv6.conf.ens5.proxy_ndp=1
sysctl net.ipv6.conf.all.proxy_ndp=1
子网明细 /50子网
Subnet ID | Subnet Address | Host Address Range | Notation |
1 | 2401:0b60:0001:: | 2401:b60:1:: – 2401:b60:1:3fff:: | 2401:b60:1::/50 |
2 | 2401:0b60:0001:4000:: | 2401:b60:1:4000:: – 2401:b60:1:7fff:: | 2401:b60:1:4000::/50 |
3 | 2401:0b60:0001:8000:: | 2401:b60:1:8000:: – 2401:b60:1:bfff:: | 2401:b60:1:8000::/50 |
4 | 2401:0b60:0001:c000:: | 2401:b60:1:c000:: – 2401:b60:1:ffff:: | 2401:b60:1:c000::/50 |
开启公网IPV6
vim /etc/docker/daemon.json
{
"ipv6": true,
"fixed-cidr-v6": "2401:b60:1::/50",
"ip6tables": true,
"experimental": true
}
检查IPV6
docker run -itd --name nginx -p 80:80 nginx
docker inspect nginx | grep -i "ipv6"
Result IPV6
root@debian201212:~# docker inspect nginx | grep -i "ipv6"
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "2401:b60:1::5",
"GlobalIPv6PrefixLen": 50,
"IPv6Gateway": "fd00::1",
"IPv6Gateway": "2401:b60:1::1",
"GlobalIPv6Address": "2401:b60:1::5",
"GlobalIPv6PrefixLen": 64,
宣告邻居
ip -6 neigh add proxy <docker 容器 IPV6> dev <公网IPV6网卡名称>
ip -6 neigh add proxy 2401:b60:1::5 dev ens5
ip6tables 映射
ip6tables -t nat -A PREROUTING -d <本机IPV6公网> -j NETMAP --to <docker 容器 IPV6>
ip6tables -t nat -A PREROUTING -d 2401:b60:1:ffff::fccd:f8d5 -j NETMAP --to 2401:b60:1::5
Result
- 访问 http://[2401:b60:1:ffff::fccd:f8d5]
- Success