PVE 主机启用 IPv6 的正确方法
categories: 技术 tags: NAS, ProxmoxVE网络存储服务一站式指南PVE主机启用IPv6的正确方法
PVE系统不能直接在 /etc/network/interface 中添加某些网络选项,容易导致开机卡住。
如果不幸卡住,可以用 Linux Live 系统或者 Linux PE 等方法将 /etc/network/interface 的错误内容去掉,重新开机。
非必要尽量不动 /etc/network/interface 中的任何内容。
创建 sysctl 配置
新建 /etc/sysctl.d/99-pve-ipv6.conf,只保留全局 all 和 default 配置:
# IPv6 Support
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.accept_ra = 2
net.ipv6.conf.default.accept_ra = 2
net.ipv6.conf.all.autoconf = 2
net.ipv6.conf.default.autoconf = 2
# net.ipv6.conf.vmbr0.accept_ra = 2
# net.ipv6.conf.vmbr0.autoconf = 2
为什么这份文件中注释了添加网络接口相关配置?
systemd-sysctl 在引导早期执行,此时 vmbr0 等网桥还没创建,net.ipv6.conf.vmbr0.* 在 sysctl.d 文件里写了也是开机不生效。
因此你会发现,你手动执行 sysctl --system 后,等几分钟可以拿到公网 IPv6,但一重启就失效,必须每次都手动执行一次上述命令。并且,sysctl net.ipv6.conf.vmbr1.accept_ra 重启后始终为 1。
因此,不想用每次开机都手动重载方案的话,sysctl 配置文件保留一个全局配置就可以了。(留着也不影响什么,不生效而已)
网络接口配置
有三种方法解决网络接口配置不生效的问题。
在 interfaces 里 post-up,网桥就绪自动执行
编辑 /etc/network/interfaces,找到 vmbr0 的配置块,增加 post-up:
auto vmbr0
iface vmbr0 inet static
address xxx.xxx.xxx.xxx/24
gateway xxx.xxx.xxx.xxx
bridge-ports enpXsY
bridge-stp off
bridge-fd 0
# 新增,vmbr0启用时自动设置ipv6 sysctl
post-up sysctl -w net.ipv6.conf.vmbr0.accept_ra=2
post-up sysctl -w net.ipv6.conf.vmbr0.autoconf=2
全局配置保留在/etc/sysctl.conf,给虚拟机 LXC 做转发。
独立 sysctl.d 文件 + 开机后重新加载 sysctl
本方法需要写全 sysctl 配置,取消注释 /etc/sysctl.d/99-pve-ipv6.conf 中:
net.ipv6.conf.vmbr0.accept_ra = 2
net.ipv6.conf.vmbr0.autoconf = 2
创建一个系统服务,写入以下内容,带网络就绪后重载 sysctl
[Unit]
Description=Reload sysctl after bridge up
After=network.target
Wants=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/sysctl --system
[Install]
WantedBy=multi-user.target
crontab 开机自动重载
本方法需要写全 sysctl 配置,取消注释 /etc/sysctl.d/99-pve-ipv6.conf 中:
net.ipv6.conf.vmbr0.accept_ra = 2
net.ipv6.conf.vmbr0.autoconf = 2
添加,@reboot sleep 30 && sysctl --system,让系统自己重载