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

本文详细介绍了在Proxmox虚拟化平台上为无特权容器配置WireGuard VPN的完整步骤,包括内核模块安装、用户空间工具配置和容器环境设置,适合需要在隔离环境中部署安全网络连接的用户。

在无特权容器中安装WireGuard(Proxmox)

WireGuard是VPN领域的新星——相比传统VPN技术确实具有一些优势,但本文不会讨论这些,因为互联网上已有大量相关信息。这篇博文专门讲解如何在无特权容器中设置WireGuard。我的所有操作都在Proxmox服务器上完成。让我们开始:

在Proxmox主机上配置内核模块

由于Proxmox基于Debian,我们只需按照Debian项目推荐的方式从unstable仓库获取WireGuard包:

1
2
3
4
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

如果遇到以下输出:

1
2
3
4
5
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。如果之后安装,需要调用:

1
dkms autoinstall

两种情况下都使用以下命令测试:

1
modprobe wireguard

如果工作正常,我们让模块在启动时自动加载,因为主机不知道容器后续需要该模块:

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

在容器中安装用户空间工具

现在我们创建无特权容器(我使用的是Debian 9),然后安装用户空间工具:

1
2
3
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

现在需要特别处理——我们只想要用户空间工具,不需要其他内容:

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

可以通过临时创建wg0设备来进行简单测试:

1
ip link add wg0 type wireguard

没有输出意味着一切正常。至此我们完成了所有设置,其余操作与在容器外运行Wireguard相同——只需选择相应的操作指南即可。

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计