在非特权容器中安装WireGuard(Proxmox环境)完整指南

在非特权容器中安装WireGuard(Proxmox环境)

WireGuard是VPN领域的新星——相比传统VPN技术确实具有诸多优势,但本文不赘述这些内容,因为互联网上已有大量相关讨论。本篇博文专门讲解如何在非特权容器中部署WireGuard,所有操作均基于Proxmox服务器环境。

主机端配置

首先需要在Proxmox宿主机上激活内核模块。由于Proxmox基于Debian,我们采用Debian项目推荐的方案:从unstable仓库获取WireGuard包。

echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable-wireguard.list
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
apt update
apt install wireguard pve-headers

若安装过程中出现以下提示:

Loading new wireguard-0.0.20190406 DKMS files...
Building for 4.15.18-9-pve
Module build for kernel 4.15.18-9-pve was skipped since the
kernel headers for this kernel does not seem to be installed.
Setting up linux-headers-4.9.0-8-amd64 (4.9.144-3.1) ...

需确保已安装当前内核对应的pve-headers。若后续安装headers,需执行:

dkms autoinstall

通过以下命令测试模块加载:

modprobe wireguard

成功后配置开机自动加载模块(宿主机无法预知容器后续需要此模块):

echo "wireguard" >> /etc/modules-load.d/modules.conf

容器端配置

创建非特权容器(本文以Debian 9为例)后安装用户空间工具:

echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable-wireguard.list
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
apt update

特别说明:此处仅安装用户空间工具

apt-get install --no-install-recommends wireguard-tools

功能验证

通过创建临时wg0设备测试安装结果:

ip link add wg0 type wireguard

无输出即表示成功。后续配置与常规WireGuard部署完全相同,可参考任意标准教程完成。

发布于2019年4月14日 | 分类:HowTo, IT安全, Linux, 网络技术
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码

posted @ 2025-08-25 15:06  qife  阅读(3)  评论(0)    收藏  举报