跳到主要内容

路由通告服务:radvd

为什么需要 radvd ?

如果你使用主路由方案,宽带也支持 IPv6,且希望家里的设备也都使用 IPv6,那就需要在主路由上部署 radvd 作为路由通告服务,类似 IPv4 的 DHCP 服务,为内网设备分配 IPv6 地址。

编译 radvd 镜像

Dockerfile 示例:

Dockerfile
FROM ubuntu:22.04
RUN apt update -y
RUN apt install -y radvd
ENTRYPOINT ["/usr/sbin/radvd", "--config", "/etc/radvd.d/radvd.conf", "--logmethod", "stderr_clean", "--nodaemon"]

目录结构

radvd
├── Dockerfile
├── config
│   └── radvd.conf
├── daemonset.yaml
└── kustomization.yaml

准备 radvd.conf

config/radvd.conf
interface enp2s0 {
# 网卡启用路由通告(RA)
AdvSendAdvert on;
# 启用 Home Agent(iOS、macOS等移动设备加入网络时发送Home Agent请求获取ipv6信息)
AdvHomeAgentFlag on;
AdvHomeAgentInfo on;
MinRtrAdvInterval 10;
MaxRtrAdvInterval 60;
prefix fddd:dddd:dddd:dddd::2/64 {
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
route fddd:dddd:dddd:dddd::2/64 {
AdvRoutePreference high;
AdvRouteLifetime 3600;
RemoveRoute off;
};
};

准备 daemonset.yaml

config/radvd.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: radvd
name: radvd
namespace: default
spec:
selector:
matchLabels:
app: radvd
template:
metadata:
labels:
app: radvd
spec:
initContainers:
- image: imroc/radvd:2.18
imagePullPolicy: IfNotPresent
name: sysctl
securityContext:
privileged: true
command:
- sh
- -c
- |
sysctl -w net.ipv6.conf.all.accept_ra_rt_info_max_plen=128
sysctl -w net.ipv6.conf.default.accept_ra_rt_info_max_plen=128
sysctl -w net.ipv6.conf.all.forwarding=1
sysctl -w net.ipv6.conf.default.forwarding=1
containers:
- image: imroc/radvd:2.18
imagePullPolicy: IfNotPresent
name: radvd
securityContext:
privileged: true
args: ["--debug", "5"]
volumeMounts:
- mountPath: /etc/radvd.d
name: radvd-config
hostNetwork: true
restartPolicy: Always
volumes:
- configMap:
name: radvd-config
name: radvd-config
updateStrategy:
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
  • 使用 initContainer 自动修改内核参数以启用 IPv6 转发和接收路由通告(拨号的网卡通过路由通告接收来自运营商分配的 IPv6 地址)。

准备 kustomization.yaml

kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- daemonset.yaml

namespace: default

configMapGenerator:
- name: radvd-config
files:
- config/radvd.conf