如何在 AlmaLinux8 上安裝 OpenVPN 服務器


本教程將向您展示如何在 AlmaLinux8 上安裝 OpenVPN 服務器。對於那些不知道的人,OpenVPN 是一款功能強大且靈活的開源 VPN 軟件,它通過單個 UDP 或 TCP 端口使用 OpenSSL 庫的所有加密、身份驗證和身份驗證功能,為您的 IP 網絡建立安全隧道。 VPN 允許您安全地連接到不安全的公共網絡,例如機場和酒店 Wi-Fi 網絡。企業和企業用戶通常需要某種 VPN 來訪問辦公室託管的服務。

本文假設您至少具有 Linux 的基本知識,知道如何使用 shell,最重要的是,將您的網站託管在您的 VPS 上。安裝非常簡單,假設您在 root 帳戶下運行。如果沒有,您需要添加一個’。sudo‘向命令獲取root權限。 我們將引導您完成在 AlmaLinux8 上安裝 OpenVPN。 對於 CentOS 和 Rocky Linux,您可以按照相同的步驟進行操作。

在 AlmaLinux8 上安裝 OpenVPN 服務器

步驟1。首先,確保您的系統是最新的。

sudo dnf update
sudo dnf install epel-release

步驟 2. 在 AlmaLinux8 上安裝 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

該腳本以一系列問題開始安裝過程,然後是提示和響應。

在 AlmaLinux8 上安裝 OpenVPN 服務器

在 AlmaLinux8 上安裝 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 客戶端配置的文件名和位置運行 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 現已成功安裝。感謝您使用本教程在您的 AlmaLinux8 系統上安裝 OpenVPN 服務器。我們鼓勵您查看更多幫助和有用信息。 OpenVPN官網..