Ubuntu和Debian8+ 上一键安装并配置 WireGuard

在Ubuntu和Debian 8+上,你可以使用以下步骤一键安装并配置WireGuard:,,1. 更新系统软件包列表:,“sudo apt update,`,,2. 安装WireGuard软件包:,`sudo apt install wireguard,`,,3. 生成WireGuard配置文件和密钥:,`,sudo wg genkey | sudo tee /etc/wireguard/privatekey | sudo wg pubkey > /etc/wireguard/publickey,`,,4. 创建WireGuard配置文件:,`,sudo nano /etc/wireguard/wg0.conf,`,,5. 将以下内容粘贴到配置文件中,然后保存并关闭文件:,`,[Interface],PrivateKey = /etc/wireguard/privatekey,Address = 10.0.0.1/24,ListenPort = 51820,,[Peer],PublicKey = /etc/wireguard/publickey,AllowedIPs = 10.0.0.2/32,Endpoint = peer.example.com:51820,PersistentKeepalive = 25,`,,6. 启动WireGuard服务:,`,sudo systemctl enable wg-quick@wg0,sudo systemctl start wg-quick@wg0,`,,7. 确认WireGuard服务已启动:,`,sudo systemctl status wg-quick@wg0,“,,现在,WireGuard已在Ubuntu和Debian 8+上安装并配置完成。

Ubuntu和Debian8+ 上一键安装并配置 WireGuard

1. 安装 WireGuard

Ubuntu和Debian8+ 上一键安装并配置 WireGuard

在 Ubuntu 或 Debian 8+ 系统上,可以使用以下命令来安装 WireGuard:

sudo aptget update
sudo aptget install wireguard

2. 生成密钥对

WireGuard 使用公钥和私钥来进行身份验证和加密,你需要为你的 WireGuard 客户端和服务器生成密钥对,可以使用以下命令生成:

wg genkey | tee privatekey | wg pubkey > publickey

这将生成一对公钥和私钥,并将它们分别保存在 privatekeypublickey 文件中。

3. 配置 WireGuard 服务器

在服务器上,需要创建一个配置文件来设置 WireGuard,可以使用以下命令创建一个新的配置文件:

sudo nano /etc/wireguard/wg0.conf

将以下内容粘贴到配置文件中,替换 <your_public_key><your_private_key> 为你在第2步中生成的公钥和私钥:

Ubuntu和Debian8+ 上一键安装并配置 WireGuard

[Interface]
PrivateKey = <your_private_key>
ListenPort = 51820
Address = 10.0.0.1/24
[Peer]
PublicKey = <your_public_key>
AllowedIPs = 10.0.0.2/32

保存并关闭文件,使用以下命令启动 WireGuard 服务器:

sudo systemctl start wgquick@wg0
sudo systemctl enable wgquick@wg0

4. 配置 WireGuard 客户端

在客户端上,也需要创建一个配置文件来设置 WireGuard,可以使用以下命令创建一个新的配置文件:

nano /etc/wireguard/wg0.conf

将以下内容粘贴到配置文件中,替换 <your_public_key><your_private_key> 为你在第2步中生成的公钥和私钥,以及 <your_server_ip> 为你的 WireGuard 服务器的 IP 地址:

[Interface]
PrivateKey = <your_private_key>
Address = 10.0.0.2/32
DNS = 8.8.8.8,8.8.4.4
[Peer]
PublicKey = <your_public_key>
AllowedIPs = 0.0.0.0/0,::/0
Endpoint = <your_server_ip>:51820
PersistentKeepalive = 25

保存并关闭文件,使用以下命令启动 WireGuard 客户端:

sudo systemctl start wgquick@wg0

现在,你应该能够在 WireGuard 服务器和客户端之间建立连接了。

常见问题与解答

Ubuntu和Debian8+ 上一键安装并配置 WireGuard

Q1: 如何查看 WireGuard 的状态?

A1: 可以使用以下命令查看 WireGuard 的状态:

sudo systemctl status wgquick@wg0

Q2: 如果我想更改 WireGuard 的配置,应该怎么做?

A2: 你可以直接编辑 /etc/wireguard/wg0.conf 文件来更改 WireGuard 的配置,完成更改后,需要重新启动 WireGuard 服务以应用更改:

sudo systemctl restart wgquick@wg0

原创文章,作者:酷盾叔,如若转载,请注明出处:https://www.kdun.com/ask/376634.html

(0)
酷盾叔订阅
上一篇 2024-03-23 07:58
下一篇 2024-03-23 07:59

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入