如何在 AlmaLinux 8 上安装 OpenVPN 服务器

在本教程中,我们将向您展示如何在 AlmaLinux 8 上安装 OpenVPN 服务器。对于那些不知道的人,OpenVPN 是一个强大且高度灵活的开源 VPN 软件,它使用所有的加密、身份验证和OpenSSL 库的认证功能可通过单个 UDP 或 TCP 端口安全地隧道 IP 网络。 VPN 使我们能够安全地连接到不安全的公共网络,例如机场或酒店的 wifi 网络。 通常,企业和企业用户需要某种 VPN 才能访问您办公室托管的服务。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 AlmaLinux 8 上逐步安装 OpenVPN。您可以按照 CentOS 和 Rocky Linux 的相同说明进行操作。

在 AlmaLinux 8 上安装 OpenVPN 服务器

第 1 步。首先,让我们首先确保您的系统是最新的。

sudo dnf update sudo dnf install epel-release

步骤 2. 在 AlmaLinux 8 上安装 OpenVPN 服务器。

安装 OpenVPN 服务器很简单,现在运行以下命令从 GitHub 页面下载安装程序 OpenVPN:

curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh

下载文件后,使其可执行并运行它:

chmod +x openvpn-install.sh ./openvpn-install.sh

该脚本将通过一系列问题开始安装过程,然后是提示和您的回复:

在 AlmaLinux 8 上安装 OpenVPN 服务器

在 AlmaLinux 8 上安装 OpenVPN 服务器

之后,添加一个新客户端,您将看到以下输出屏幕,您必须在其中定义客户端名称:

Okay, that was all I needed. We are ready to setup your OpenVPN server now. You will be able to generate a client at the end of the installation. Press any key to continue...  Tell me a name for the client. The name must consist of alphanumeric character. It may also include an underscore or a dash. Client name: meilanamaria

接下来,将询问您是否要使用密码保护配置文件:

Do you want to protect the configuration file with a password? (e.g. encrypt the private key with a password)    1) Add a passwordless client    2) Use a password for the client Select an option [1-2]: 1

最后,您将被告知该过程已成功:

Client meilanamaria added.  The configuration file has been written to /home/user/idroot.ovpn. Download the .ovpn file and import it in your OpenVPN client.

步骤 3. 将客户端连接到 OpenVPN 服务器

安装成功后,下载 .ovpn 客户端文件。 如果您使用的是 OpenVPN 客户端的 shell 版本(无 GUI),为了连接,只需在终端中使用 .ovpn 客户端配置 fike 的文件名和位置运行 OpenVPN:

openvpn meilanamaria.ovpn

步骤 4. 配置防火墙。

AlmaLinux 自带一个开箱即用的活动防火墙,它会在第一次启动时处于运行状态,因此为了能够与 OpenVPN 服务器建立连接,您需要添加防火墙规则以允许 OpenVPN 连接服务器:

sudo firewall-cmd --zone=trusted --add-service=openvpn sudo firewall-cmd --zone=trusted --permanent --add-service=openvpn sudo firewall-cmd --add-masquerade sudo firewall-cmd --permanent --add-masquerade sudo firewall-cmd --zone=trusted --permanent --add-port=1194/udp sudo firewall-cmd --reload

恭喜! 您已成功安装 OpenVPN。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 OpenVPN 服务器。 如需更多帮助或有用信息,我们建议您查看 官方 OpenVPN 网站.