首页 OpenVZ安装WireGuard方法
文章
取消

OpenVZ安装WireGuard方法

简介

WireGuard是一款已经被合并到linux内核的vpn,这使得我们在组网时有了更轻量的软件。一些社区的用户首先推荐使用此款软件,如DN42。但是在OpenVZ的虚拟化平台下,无法直接使用,需要使用wireguard-go,本文章介绍完整的安装和使用方法。

安装配置步骤

安装WireGuard

1
2
3
4
5
# apt update
# apt upgrade
# sh -c "echo 'deb http://deb.debian.org/debian buster-backports main contrib non-free' > /etc/apt/sources.list.d/buster-backports.list"
# apt update
# apt install wireguard

安装wireguard-go

1
# git clone https://github.com/WireGuard/wireguard-go.git

对于小内存vps可以修改device/queueconstants_default.go,这可以限制最大使用20MB内存

1
2
MaxSegmentSize             = 1700 
PreallocatedBuffersPerPool = 1024 

编译安装:

1
2
3
# make
# cp wireguard-go /usr/local/bin
# wireguard-go --version

配置WireGuard秘钥

1
2
3
# cd /etc/wireguard/
# umask 077; wg genkey | tee privatekey | wg pubkey > publickey
# ls -l privatekey publickey

配置WireGuard配置文件

1
2
3
4
5
6
7
8
9
10
11
# cat /etc/wireguard/wg123.conf
[Interface]
PrivateKey = {你的privatekey}
ListenPort = {监听端口,每个配置文件1个端口}
PostUp = ip addr add {fe80/10或其他ip地址} dev %i
Table = off

[Peer]
PublicKey = {对面的公钥}
AllowedIPs = {允许的ip段}
Endpoint = {对面WireGuard服务端ip:port}

同时,你需要把自己的publickey、公网ip、监听端口以及内网组网ip发送给对端,让对端也配置好WireGuard。

配置允许用户态wireguard-go

修改/lib/systemd/system/wg-quick@.service,添加一行环境变量。

1
Environment=WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1 

启用WireGuard

1
2
3
4
5
# systemctl enable wg-quick@wg123
# systemctl start wg-quick@wg123
# systemctl status wg-quick@wg123
# ip addr
# wg

这样就安装配置好了。

参考

Debian10安装WireGuard

OpenVZ安装配置wireguard-go

用户态wireguard-go手动启动脚本

知识共享许可协议 本文由作者按照 CC BY-SA 4.0 进行授权