Centos7上openVP的另一種使用方式,實現訪問控制!

首先跟大家說一下這次和第一篇open的主要區別在於第一篇屬於訪問整個內網,而今天這篇只是針對於指定用戶的指定網段,相對來說這篇的訪問方式更加的安全。而且這兩篇最大的區別主要是配置文件,所以安裝過程等,可以省略不看,但是爲了讓對於open安裝相對陌生的人考慮,所以還是將完整的過程記錄如下:

一、安裝軟件包

1、更新源

yum upgrade

2、裝epel庫

yum -y install epel-release

3、安裝依賴包

yum -y install open openssh-server lzo openssl openssl-devel NetworkManager-open open**-auth-ldap

4、手動下載easy-rsa 想要生成各種證書和密鑰,我們還要用到easy-rsa(只有服務器端需要easy-rsa,客戶端無需安裝)。坑爹的是,Open 2.3.x並沒有自帶這個東西,我們還需要去GitHub下載easy-rsa。更坑爹的是,GitHub上的easy-rsa已經升級到了3.0版本,該版本幾乎重寫了之前所有的程序代碼,連使用方法都全變了,然Open的官方文檔並沒有作相應更新,其中介紹的仍然是easy-rsa 2.0的操作方法。爲了避免不必要的麻煩,我們推薦下載2.0版本的easy-rsa,你也可以直接點擊這裏下載。

1)在這裏我們將下載的easy-rsa-release-2.x.zip上傳並解壓放在/usr/local/open/目錄下(這裏open目錄是新建的)
Centos7上openVP的另一種使用方式,實現訪問控制!

2)拷貝/usr/local/open/easy-rsa-release-2.x/easy-rsa/ 到/etc/open/目錄下
cp -r /usr/local/open/easy-rsa-release-2.x/easy-rsa/ /etc/open/
Centos7上openVP的另一種使用方式,實現訪問控制!

5、拷貝配置文件

cp /usr/share/doc/open-2.4.4/sample/sample-config-files/server.conf /etc/open/
Centos7上openVP的另一種使用方式,實現訪問控制!

6、備份open**配置文件

cp /etc/open/server.conf /etc/open/server.conf.back
Centos7上openVP的另一種使用方式,實現訪問控制!

//查看 ls /etc/open**/
Centos7上openVP的另一種使用方式,實現訪問控制!

7、創建ccd目錄(指定用戶訪問指定網段)

mkdir -p /etc/open**/ccd/
Centos7上openVP的另一種使用方式,實現訪問控制!

8、在/etc/open**/ccd/目錄創建兩個指定用戶分別訪問指定網段

Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
註釋:
push route: 指定當前用戶能訪問的內網網段
iroute :指定當前用戶**訪問內網時所走的路由網段(這條加不加都行,不加走默認的路由)

9、編輯open**配置文件

vi /etc/open**/server.conf
Centos7上openVP的另一種使用方式,實現訪問控制!
注:這裏使用的是udp協議(tcp協議在網絡較弱時容易斷線)

二、配置證書

1、編輯vars文件

vi /etc/open**/easy-rsa/2.0/vars
Centos7上openVP的另一種使用方式,實現訪問控制!

2、製作證書

1)切換目錄讓配置文件生效(根據截圖提示按步驟操作)先執行 source ./vars,然後根據提示執行./clean-all,然後創建ca證書./build-ca後按回車鍵,一直到結束。
Centos7上openVP的另一種使用方式,實現訪問控制!

2)創建服務端證書
執行命令./build-key-server server 按回車鍵進行,最後輸入兩次“y”回車。
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!

3)創建客戶端證書
執行命令生成迪菲•赫爾曼交換密鑰./build-dh 創建祕鑰文件,等待命令執行完。
Centos7上openVP的另一種使用方式,實現訪問控制!

4)查看目錄中創建好的證書文件 ls keys/
Centos7上openVP的另一種使用方式,實現訪問控制!

5)創建客戶端證書文件(在/etc/open**/easy-rsa/2.0/下執行)
執行命令./build-key wangfeiyu創建客戶端證書文件,按回車進行,提示輸入密碼的地方,輸入之前設置的證書密碼feiyu,An optional company name處輸入先前設置的公司名字(xingyoucai.com)。【一定要和先前輸入的一樣,其他參數如果前面設置了,也要保持一致噢】 另外注意:有多少個客戶端就需要./build-key client 多少次,當然client名字需不同。而且創建服務端證書時可以不設置用戶密碼,那麼後邊創建客戶端證書也就不用輸入用戶密碼了。
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!

//創建第二個客戶端證書文件 ./build-key xiaohong
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!

6)查看證書 ls keys/
Centos7上openVP的另一種使用方式,實現訪問控制!

7)爲了日後使用**人員較多,方便管理,實現人名目錄制,如下:
Centos7上openVP的另一種使用方式,實現訪問控制!

三、設置iptables、路由轉發

1、安裝iptables

yum -y install iptables-services

2、設置iptables開機自啓

systemctl enable iptables

3、關閉Centos7默認的 firewall防火牆

systemctl stop firewalld

4、關閉Centos7默認的 firewall防火牆開機自啓

systemctl disable firewalld

5、啓動iptables

systemctl start iptables

6、清空iptables默認規則

iptables –F iptables –X iptables -Z

7、設置iptables NAT轉發規則

iptables -t nat -A POSTROUTING -s 10.0.100.0/24 -j MASQUERADE
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
注:保存防火牆規則service iptables save(防止重啓規則丟失)
Centos7上openVP的另一種使用方式,實現訪問控制!

8、開啓路由轉發

vi /etc/sysctl.conf
Centos7上openVP的另一種使用方式,實現訪問控制!

驗證: sysctl -p
Centos7上openVP的另一種使用方式,實現訪問控制!

四、啓動open**

1、設置啓動文件

systemctl -f enable open**@server.service
Centos7上openVP的另一種使用方式,實現訪問控制!

2、啓動open**的命令

systemctl start open**@server.service
Centos7上openVP的另一種使用方式,實現訪問控制!

3、打開iptables防火牆的1194端口

iptables -A INPUT -p udp --destination-port 1194 -j ACCEPT
Centos7上openVP的另一種使用方式,實現訪問控制!

4、查看open**服務運行(centos7需要安裝net-tools)

netstat –antulp
Centos7上openVP的另一種使用方式,實現訪問控制!

5、open客戶端(電腦、手機)連接使用telnet命令連接**1194端口

五、配置客戶端實現連接

1、把服務器上的四個客戶端證書文件,下載到本地電腦配置**客戶端。

/etc/open**/easy-rsa/keys/ca.crt

/etc/open**/easy-rsa/keys/wangfeiyu.crt

/etc/open**/easy-rsa/keys/wangfeiyu.key

/etc/open**/easy-rsa/keys/wangfeiyu.csr(這條可加可不加,以上邊三條爲主)

2、安裝好open客戶端軟件後,把證書文件,存放到open安裝目錄的config文件夾下。 從sample-config文件夾下,拷貝客戶端的配置文件client.o**到config文件夾下。

Centos7上openVP的另一種使用方式,實現訪問控制!

3、編輯config文件夾下的配置文件client.o**,修改remote my-server-1 1194 這行配置,指定open服務器的ip地址,默認爲你服務器的外IP然後修改協議。需要注意的是:在服務器端的配置需要和客戶端的配置參數一致。

Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!

4、客戶端連接,右擊軟件生成的運行圖標,點擊連接。

Centos7上openVP的另一種使用方式,實現訪問控制!
Centos7上openVP的另一種使用方式,實現訪問控制!
注:這篇open與第一篇看起來區別不大,但是這個更完美的實現了具體用戶具體網段的訪問控制!而且需要特別注意,並不是看到如上截圖顯示分到IP就確定openvp沒問題了,最主要是需要在客戶端使用route print(windows命令)查看是否有後端推送的IP,如果沒有,那麼有可能是因爲推送IP命令錯誤或者子網掩碼錯誤。

測試:

1、先用wangfeiyu密鑰使用**訪問公司內網

Centos7上openVP的另一種使用方式,實現訪問控制!
注:需要特別注意,並不是看到如上截圖顯示分到IP就確定openvp沒問題了,最主要是需要在客戶端使用route print(windows命令)查看是否有後端推送的IP,如果沒有,那麼有可能是因爲推送IP命令錯誤或者子網掩碼錯誤

2、再用xiaohong密鑰使用**訪問公司內網

Centos7上openVP的另一種使用方式,實現訪問控制!
注:需要特別注意,並不是看到如上截圖顯示分到IP就確定openvp沒問題了,最主要是需要在客戶端使用route print(windows命令)查看是否有後端推送的IP,如果沒有,那麼有可能是因爲推送IP命令錯誤或者子網掩碼錯誤

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章