搜知小筑

牛马日记

飞牛安装Wireguard客户端,实现内网穿透以及虚拟局域

1. 安装 WireGuard

在 Debian 12 中,WireGuard 已包含在官方软件源中,可以直接使用 apt 进行安装:

sudo apt update
sudo apt install wireguard -y
2. 创建 WireGuard 客户端配置文件

WireGuard 需要一个配置文件来连接到服务器。可以手动创建配置文件,也可以使用服务端提供的客户端配置文件。

手动创建配置文件
创建配置文件目录和配置文件:

sudo mkdir -p /etc/wireguard
sudo nano /etc/wireguard/wg0.conf

在 wg0.conf 文件中添加以下内容,将其中的参数替换为实际的服务器和客户端信息:

[Interface]
PrivateKey = 客户端私钥
Address = 客户端IP/24 # 例如 10.0.0.2/24
[Peer]
PublicKey = 服务器公钥
Endpoint = 服务器IP:服务器端口 # 例如 198.51.100.1:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25 # 可选项,保持连接活跃
  • PrivateKey:客户端私钥(生成方法见下方)。

  • PublicKey:服务端的公钥。

  • Endpoint:服务端的 IP 和端口。

  • AllowedIPs:可以是 0.0.0.0/0, ::/0,表示允许通过 VPN 访问所有流量,或仅指定特定 IP。


(备注 将服务端生成的信息复制到 wg0.conf 文件中,删除DDNS信息)

启动 WireGuard 客户端

保存并退出配置文件后,使用以下命令启动 WireGuard 客户端:

sudo wg-quick up wg0

如果想要关闭连接:

sudo wg-quick down wg0

设置开机启动(可选)

如果希望 WireGuard 客户端在开机时自动启动,可以执行以下命令:

sudo systemctl enable wg-quick@wg0

这样 WireGuard 客户端将在系统启动时自动连接。

测试连接

检查 WireGuard 的连接状态:

sudo wg


这会显示当前 WireGuard 的连接状态及流量情况。

«    2025年9月    »
1234567
891011121314
15161718192021
22232425262728
2930
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
    文章归档
    网站收藏
    友情链接

    Powered By Z-BlogPHP 1.7.4

    Copyright SoSo.Show.Some Rights Reserved.
    粤ICP备2025450197号