WireGuard 系列文章(三):WireGuard 安装

简介: WireGuard 系列文章(三):WireGuard 安装

WireGuard 的安装都不难,这里以我用到的设备为例,包括:

  1. Linux - Ubuntu 20.04
  2. Windows 10
  3. NAS - 威联通 QTS 5.0
  4. 安卓

Ubuntu 20.04

⚠️ 注意

WireGuard 对 Linux 内核版本有要求,5.4 以上内核才将其纳入其中。

如果内核低于该版本(典型如:RHEL 和 CentOS),就需要比较复杂的涉及内核编译的过程,请自行登录 官网 查找详细信息。

$ sudo apt install wireguard
BASH

安装成功后,有以下文件:

  1. CLI
  1. wg
  2. wg-quick
  1. Systemd
  1. wg-quick@.service
  2. wg-quick.target
# which wg
/usr/bin/wg # WireGuard CLI
# which wg-quick
/usr/bin/wg-quick # WireGuard 快速 CLI
# sudo ls -l /etc/
drwx------ 2 root root       4096 Aug  4  2020 wireguard    # WireGuard 默认配置文件位置
# sudo systemctl list-unit-files
UNIT FILE                              STATE           VENDOR PRESET
wg-quick@.service                      disabled        enabled
wg-quick.target                        static          enabled
# pwd
/lib/systemd/system # WireGuard 2 个 Service 所在的目录
# cat wg-quick@.service
# /usr/lib/systemd/system/wg-quick@.service
[Unit]
Description=WireGuard via wg-quick(8) for %I
After=network-online.target nss-lookup.target
Wants=network-online.target nss-lookup.target
PartOf=wg-quick.target
Documentation=man:wg-quick(8)
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i
ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'
Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity
[Install]
WantedBy=multi-user.target
# cat wg-quick.target
[Unit]
Description=WireGuard Tunnels via wg-quick(8)
BASH

✔️ 实用技巧

可以在 WireGuard 的 Service 文件中加入如下一行,重新加载配置流量不中断。

ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'

Windows 10

安装后 WireGuard UI 如下:

WireGuard UI

启动 WireGuard 后会有 2 个服务:

WireGuardManager 服务

WireGuard Tunnel 服务

Android

WireGuard Android 客户端:

WireGuard Android 客户端

威联通 QTS 5.0

我为啥会捣鼓 WireGuard,其实事情是这样滴:

  1. 家里的电信网,没有公网 IPv4,之前打电话要求有公网地址,给了个公网 IPv4,结果多一段时间发现又偷偷被收回了😓 虽然有 IPv6 公网地址,但是很多应用不支持
  2. 威联通提供的 QnapCloud 在没有公网 IPv4 的前提下,使用体验差极了
  3. 用 OpenVPN 和 IPsec 都搭建过家庭 VPN,性能、使用体验确实不行
  4. 前端时间 NAS 升级到 QTS 5.0(出于安全目的,会紧跟厂商升级),发现它 Linux Kernel 已经升级到 5.10, 自带 WireGuard:😏😏😏


  5. 「全新 QVPN 3.0 整合广受好评、更轻量、更稳定的 WireGuard VPN 服务,让您通过简单的用户接口轻松设置,享受快速安全联机,是居家工作与移动办公的不二选择。」好家伙,这么牛逼吗?那必须得试一试。
  6. 所以才有这一个多月捣鼓 WireGuard 的过程。

综上,QTS 5.0 内置 WireGuard,无需安装。

自带内容包括:

[~] # which wg
/usr/bin/wg
[~] # which wg-quick
/usr/bin/wg-quick
[~] # find / -name *wireguard* -type d 2>/dev/null
/share/CACHEDEV1_DATA/.qpkg/CodexPack/sys/module/wireguard
/share/CACHEDEV1_DATA/.qpkg/QVPN/wireguard_log  # wg 日志目录
/sys/module/wireguard    
/mnt/HDA_ROOT/.config/qvpn/wireguard    # wg 默认配置目录,就是 `/etc/config/qvpn/wireguard/` 这个目录
[~] # ll /share/CACHEDEV1_DATA/.qpkg/QVPN/wireguard_log
total 16K
drwxr-xr-x  2 admin administrators 4.0K 2021-11-12 23:01 ./
drwxr-xr-x 13 admin administrators 4.0K 2021-11-15 23:00 ../
-rw-rw-rw-  1 admin administrators 6.8K 2021-12-07 21:14 wg_server.log
[~] # find / -name *wireguard* -type f 2>/dev/null
/share/CACHEDEV1_DATA/.qpkg/container-station/usr/local/container-station/python/lib/python2.7/site-packages/pyroute2/netlink/generic/wireguard.pyc
/share/CACHEDEV1_DATA/.qpkg/container-station/usr/local/container-station/python/lib/python2.7/site-packages/pyroute2/netlink/generic/wireguard.py
/share/CACHEDEV1_DATA/.qpkg/container-station/usr/local/container-station/python/lib/python2.7/site-packages/scapy/contrib/wireguard.pyc
/share/CACHEDEV1_DATA/.qpkg/container-station/usr/local/container-station/python/lib/python2.7/site-packages/scapy/contrib/wireguard.py
/share/CACHEDEV1_DATA/.qpkg/QVPN/etc/init.d/vpn_wireguard_client.sh # 如果是用 qvpn 配置的 wireguard,那么这是 qvpn 调用 wireguard 的启动脚本
/share/CACHEDEV1_DATA/.qpkg/QVPN/etc/init.d/vpn_wireguard.sh # 如果是用 qvpn 配置的 wireguard,那么这是 qvpn 调用 wireguard 的启动脚本
/lib/modules/5.10.60-qnap/wireguard.ko
BASH

参考资料

相关文章
|
3月前
|
网络协议 安全 网络安全
WireGuard 系列文章(六):Netmaker 安装
WireGuard 系列文章(六):Netmaker 安装
|
3月前
|
Kubernetes 网络协议 数据安全/隐私保护
WireGuard 系列文章(八):基于 WireGuard 的 K8S CNI Kilo 简介
WireGuard 系列文章(八):基于 WireGuard 的 K8S CNI Kilo 简介
|
3月前
|
网络协议 网络安全 网络虚拟化
WireGuard 系列文章(四):WireGuard 快速上手
WireGuard 系列文章(四):WireGuard 快速上手
openvpn安装文档
openvpn通过使用公开密钥(非对称密钥,加密解密使用不同的key,一个称为Publice key,另外一个是Private key)对数据进行加密的。这种方式称为TLS加密。openvpn使用TLS加密的工作过程是,首先VPN Sevrver端和VPN Client端要有相同的CA证书,双方通过交换证书验证双方的合法性,用于决定是否建立VPN连接。然后使用对方的CA证书,把自己目前使用的数据加密方法加密后发送给对方,由于使用的是对方CA证书加密,所以只有对方CA证书对应的Private key才能解密该数据,这样就保证了此密钥的安全性,并且此密钥是定期改变的。
2547 0
|
3月前
|
安全 网络安全 网络虚拟化
WireGuard 系列文章(二):WireGuard 简介 - 快速、现代、安全的 VPN 隧道
WireGuard 系列文章(二):WireGuard 简介 - 快速、现代、安全的 VPN 隧道
|
3月前
|
网络协议 物联网 Linux
WireGuard 系列文章(七):使用 WireGuard 和 Netmaker 创建 Full Mesh 网络
WireGuard 系列文章(七):使用 WireGuard 和 Netmaker 创建 Full Mesh 网络
|
3月前
|
安全 网络协议 网络安全
WireGuard 系列文章(一):什么是 VPN
WireGuard 系列文章(一):什么是 VPN
|
存储 网络协议 Shell
strongSwan之ipsec.secrets配置手册
将ID与选择器匹配相当简单:它们必须相等。在“Road Warrior”连接的情况下,如果找不到对等体ID的相同匹配项,并且它是IP地址的形式,则%any的选择器将匹配对等体的IP地址(如果是IPV4),而%any6的选择器将匹配对等体的IP地址(如果是IPV6)。目前,可以使用过时的符号0.0.0.0代替%any。
395 0
strongSwan之ipsec.secrets配置手册
|
算法 网络协议 安全
strongswan之ipsec.conf配置手册(上)
strongswan之ipsec.conf配置手册
|
网络协议 Shell 网络安全
strongswan之ipsec.conf配置手册(下)
strongswan之ipsec.conf配置手册