WireGuard 是一种新的开源 VPN 协议,旨在提供更安全、更快、更简单的 VPN 体验。它使用最新的加密技术,并具有小型且易于审核的代码库。它重量轻,开销最小,可在各种平台上运行,并且设计得非常快。
第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:
sudo dnf check-update sudo dnf install dnf-utils sudo dnf install epel-release elrepo-release
第 2 步。启用线卫内核模块。
现在使用以下命令启用 Wirguard 内核模块:
sudo echo wireguard > /etc/modules-load.d/wireguard.conf
第 3 步。在 Rocky Linux 9 上安装 Wireguard VPN。
默认情况下,Wireguard 在 Rocky Linux 9 AppStream 存储库中可用。现在运行以下命令,在Rocky Linux系统上安装最新版本的Wireguard:
sudo dnf install wireguard-tools
第 4 步。生成服务器和客户端密钥对。
生成服务器密钥对
现在运行 \’\’ 命令以生成服务器私钥 \’\’。然后,将默认权限更改为“”以禁用从其他人和组写入和执行:wg genkey
/etc/wireguard/server.key
0400
wg genkey | sudo tee /etc/wireguard/server.key sudo chmod 0400 /etc/wireguard/server.key
之后,运行以下命令为 Wireguard 服务器 \’\’ 生成公钥:/etc/wireguard/server.pub
sudo cat /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub
验证 Wireguard 服务器的公钥和私钥:
cat /etc/wireguard/server.key cat /etc/wireguard/server.pub
现在运行以下命令以创建新目录 \’\’。此目录将用于存储客户端密钥对:/etc/wireguard/clients
mkdir -p /etc/wireguard/clientswg genkey | tee /etc/wireguard/clients/client1.keycat /etc/wireguard/clients/client1.key | wg pubkey | tee /etc/wireguard/clients/client1.pub
验证客户端的公钥和私钥:
cat /etc/wireguard/clients/client1.key cat /etc/wireguard/clients/client1.pub
第5步。配置线卫服务器。
现在在目录中创建一个新的 WireGuard 配置文件。您可以通过在终端中运行以下命令来创建文件:/etc/wireguard
nano /etc/wireguard/wg0.conf
添加以下行:
[Interface] # Wireguard Server private key - server.key PrivateKey = G0detzbW8wqTQDbU/KITGMeyzWVohVZsi2o4w= # Wireguard interface will be run at 10.8.0.1 Address = 10.8.0.1/24 # Clients will connect to UDP port 51820 ListenPort = 51820 # Ensure any changes will be saved to the Wireguard config file SaveConfig = true
接下来,添加以下行以定义客户端-对等连接:
[Peer] # Wireguard client public key - client1.pub PublicKey = meYl4na+QK4185xOkimp0iXYo1jGyiyI0okT0= # clients\' VPN IP addresses you allow to connect # possible to specify subnet ⇒ [172.16.100.0/24] AllowedIPs = 10.8.0.8/24
第 6 步。启用端口转发。
要配置转发并允许来自 WireGuard 网络的路由流量,请打开并编辑文件:/etc/sysctl.conf
nano /etc/sysctl.conf
将以下行添加到行的底部:
# Port Forwarding for IPv4 net.ipv4.ip_forward=1 # Port forwarding for IPv6 net.ipv6.conf.all.forwarding=1
保存文件并退出文件,然后运行以下 \’\’ 命令以对 \’ 文件应用更改:sysctl
/etc/sysctl.conf\'
sudo sysctl -p
步骤 7.配置防火墙。
现在我们允许 UDP 端口 51820 上的 WireGuard 流量:
sudo firewall-cmd --add-port=51820/udp --permanent sudo firewall-cmd --reload
通过以下防火墙-cmd 命令验证防火墙规则:
sudo firewall-cmd --list-all
第8步。启动线卫服务器。
可以将 WireGuard 配置为使用其内置脚本作为服务运行。运行以下命令实用程序以启动并启用 Wireguard 服务器:systemd
wg-quick
systemctl
sudo systemctl start wg-quick@wg0.service sudo systemctl enable wg-quick@wg0.service
第9步。连接 WireGuard 客户端。
WireGuard 客户端应用程序可在多个操作系统上使用。您可以设置另一个Rocky Linux服务器作为对等服务器,也可以下载WireGuard客户端应用程序来连接您的iOS,Android,macOS,Linux或Windows操作系统。
感谢您使用本教程在您的 Rocky Linux 9 系统上安装 Wireguard VPN。有关其他帮助或有用信息,我们建议您查看官方Wireguard网站。