在Ubuntu 24.04 上启动WireGuard
在Ubuntu 24.04 上启动WireGuard 需要先安装WireGuard, 然后配置并启用WireGuard 接口。启动后,可以使用 wg show 命令来查看接口状态,并使用 journalctl 命令来查看日志进行故障排除。
以下是详细步骤:
1. 安装WireGuard:
代码
sudo apt updatesudo apt install wireguard2. 创建WireGuard 配置文件:
- 创建一个新的配置文件,例如
/etc/wireguard/wg0.conf(使用你喜欢的文本编辑器)。 - 配置文件的内容包括:
[Interface]部分:PrivateKey: 服务器的私钥(使用wg genkey生成)。Address: 服务器的IP 地址(例如,10.6.0.1/24)。ListenPort: 服务器监听的端口(例如,51820)。
[Peer]部分:PublicKey: 客户端的公钥。AllowedIPs: 客户端可以访问的IP 地址范围(例如,10.6.0.2/32)。Endpoint: 客户端的公网IP 地址和端口(例如,client.example.com:51820)。PersistentKeepalive: 保持连接的频率(例如,25)。
3. 启用并启动WireGuard 接口:
代码
sudo systemctl enable wg-quick@wg0.servicesudo systemctl start wg-quick@wg0.service4. 验证WireGuard 接口状态:
代码
sudo wg show wg05. 查看日志(故障排除):
代码
sudo journalctl -u wg-quick@wg0.service
参考2:
1. 安装WireGuard:2. 配置WireGuard 接口:
- 创建一个配置文件,例如
wg0.conf,在/etc/wireguard/目录下。配置文件内容包括私钥、公钥、对端地址和允许的IP范围等。Vultr Docs 提供了详细的配置示例。- 生成WireGuard 密钥对:
- 根据你的需求,修改
wg0.conf文件,例如:3. 启动WireGuard 服务:使用wg-quick 命令启动接口。
- 启用
wg0接口在开机时自动启动:
评论
发表评论