OpenVPN 是一个强大且高度灵活的开源 VPN 软件,它使用所有加密、身份验证和OpenSSL 库的认证功能,可通过单个 UDP 或 TCP 端口安全地隧道 IP 网络。VPN 使我们能够安全地连接到不安全的公共网络,例如机场或酒店的 wifi 网络。通常,商业和企业用户需要某种 VPN 才能访问您办公室托管的服务。OpenVPN-logo-3OpenVPN-logo-3

在 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

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

install-openvpn-server-on-almalinux-1-1install-openvpn-server-on-almalinux-1-1

install-openvpn-server-on-almalinux-2-1install-openvpn-server-on-almalinux-1-1

install-openvpn-server-on-almalinux-3-1install-openvpn-server-on-almalinux-1-1

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

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 客户端配置文件的文件名和位置运行 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

感谢您使用本教程在您的 AlmaLinux 8 系统上安装 OpenVPN 服务器。如需其他帮助或有用信息,我们建议您查看官方 OpenVPN 网站。