WireGuard 是一个轻量级的 VPN 服务器,安装和配置相对简单。以下是在 Ubuntu/Linux 系统上安装 WireGuard 的步骤
安装必要工具
确保你的系统已经安装了必要的工具。
sudo apt update sudo apt install ufw dnsmasq iptables
生成 WireGuard 密钥
下载并运行 WireGuard 安装脚本:
sudo wget https://raw.githubusercontent.com/wireguard/wireguard/master/src/utils/install.sh sudo bash install.sh
设置 WireGuard 服务器
运行安装脚本后,WireGuard 会为你生成默认的配置文件,位置在 /etc/wireguard/。
sudo wg-quick-hello
配置 WireGuard 服务器
编辑 WireGuard 的配置文件,添加服务器的 IP、端口和 DNS 服务器。
sudo nano /etc/wireguard/wg.conf
[Interface] ListenPort = 518 DNAT = port-forwarding MASQUERADE = yes [Peer] AllowedIPs = 0.../24 Endpoint = your-external-ip:518 PersistentKeepalive = 10
启动 WireGuard 服务
启动 WireGuard 服务并设置开机启动。
sudo systemctl unmask wg-quick@wg.service sudo systemctl enable wg-quick@wg.service sudo systemctl start wg-quick@wg.service
连接到 WireGuard 服务器
使用以下命令连接到服务器(your-external-ip 替换为你的服务器 IP 或域名):
sudo wg-quick-join your-external-ip:518
测试连接
使用 ping 命令测试连接是否成功。
ping 8.8.8.8
配置 DNS 和域名(可选)
如果你希望 WireGuard 服务器作为 DNS 服务器,可以添加以下内容到配置文件中:
[DNS] Domains = *
然后重启服务:
sudo systemctl restart wg-quick@wg.service
安装完成
完成以上步骤后,WireGuard 已经安装并配置完成,你可以通过你的设备连接到服务器,享受高效的 VPN 服务。
如果你遇到问题,可以检查 WireGuard 的日志文件:
sudo journalctl -u wg-quick@wg.service -b

如果没有特点说明,本站所有内容均由原子加速器官方网站|提供客户端版本、线路管理与节点选择功能,适配Windows、Android、iOS等设备,便于用户进行网络连接优化原创,转载请注明出处!