Friday, March 29, 2024

服務器架設:安裝SoftEtherVPN Server For Linux

SoftEtherVPN是由日本筑波大學(University of Tsukuba)登 大遊 (Daiyu Nobori)在碩士論文中提出的開源、跨平台、多重協議的虛擬專用網方案。

本文以64位CentOS 7安裝環境為例,講解如何安裝SoftEtherVPN Server For Linux。

第一部分:安裝SoftEtherVPN Server

安裝編譯環境

yum -y install gcc

SoftEther下載中心下載SoftEtherVPN Server For Linux

wget https://www.softether-download.com/files/softether/v4.43-9799-beta-2023.08.31-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-x64-64bit.tar.gz

或者從GitHub下載SoftEtherVPN Server For Linux

wget https://github.com/SoftEtherVPN/SoftEtherVPN/releases/download/5.02.5181/SoftEtherVPN-5.02.5181.tar.xz

解壓文件

tar -zxvf softether-vpnserver-*.tar.gz

進入到解壓目錄

cd vpnserver

啟動安裝腳本

./.install.sh

閱讀License,根據提示,輸入“1”然後回車確認。

如果提示不識別某些命令比如gcc,另行安裝即可。如果沒有異常則說明安裝成功。

啟動服務

./vpnserver start

(停止服務命令為:./vpnserver stop)

在CentOS 7系統中可以用systemd啟動vpnserver,先新建啟動腳本/etc/systemd/system/vpnserver.service:

[Unit]
Description=SoftEther VPN Server
After=network.target

[Service]
Type=forking
ExecStart=/root/vpnserver/vpnserver start
ExecStop=/root/vpnserver/vpnserver stop

[Install]
WantedBy=multi-user.target

然後就可以通過systemctl start vpnserver啟動了,並通過systemctl enable vpnserver設置開機自啟。

啟動成功後我們需要設置遠程登錄密碼以便本地管理服務。運行下面的命令進入VPN的命令行:

./vpncmd

選擇1. Management of VPN Server or VPN Bridge

這裡需要選擇地址和端口。默認443端口,如果需要修改,可以輸入localhost:5555(實際端口),然後出現:

If connecting to the server by Virtual Hub Admin Mode, please input the Virtual Hub name.
If connecting by server admin mode, please press Enter without inputting anything.
Specify Virtual Hub Name:

這裡就是指定一個虛擬HUB名字,用默認的直接回車就行。

Connection has been established with VPN Server "localhost" (port 5555).

You have administrator privileges for the entire VPN Server.

VPN Server>

這時我們需要輸入ServerPasswordSet命令設置遠程管理密碼,確認密碼後就可以通過Windows版的SoftEther VPN Server Manager遠程管理了。

第二部分:VPN管理

首先下載並安裝SoftEther VPN Server Manager,安裝之後運行它:

在這裡點新建:

Host Name填服務器的地址或域名,端口如果之前改過了在這也記得改過來,右下角的密碼填之前設置過的密碼。新建完成後Connect就會彈出Easy Setup窗口(如果提示連不上請檢查一下服務器的防火牆設置):

這裡在第一個遠程連接挑鉤然後下一步即可,虛擬HUB名像之前一樣默認就好。

然後會彈出一個動態DNS功能的窗口,由於不能確定它給的域名是不是被牆了,我們就不去用它,把這個窗口關了就行了。

之後會有一個協議設置的窗口:

這裡把啟用L2TP挑上鉤,下面設置一個IPsec預共享密鑰就行了。

之後又會彈出一個VPN Azure Cloud服務的窗口,感覺沒什麼用,禁用了就行了。即使有用以後也可以再啟用。

接下來要新建用戶:

其中用戶名是必填的,驗證類型選密碼驗證就行,然後在右側設置用戶密碼。

之後回到管理界面,點管理虛擬HUB:

點虛擬NAT和虛擬DHCP服務器,彈出窗口:

在裡面啟用SecureNAT並點SecureNAT配置:

注意DNS要改為8.8.8.8和8.8.4.4。這裡就算配置完畢。然後順便生成一下OpenVPN的配置文件,點OpenVPN / MS-SSTP Setting:

然後點擊新窗口中部的按鈕生成配置文件:

打開導出的壓縮包會看到裡面有兩個.ovpn文件,一般我們要用到*_openvpn_remote_access_l3.ovpn這個文件,因為我們是通過IPv4地址管理的VPN,所以這個配置文件里的remote一項會是IPv4地址,如果需要使用IPv6的VPN就將其替換為相應的IPv6地址即可。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.