安装 WireGuard
根据你的操作系统安装 WireGuard:
Windows
- 打开 PowerShell(以管理员身份运行)。
- 复制以下命令并粘贴并按回车:
powershell -Command "iwr https://www.wireguard.io/assets/windows/wg-1..2.zip"
- 提取压缩文件,找到
wg.exe并运行它。
Linux
- 使用包管理器安装 WireGuard:
- Ubuntu/Debian:
sudo apt-get install wireguard
- Fedora:
sudo dnf install wireguard
- Ubuntu/Debian:
- 启用 WireGuard 服务:
sudo systemctl unmask wireguard sudo systemctl enable wireguard
macOS
- 使用 Homebrew 安装:
brew install wireguard
- 启用 WireGuard 服务:
sudo launchctl load /System/Library/LaunchDaemons/wireguard.plist
配置 WireGuard 服务器
在服务器上安装 WireGuard 并配置接口:
服务器配置
- 打开终端并运行以下命令生成公钥:
wg genkey
- 将生成的公钥添加到 WireGuard 服务中:
wg-quick add
- 啟動 WireGuard 服務:
sudo systemctl start wireguard
客户端配置
- 在客户端上生成相同的公钥:
wg genkey
- 将客户端的公钥添加到服务器:
wg-quick add <服务器IP>
替換
<服务器IP>为你們的服务器地址。
连接到服务器
使用 wg 命令连接到服务器:
自动连接
- 啟動自動連接:
wg-quick connect <服务器IP>:<服務埠號>
- 如果你有自己的密鑰,使用:
wg-quick connect <服务器IP>:<服務埠號> --key <私钥文件>
手動配置
-
打開 WG 配置文件(
~/.wg/config)並編輯:nano ~/.wg/config
-
添加以下內容,並保存:
[Interface] Address = 192.168.1.2/24 Port = 518 ListenPort = 5181
-
啟動連接:
wg-quick up
高級設定
- MTU 設定:
wg set mtu 138
- DNS 配置:
wg set dns 8.8.8.8
安全注意事項
- 私鑰管理:將私鑰 stored安全地,避免落入敵人手中。
- 防火牢配置:確保 WG 服務只接受授權連接。
- 防火牢规則:使用
ufw或iptables限制 WG 連接。
常用工具
wg-quick:用於快速連接。wg:用於管理 WG 接口。wgctl:用於遠程管理 WG 服務。
总結
WireGuard 提供了簡單易用的 API 和高性能的連接,適合 VPN 和安全通信,使用上述指南,你可以輕鬆在电脑上配置 WireGuard,享受安全且快速的網絡連線。









