在Ubuntu 24.04 上启动WireGuard

 在Ubuntu 24.04 上启动WireGuard 需要先安装WireGuard, 然后配置并启用WireGuard 接口启动后,可以使用 wg show 命令来查看接口状态,并使用 journalctl 命令来查看日志进行故障排除。

以下是详细步骤:
1. 安装WireGuard:
代码
sudo apt updatesudo apt install wireguard
2. 创建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.service
4. 验证WireGuard 接口状态:
代码
sudo wg show wg0
5. 查看日志(故障排除):
代码
sudo journalctl -u wg-quick@wg0.service 


参考2:
1. 安装WireGuard:
代码
sudo apt updatesudo apt install wireguard
2. 配置WireGuard 接口:
  • 创建一个配置文件,例如 wg0.conf,在 /etc/wireguard/ 目录下。配置文件内容包括私钥、公钥、对端地址和允许的IP范围等。Vultr Docs 提供了详细的配置示例。
  • 生成WireGuard 密钥对:
代码
wg genkey | tee privatekey | wg pubkey > publickey
  • 根据你的需求,修改 wg0.conf 文件,例如:
代码
[Interface]PrivateKey = <你的私钥>Address = 10.78.0.2/32
ListenPort = 51820[Peer]
PublicKey = <对端公钥>AllowedIPs = 192.168.77.0/24Endpoint = <端IP>:<对端端口>
3. 启动WireGuard 服务:
使用wg-quick 命令启动接口。
代码
sudo wg-quick up wg0
  • 启用 wg0 接口在开机时自动启动:
代码
sudo systemctl enable wg-quick@wg0
5. 常用命令:
  • 启动接口:sudo wg-quick up wg0
  • 停止接口:sudo wg-quick down wg0
  • 查看状态:sudo wg show 或 ip a show wg0
  • 查看日志:sudo journalctl -u wg-quick@wg0.service
  • 启用开机自启:sudo systemctl enable wg-quick@wg0
  • 禁用开机自启:sudo systemctl disable wg-quick@wg0

评论

此博客中的热门博文

使用 OpenWrt 23.05.5 官网源码编译固件 创建日期:2023/04/05 修改日期:2024/10/27

OpenWrt作为旁路由配置Wireguard 实现内网穿透

yt-dlp详细使用教程参考,其中下载播放列表有效