安装 WireGuard VPN
一、 环境介绍 Debian 11.10 阿里云上海ECS 二、 部署 安装wireguard sudo apt update sudo apt install wireguard wireguard-tools 生成 WireGuard 服务器端密钥对 1. 生成服务器私钥和公钥: 使用 wg 命令生成密钥对: wg genkey | tee /etc/wireguard/server_private_key | wg pubkey > /etc/wireguard/server_public_key wg genkey | tee /etc/wireguard/server_private_key | wg pubkey > /etc/wireguard/server_public_key View this post on Instagram wg genkey | tee /etc/wireguard/server_private_key | wg pubkey > /etc/wireguard/server_public_key wg genkey | tee /etc/wireguard/server_private_key | wg pubkey > /etc/wireguard/server_public_key 2. 查看密钥: 你可以查看生成的私钥和公钥: cat /etc/wireguard/server_private_key cat /etc/wireguard/server_public_key 配置 WireGuard 服务器 1. 创建 WireGuard 配置文件 /etc/wireguard/wg0.conf: sudo nano /etc/wireguard/wg0.conf 2. 配置文件内容: 根据你的网络需求,填写以下内容(这将是服务器端的配置): [Interface] Address = 10.0.0.1/24 # 服务器的虚拟 IP 地址 ListenPort = 51820 # WireGuard 默认端口 PrivateKey = <server_private_key> # 服务器的私钥(复制之前生成的私钥) # 客户端配置 [Peer] PublicKey = <client_public_key> # 客户端公钥(稍后会配置) AllowedIPs = 10.0.0.2/32 # 允许连接的客户端的虚拟 IP 地址 Address:配置服务器的虚拟 IP 地址,通常设置为一个私有子网(如 10.0.0.1/24)。 ListenPort:WireGuard 默认监听端口,51820。 PrivateKey:填入你生成的服务器私钥。 [Peer] 部分用于配置客户端。 3. 保存并退出编辑器:按 CTRL+X 保存文件,按 Y 确认保存。 步骤 4:启用 IP 转发和配置 NAT 1. 在 /etc/sysctl.conf 找到并取消注释以下行: net.ipv4.ip_forward=1 2.配置生效 sudo sysctl -p 3. 配置防火墙NAT 启动 WireGuard 服务 1. 启动 WireGuard 服务: 启动 WireGuard 并激活配置文件 wg0: sudo wg-quick up wg0