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

已为老胡 2026-03-31 PM 3℃ 0条

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 客户端将在系统启动时自动连接。


# 启动

systemctl start wg-quick@wg0

# 停止

systemctl stop wg-quick@wg0

# 关闭开机自启动

systemctl disable wg-quick@wg0



检查 WireGuard 的连接状态:

sudo wg


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



启动与停止

在完成Wireguard安装、撰写配置文件完成后,我们可以通过命令启动我们的WireGuard


标签: none

非特殊说明,本博所有文章均为博主原创。

上一篇 wg-easy安装教程步骤
下一篇 没有了

评论啦~