open***服務器配置詳解

1、open***介紹與圖解

1.1      open***介紹

Open*** 是一個基於 OpenSSL庫的應用層 *** 實現。和傳統 *** 相比,它的優點是簡單易用。***直譯就是虛擬專用通道,是提供企業之間或者公司之間安全數據傳輸的隧道。Open***是一個全特性的SSL ***,它使用2層或3層的安全網絡技術,使用的是工業標準的SSL/TLS協議。SSL(Secure Sockets Layer 安全套接層),及其繼任者傳輸層安全(TransportLayer SecurityTLS)是爲網絡通信提供安全及數據完整性的一種安全協議。Open***支持靈活的客戶端授權方式,支持證書、智能卡、用戶名和密碼,允許用戶可以通過防火牆連接到***的虛擬接口,Open***不是一個基於web代理的應用,也不是基於瀏覽器訪問。

1.2      open***使用場景

a)      企業員工遠程辦公,通過遠程***連接到公司的服務器,訪問公司ERPOA等系統。IT技術人員通過***遠程連接到機房進行系統維護。

b)      總部與分支機構之間聯通,打通分支與總部的連接

c)      IDC機房之間的互聯,實現多機房之間的互聯互通,數據共享,文件傳送

注意:Open***適用於功能性實現,對於大流量大帶寬應用,建議使用點對點專線實現互聯



2、open***服務端安裝與配置

2.1      環境介紹

實現模擬Open***功能的實驗環境介紹:

使用兩臺內網內段192.168.3.0/24的機器模擬公網環境,左側的lclient與右側的lanserver在不同的網段,正常情況下不能通信



wKioL1eYUTWxnsbKAAjbc4fW37Y331.png-wh_50

本次實驗使用***client的另外一個接口eth1模擬lclient,IP地址爲10.0.0.17

2.2      基礎環境配置及依賴包安裝

2.2.1   開啓內核參數ip轉發

***server上開啓ip轉發功能,編輯/etc/sysctl.conf,修改net.ipv4.ip_forward1

net.ipv4.ip_forward = 1

使用-p選項使參數修改生效

[root@***server ~]# sysctl -p
net.ipv4.ip_forward = 1

2.2.2   停止iptables

在全部測試完成前,暫時先停掉iptables,以防止由於iptables的原因造成的問題,全部調試完成後再對iptables進行設置

[root@***server ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [ OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@***server ~]# /etc/init.d/iptables stop

2.2.3   安裝基礎依賴包

安裝openssl相關的依賴包

yum install openssl* -y

2.2.4   更新系統時間

使用ntp同步系統時間

ntpdate -u pool.ntp.org

制定計劃任務,每隔5分鐘進行時間同步

echo '#sync system date from ntpserver'>>/var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate -u pool.ntp.org >/dev/null 2>&1' >>/var/spool/cron/root

檢查配置信息

[root@***server ~]# crontab -l
#sync system date from ntpserver
*/5 * * * * /usr/sbin/ntpdate -u pool.ntp.org >/dev/null 2>&1


2.3      安裝lzo

創建相應的安裝包目錄

mkdir -p /server/tools
cd /server/tools/

將相應的安裝包上傳至tools目錄

[root@***server tools]# ll
total 1476
-rw-r--r--. 1 root root 594855 Jul 5 08:33 lzo-2.09.tar.gz
-rw-r--r--. 1 root root 911158 Jul 5 08:33 open***-2.2.2.tar.gz

安裝lzo源碼包

cd /server/tools/
tar xf lzo-2.09.tar.gz
cd lzo-2.09
./configure
make
make install

 

2.4   安裝open***軟件

2.4.1   源碼包安裝

版本選擇:目前最新的版本爲2.3.1,本次選用Linux客戶端和服務端的版本爲2.2.2windows客戶端軟件依然使用的是2.3.1

解壓安裝Open***源碼包

mkdir /application
tar xf open***-2.2.2.tar.gz -C /application/
cd /application/open***-2.2.2/
./configure --with-lzo-lib=/usr/local/lib--with-lzo-headers=/usr/local/include
make
make install

檢查安裝結果

[root@***server open***-2.2.2]# which open***
/usr/local/sbin/open***

生成軟鏈接

ln -s /application/open***-2.2.2/ /application/open***

2.4.2   生成CA證書

進入製作證書所在目錄,後續很多的操作都在此目錄

cd /application/open***-2.2.2/easy-rsa/2.0
[root@***server 2.0]# ll
total 128
-rwxrwxr-x. 1 sunny sunny  119 Nov 25  2011 build-ca   #生成CA證書
-rwxrwxr-x. 1 sunny sunny  352 Nov 25  2011 build-dh  #生成密碼協議交換文件
-rwxrwxr-x. 1 sunny sunny  188 Nov 25  2011 build-inter
-rwxrwxr-x. 1 sunny sunny  163 Nov 25  2011 build-key        #生成免密碼客戶端密鑰對
-rwxrwxr-x. 1 sunny sunny  157 Nov 25  2011 build-key-pass   #生成帶密碼客戶端密鑰對
-rwxrwxr-x. 1 sunny sunny  249 Nov 25  2011 build-key-pkcs12
-rwxrwxr-x. 1 sunny sunny  268 Nov 25  2011 build-key-server    #生成服務端密鑰對
-rwxrwxr-x. 1 sunny sunny  213 Nov 25  2011 build-req
-rwxrwxr-x. 1 sunny sunny  158 Nov 25  2011 build-req-pass
-rwxrwxr-x. 1 sunny sunny  428 Nov 25  2011 clean-all     #初始化配置,清空所有keys
-rwxrwxr-x. 1 sunny sunny 1457 Nov 25  2011 inherit-inter
-rwxrwxr-x. 1 sunny sunny  295 Nov 25  2011 list-crl
-rw-rw-r--. 1 sunny sunny  413 Nov 25  2011 Makefile
-rwxrwxr-x. 1 sunny sunny 7768 Oct 21  2010openssl-0.9.6.cnf
-rwxrwxr-x. 1 sunny sunny 8325 Nov 25  2011openssl-0.9.8.cnf
-rwxrwxr-x. 1 sunny sunny 8222 Nov 25  2011openssl-1.0.0.cnf
-rwxrwxr-x. 1 sunny sunny 12675 Nov 25  2011 pkitool    #各證書生成主要調用此命令執行
-rw-rw-r--. 1 sunny sunny 9299 Nov 25  2011 README
-rwxrwxr-x. 1 sunny sunny  918 Nov 25  2011 revoke-full     #證書吊銷
-rwxrwxr-x. 1 sunny sunny  178 Nov 25  2011 sign-req
-rwxrwxr-x. 1 sunny sunny 1841 Nov 25  2011 vars       #預先定義的證書基本信息
-rwxrwxr-x. 1 sunny sunny  714 Nov 25  2011 whichopensslcnf

修改證書預定義信息vars

首先對vars進行備份

cp vars vars.sunny.ori

編輯最後11行修改爲如下內容:

export KEY_COUNTRY="CN"
export KEY_PROVINCE="HB"
export KEY_CITY="WuHan"
export KEY_ORG="sunny"
export KEY_EMAIL="[email protected]"
export [email protected]
export KEY_CN=sunny
export KEY_NAME=sunny
export KEY_OU=sunny
export PKCS11_MODULE_PATH=changeme
export PKCS11_PIN=1234

注意:如果是AD或者ldap請根據自身內容進行填寫

載入vars配置,新開窗口製作證書時,需要重新加載vars文件

[root@***server 2.0]# source vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on/application/open***-2.2.2/easy-rsa/2.0/keys

第一次會提示初始化配置,按提示操作,後續正常使用時不可執行此操作,它會清空keys目錄,並初始化序列

[root@***server 2.0]# ./clean-all
[root@***server 2.0]# ll keys/
total 4
-rw-r--r--. 1 root root 0 Jul 7 16:57 index.txt
-rw-r--r--. 1 root root 3 Jul 7 16:57 serial

製作CA證書,由於已經預先定義好了各個配置,一路回車,表示使用默認配置

[root@***server 2.0]# ./build-ca
Generating a 1024 bit RSA private key
...++++++
......................................++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will beincorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Nameor a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [HB]:
Locality Name (eg, city) [WuHan]:
Organization Name (eg, company) [sunny]:
Organizational Unit Name (eg, section) [sunny]:
Common Name (eg, your name or your server's hostname) [sunny]:
Name [sunny]:
Email Address [[email protected]]:

查看生成的證書文件,ca.crt就是新生成的證書文件,ca.key就是私鑰

[root@***server 2.0]# ls -l keys
total 12
-rw-r--r--. 1 root root 1277 Jul 7 16:58 ca.crt   CA證書文件
-rw-------. 1 root root  916Jul  7 16:58 ca.key          CA的私鑰
-rw-r--r--. 1 root root    0Jul  7 16:57 index.txt
-rw-r--r--. 1 root root    3Jul  7 16:57 serial

 

2.4.3   生成服務端證書與密鑰

生成服務端證書調用的命令爲build-key-server,後面直接跟服務端證書名即可,這裏服務端證書名取爲server

[root@***server 2.0]# ./build-key-server server
Generating a 1024 bit RSA private key
....................++++++
............................................++++++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will beincorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Nameor a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [HB]:
Locality Name (eg, city) [WuHan]:
Organization Name (eg, company) [sunny]:
Organizational Unit Name (eg, section) [sunny]:
Common Name (eg, your name or your server's hostname) [server]:
Name [sunny]:
Email Address [[email protected]]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:sunny
Using configuration from/application/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName          :PRINTABLE:'CN'
stateOrProvinceName  :PRINTABLE:'HB'
localityName         :PRINTABLE:'WuHan'
organizationName     :PRINTABLE:'sunny'
organizationalUnitName:PRINTABLE:'sunny'
commonName            :PRINTABLE:'server'
name                 :PRINTABLE:'sunny'
emailAddress         :IA5STRING:'[email protected]'
Certificate is to be certified until Jul  5 09:04:46 2026 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

着色的是手動輸入的,需要兩次確認

檢查生成的證書密鑰對

[root@***server 2.0]# ll keys/server*
-rw-r--r--. 1 root root 3943 Jul 7 17:04 keys/server.crt    #服務端證書
-rw-r--r--. 1 root root  757Jul  7 17:04 keys/server.csr  #服務端證書請求文件
-rw-------. 1 root root  916Jul  7 17:04 keys/server.key  #服務端私鑰


2.4.4   生成客戶端證書與密鑰

客戶端生成證書是與客戶的賬號是一一對應的,每一個賬號對應一個服務端證書文件

生成一個無密碼驗證密鑰,使用命令build-key

新建一個test客戶端密鑰,此賬號無需密碼驗證

[root@***server 2.0]# ./build-key test
Generating a 1024 bit RSA private key
.....................................++++++
..++++++
writing new private key to 'test.key'
-----
You are about to be asked to enter information that will beincorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Nameor a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [HB]:
Locality Name (eg, city) [WuHan]:
Organization Name (eg, company) [sunny]:
Organizational Unit Name (eg, section) [sunny]:
Common Name (eg, your name or your server's hostname) [test]:
Name [sunny]:
Email Address [[email protected]]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:sunny
Using configuration from/application/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName          :PRINTABLE:'CN'
stateOrProvinceName  :PRINTABLE:'HB'
localityName         :PRINTABLE:'WuHan'
organizationName     :PRINTABLE:'sunny'
organizationalUnitName:PRINTABLE:'sunny'
commonName           :PRINTABLE:'test'
name                 :PRINTABLE:'sunny'
emailAddress         :IA5STRING:'[email protected]'
Certificate is to be certified until Jul  5 09:13:01 2026 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

生成一個需要密碼驗證的客戶端密鑰sunny,密碼爲123456,生產環境此密碼需要設置較複雜

[root@***server 2.0]# ./build-key-pass sunny
Generating a 1024 bit RSA private key
...++++++
...............................................++++++
writing new private key to 'sunny.key'
Enter PEM pass phrase:                         #此處需要輸入用戶密碼
Verifying - Enter PEM pass phrase:     #此處需要確認用戶密碼
-----
You are about to be asked to enter information that will beincorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Nameor a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [HB]:
Locality Name (eg, city) [WuHan]:
Organization Name (eg, company) [sunny]:
Organizational Unit Name (eg, section) [sunny]:
Common Name (eg, your name or your server's hostname) [sunny]:
Name [sunny]:
Email Address [[email protected]]:
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:sunny
Using configuration from/application/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName          :PRINTABLE:'CN'
stateOrProvinceName  :PRINTABLE:'HB'
localityName         :PRINTABLE:'WuHan'
organizationName      :PRINTABLE:'sunny'
organizationalUnitName:PRINTABLE:'sunny'
commonName           :PRINTABLE:'sunny'
name                 :PRINTABLE:'sunny'
emailAddress         :IA5STRING:'[email protected]'
Certificate is to be certified until Jul  5 09:16:29 2026 GMT (3650 days)
Sign the certificate? [y/n]:
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

查看生成的客戶端密鑰

[root@***server 2.0]# ls -l keys/{test,sunny}*
-rw-r--r--. 1 root root 3821 Jul 7 17:16 keys/sunny.crt
-rw-r--r--. 1 root root  757Jul  7 17:16 keys/sunny.csr
-rw-------. 1 root root 1041 Jul 7 17:16 keys/sunny.key
-rw-r--r--. 1 root root 3816 Jul 7 17:13 keys/test.crt
-rw-r--r--. 1 root root  757Jul  7 17:13 keys/test.csr
-rw-------. 1 root root  916Jul  7 17:13 keys/test.key

2.4.5   生成密碼協議交換文件

使用命令build-dh命令生成密碼協議交換文件,直接執行命令即可。

[root@***server 2.0]# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.........................................+.............................++*++*++*
[root@***server 2.0]# ls keys/dh1024.pem
keys/dh1024.pem

2.4.6   生成防***key文件

生成防止***的key文件

[root@***server 2.0]# open*** --genkey --secret keys/ta.key
[root@***server 2.0]# ll keys/ta.key
-rw-------. 1 root root 636 Jul 7 17:22 keys/ta.key

2.4.7   編輯服務端配置文件

創建配置文件目錄

mkdir /etc/open***
cd /etc/open***

keys目錄拷貝到配置文件目錄

[root@***server open***]# cp -ap /application/open***/easy-rsa/2.0/keys.
[root@***server open***]# ll
total 4
drwx------. 2 root root 4096 Jul 7 17:22 keys

將服務端配置文件拷貝到/etc/open***目錄

cp /application/open***/sample-config-files/server.conf server.bak

server.bak中的有效指令重定向至server.conf

grep -Ev "#|;|^$" server.bak >server.conf

編輯server.conf文件,修改後的文件內容如下:

local 192.168.3.201
port 52115
proto tcp
dev tun
ca /etc/open***/keys/ca.crt
cert /etc/open***/keys/server.crt
key /etc/open***/keys/server.key
dh /etc/open***/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
push "route 192.168.18.0 255.255.255.0"
ifconfig-pool-persist ipp.txt
keepalive 10 120
comp-lzo
persist-key
persist-tun
status open***-status.log
log /var/log/open***.log
duplicate-cn
client-to-client
verb 3


local 本地監聽的IP地址

port 本地監聽的端口,默認爲1194,安全起見,建議修改

proto 協議,這裏使用tcp協議,穩定性更好

dev tun,使用tunnel接口,另外還有一種爲tap

ca CA證書文件路徑

cert 服務端證書路徑

key 服務端密鑰文件路徑

dh 證書密鑰交換文件路徑

server 分配給客戶端的IP地址,即客戶端拔號成功後獲取到的IP地址

push 推送到客戶端的路由信息,一般這裏推送的是***server端的本地子網

ifconfig-pool-persist 記錄客戶端所獲取到的IP地址信息列表,客戶端重啓後獲取到與上次分配的IP相同的IP地址信息

keepalive 10 120 每隔10秒客戶端ping服務端,確保服務端沒有離線,超長爲120

comp-lzo 允許壓縮傳輸

status open***-status.log 連接狀態日誌

log 連接日誌信息

duplicate-cn 允許同一賬號多人同時使用

client-to-client 允許客戶端與客戶端之間通信

verb 日誌級別

;max-clients 100 最大客戶端數量默認爲100

 

 

2.5      啓動服務端

2.5.1   啓動服務端

[root@***server open***]# /usr/local/sbin/open*** --config/etc/open***/server.conf &
[1] 22510
[root@***server open***]# ps -ef|grep open***
root      22510  22401 0 09:06 pts/0    00:00:00/usr/local/sbin/open*** --config /etc/open***/server.conf
root      22521  22401 0 09:06 pts/0    00:00:00 grep open***

報錯處理一:

[root@***server open***]# less /var/log/open***.log
Options error: You must define private key file (--key) or PKCS#12file (--pkcs12)
Use --help for more information.

根據提示,表明配置文件中沒有加入服務端的密鑰文件路徑,或者路徑不對,檢查server.conf文件中key文件的配置

key /etc/open***/keys/server.key


2.5.2   Open***加入開機自啓動

需要將Open***加入開機自啓動

方法一:

將啓動命令加入到/etc/rc.local

echo “/usr/local/sbin/open*** --config /etc/open***/server.conf>/dev/null  &”>>/etc/rc.local

方法二:

利用sample-scripts下面的腳本

cp /application/open***/sample-scripts/open***.init /etc/init.d/open***
chkconfig open*** on
chkconfig --list open***
open***         0:off   1:off  2:on    3:on    4:on   5:on    6:off

 


 

3、    open***客戶端安裝與配置

3.1      windows客戶端安裝與配置

3.1.1   查看操作系統版本

這裏提供了不同操作系統版本,可以根據自己操作系統的版本選擇對應的客戶端軟件進行安裝,win8win10選擇win7客戶端安裝,在我的電腦上右鍵屬性可以查看操作系統版本

3.1.2   安裝windows客戶端軟件

win10可以使用win7客戶端,這裏以win7-64位操作系統爲例,進入windows-win7-64

雙擊“open***-install-2.3.11-I601-x86_64(win7).exe

點擊”next”

點擊“I Agree”

不做任何修改,點擊Next

選擇安裝路徑,按默認路徑即可,64位系統默認爲”C:\Program Files\Open***”,其它系統路徑會略有不同

點擊Install,如果提示是否信任,勾選“Always trust software from …”,點擊Install

點擊next進入下一步

點擊Finish完成安裝

3.1.3   windows客戶端軟件配置

3.1.4   拷壩證書文件

進入到open***安裝目錄下的config文件夾中,我的路徑爲“C:\Program Files\Open***\config“,新建test目錄,將open***server/etc/open***/keys目錄下的證書文件ca.crt,test.crt,test.key拷貝到config目錄中config目錄拷貝

test目錄下新建test.o***文件,此文件的模板爲/application/open***/sample-config-files/client.conf,此文件test.o***內容如下:

client
dev tun
proto tcp
remote 192.168.3.201 52115
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert test.crt
key test.key
ns-cert-type server
comp-lzo
verb 3

3.1.5   連接測試

安裝完成後桌面會出現一個圖標,雙擊點開,右下角會出現一個帶小鎖的小圖標,在圖標上點擊右鍵,選中賬號test,點擊Connect,如果沒有密碼,會直接連接,如果需要密碼,則會提示輸入密碼

拔號成功後,右下角會彈出提示

並且原來灰色的圖標會變爲綠色,表示已經連接上了

3.1.6   連通性測試

此時ping ***服務器的內網口192.168.18.201已通,但到lanserver192.168.18.203不通

C:\Users\Administrator>ping 192.168.18.201
正在 Ping 192.168.18.201 具有 32 字節的數據:
來自 192.168.18.201 的回覆: 字節=32 時間<1ms TTL=64
來自 192.168.18.201 的回覆: 字節=32 時間=1ms TTL=64
C:\Users\Administrator>ping 192.168.18.203
正在 Ping 192.168.18.203 具有 32 字節的數據:
請求超時。
請求超時。


查看lanserver上的路由

[root@lanserver ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.18.0    0.0.0.0         255.255.255.0   U    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U    1002   0        0 eth0
0.0.0.0        192.168.18.2    0.0.0.0         UG   0      0        0 eth0

windowsping 192.168.18.203,然後在lanserver上抓包測試

[root@lanserver ~]# tcpdump icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocoldecode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535bytes
18:47:48.676249 IP 10.8.0.6 > 192.168.18.203: ICMP echo request,id 1, seq 17288, length 40
18:47:48.676288 IP 192.168.18.203 > 10.8.0.6: ICMP echo reply, id1, seq 17288, length 40

可見有包過來,但沒有回包,原因是lanserver上有一條默認網關,但是指向的不是***server,解決辦法有兩個:

方法一:將lanserver上的網關指向***server

[root@lanserver ~]# route del default gw 192.168.18.2
[root@lanserver ~]# route add default gw 192.168.18.201
[root@lanserver ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.18.0    0.0.0.0         255.255.255.0   U    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U    1002   0        0 eth0
0.0.0.0        192.168.18.201  0.0.0.0         UG   0      0        0 eth0

添加完成後,windows客戶端與lanserver立刻就通了

方法二:單獨添加一條到10.8.0.0/24的路由

首先刪除默認路由,刪除成功後,客戶端與lanserver立馬就不通了

route del default gw 192.168.18.201

添加到10.8.0.0/24網段的路由

route add -net 10.8.0.0/24 gw 192.168.18.201

方法三:網關不在***server上,在***server上添加一條NAT地址轉換,將所有的10.8.0.0/24網段的IP都轉成192.168.18.201,在iptables上添加如下語句

iptables -t nat -APOSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE


上面的命令也可以用如下命令替換

iptables -t nat -APOSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.18.201


windows客戶端上ping,實際IP10.8.0.6,而在lanserver上抓包看到的源地址顯示爲192.168.18.201

[root@lanserver ~]# tcpdump -i eth0 icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocoldecode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535bytes
19:21:52.889132 IP 192.168.18.201 >192.168.18.203: ICMP echo request, id 1, seq 18615, length 40
19:21:52.889154 IP 192.168.18.203 > 192.168.18.201: ICMP echoreply, id 1, seq 18615, length 40
19:21:53.904123 IP 192.168.18.201 > 192.168.18.203: ICMP echorequest, id 1, seq 18616, length 40
19:21:53.904144 IP 192.168.18.203 > 192.168.18.201: ICMP echoreply, id 1, seq 18616, length 40

小結:

方法一優點實施簡單,只需lanserver網關指向***server即可,在某些網關指向路由器的情形下,可以在路由器上添加一條到遠端10.8.0.0/24的路由即可,缺點是需要經過路由器跳轉,多了一跳

方法二需要在所有的lanserver上添加路由,實施起來較麻煩。

方法三針對方法2進行改進,不需要在每臺機器上配置路由,缺點是無法顯示出源IP信息

3.2      linux客戶端安裝與配置

3.2.1   安裝linux客戶端軟件

linux客戶端軟件的安裝與服務端軟件安裝過程一樣,也是需要先安裝lzo,然後源碼編譯open***2.2.2,具體安裝操作過程可參照服務端源碼包安裝2.4.1

3.2.2   編輯客戶端配置文件

新建配置文件目錄/etc/open***

mkdir /etc/open***
cd /etc/open***

ca.crt,test.crt,test.key,client.conf上傳

1          [root@***client open***]# ls

ca.crt  client.conf  test.crt test.key

client.conf內容與windows客戶端下的test.o***內容一樣

[root@***client open***]# cat client.conf
client
dev tun
proto tcp
remote 192.168.3.201 52115
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert test.crt
key test.key
ns-cert-type server
comp-lzo
verb 3

3.2.3   遠程拔入***

使用與服務端類似的啓動方式進行啓動,開機自啓方式可以加入/etc/rc.local

[root@***client open***]# /usr/local/sbin/open*** --config/etc/open***/client.conf  &
[1] 16347
[root@***client open***]# Thu Jul 7 19:49:00 2016 Open*** 2.2.2 x86_64-unknown-linux-gnu [SSL] [LZO2][EPOLL] [eurephia] built on Jul  7 2016
Thu Jul  7 19:49:00 2016 NOTE:Open*** 2.1 requires '--script-security 2' or higher to call user-definedscripts or executables
…此處省略若干行
Thu Jul  7 19:49:03 2016 ROUTEdefault_gateway=192.168.3.251
Thu Jul  7 19:49:04 2016TUN/TAP device tun0 opened
Thu Jul  7 19:49:04 2016TUN/TAP TX queue length set to 100
Thu Jul  7 19:49:04 2016/sbin/ifconfig tun0 10.8.0.10 pointopoint 10.8.0.9 mtu 1500
Thu Jul  7 19:49:04 2016/sbin/route add -net 192.168.18.0 netmask 255.255.255.0 gw 10.8.0.9
Thu Jul  7 19:49:04 2016/sbin/route add -net 10.8.0.0 netmask 255.255.255.0 gw 10.8.0.9
Thu Jul  7 19:49:04 2016Initialization Sequence Completed
拔號成功後,會多出一個接口tun0
[root@***client open***]# ifconfig tun0
tun0      Linkencap:UNSPEC  HWaddr00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          inetaddr:10.8.0.10  P-t-P:10.8.0.9  Mask:255.255.255.255
          UP POINTOPOINTRUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0errors:0 dropped:0 overruns:0 frame:0
          TX packets:0errors:0 dropped:0 overruns:0 carrier:0
          collisions:0txqueuelen:100
          RX bytes:0 (0.0b)  TX bytes:0 (0.0 b)

如果是帶密碼認證的用戶,以sunny爲例,將sunny.crt,sunny.key,sunny.o***上傳至/etc/open***,sunny.o***的內容如下:

client
dev tun
proto tcp
remote 192.168.3.204 52115
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert sunny.crt
key sunny.key
ns-cert-type server
comp-lzo
verb 3
--script-security 3


/etc/open***下新建密碼文件pass.txt

123456

安全起見,修改pass.txt權限爲400

chmod 400 /etc/open***/pass.txt

啓動客戶端

open***--config /etc/open***/sunny.o*** --askpass /etc/open***/pass.txt &


加入開機自啓的方法:

echo ‘open*** --config /etc/open***/sunny.o*** --askpass/etc/open***/pass.txt >/dev/null &’>>/etc/rc.local

3.2.4   檢查路由變化和連通性

測試到192.168.18.203網絡是通的,停掉open***服務(pkill open***)後,網絡又斷開了,linux客戶端配置成功

連通性問題處理方案與windows客戶端上一致,見3.1.6

 



4、    open***高可用方案

4.1      使用open***實現代理訪問

4.1.1   ***解決方案需求分析

web代理類似,客戶的IP地址通過代理訪問後,源地址變成***server的外網IP,客戶端所有的上網行爲都走***server,相當於是遠端的***server去請求網頁服務。之前的普通模式只是訪問遠端特定的內網服務器時,纔會走***server,其它外網訪問依然走客戶端本地網絡,如果這臺***server在國外,可以通過此服務器訪問國外的網站,請不要使用此方法用於非法用途,否則後果自負。

具體邏輯如下圖所示:


wKioL1eYSv_SR_28AAEQIOFvqZE761.png-wh_50

4.1.2   代理訪問解決方案配置

和普通配置相比,在server.conf上增加如下配置

push "redirect-gateway def1 bypass-dhcp bypass-dns"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

啓動轉發功能

sed –i ‘s#net.ipv4.ip_forward= 0# net.ipv4.ip_forward= 1#g’/etc/sysctl.conf
sysctl –p

開啓防火牆NAT映射

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

開放防火牆

iptables -A INPUT -p udp -m state –state NEW –m udp  --dport 52115 -j ACCEPT

4.2      同一賬號拔入不同服務器

4.2.1   實現原理

wKioL1eYSv6C4vmZAADZQidMKzg408.png-wh_50

配置兩臺***server,2臺服務器上同樣也需要開啓net.ipv4.ip_forward,源碼編譯安裝完成後,所有的證書製作過程不需要了,直接將***server1/etc/open***/keys目錄拷貝到***server2中,這樣兩臺***server的內容是一樣的,除了接入的IP地址不一樣,只需要在客戶端生成一個新的配置文件(client.conf/test2.o***,

4.2.2   同一賬號拔入不同***server方案

***server1上對證書文件目錄打包

[root@***server open***]# cd /tmp
[root@***server tmp]# tar zcvf open***.tar.gz /etc/open***/
[root@***server tmp]# scp open***.tar.gz 192.168.3.204:/tmp

***server2上解包

[root@***server2 tmp]# tar xf open***.tar.gz -C /
[root@***server2 tmp]# ls /etc/open***/
ipp.txt  keys  open***-status.log  server.bak server.conf

修改***sever2上的server.conf文件

local 192.168.3.204
server10.8.1.0 255.255.255.0


啓動***server2

/usr/local/sbin/open*** --config /etc/open***/server.conf &

加入開機自啓動

echo "/usr/local/sbin/open*** --config /etc/open***/server.conf>/dev/null  &">>/etc/rc.local

修改客戶端配置文件,新增一個配置文件,除IP地址外,其它均一樣

一旦一臺***server停掉了,需要手動將此鏈接斷開,拔號到另外一臺***server

優點:無額外單點故障,配置簡單

缺點:需要手工切換拔號服務器

4.3      OPEN***負載均衡

4.3.1   原理圖解


wKioL1eYSv6C4vmZAADZQidMKzg408.png-wh_50


4.3.2   負載均衡實現

配置server客戶端分配不同的IP地址

server1
    server 10.8.0.0 255.255.255.0
server2
    server 10.8.1.0255.255.255.0
server3
server 10.8.2.0 255.255.255.0

***server2上添加如下命令中的一條,做地址轉換

方法1

iptables -t nat -APOSTROUTING -s 10.8.1.0/24 -o eth0 -j MASQUERADE


方法2

iptables -t nat -APOSTROUTING -s 10.8.1.0/24 -o eth0 -j SNAT --to-source 192.168.18.204


 

客戶端配置配置文件修改

remote 192.168.3.201 52115
remote 192.168.3.204 52115
remote-random
resolv-retry 20

這樣只需要建一個配置文件即可,當一臺***server斷掉時,20秒後自動連另外一臺***server

 


 

5、    open***統一身份認證體系解決方案

5.1      Open***統一身份驗證分類

1)  通過本地證書密鑰認證

2)  本地文件認證

本地新建賬號密碼文件,通過腳本驗證本地的密碼文件

3)  通過數據庫認證

方法1:利用腳本程序或PHP程序不從本地文件讀,從Mysql數據庫中讀取

方法2:使用pam_mysql模塊

4)  LDAP統一用戶認證

方法1open***-auth-ldap

方法2:利用第一個文件認證的思路,去LDAP查詢,也可以和本地文件做比較

5)  RadisRemote Authentication Dial In User Service)認證,主要用來驗證、授權、計費

6)  利用微軟的活動目錄認證(可以和LDAP打通)

7)  結合U盾等設備認證

5.2      Open***本地身份認證

5.2.1   服務端配置

/etc/open***/server.conf中添加如下配置

#auth password added by sunny
script-security 3
auth-user-pass-verify /etc/open***/checkpsw.sh via-env
client-cert-not-required
username-as-common-name

說明:

script-security 3  使用3級別開啓腳本使用功能

auth-user-pass-verify /etc/open***/checkpsw.sh via-env使用腳本驗證本地文件

client-cert-not-required       不驗證客戶端證書,如果啓用證書和密碼雙重認證註釋此行username-as-common-name          使用客戶提供的UserName作爲CommonName

/etc/open***下新建腳本文件checkpsw.sh

#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman <mathias@open***.se>
#
# This script will authenticate Open*** users against
# a plain text file. The passfile should simply contain
# one row per user with the username first followed by
# one or more space(s) or tab(s) and then the password.
PASSFILE="/etc/open***/psw-file"
LOG_FILE="/var/log/open***-password.log"
TIME_STAMP=`date "+%Y-%m-%d %T"`
###########################################################
if [ ! -r "${PASSFILE}" ]; then
echo "${TIME_STAMP}: Could not open password file\"${PASSFILE}\" for reading." >> ${LOG_FILE}
exit 1
fi
CORRECT_PASSWORD=`awk'!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}'${PASSFILE}`
if [ "${CORRECT_PASSWORD}" = "" ]; then 
echo "${TIME_STAMP}: User does not exist: username=\"${username}\",password=\"${password}\"." >> ${LOG_FILE}
exit 1
fi
if [ "${password}" = "${CORRECT_PASSWORD}" ]; then 
echo "${TIME_STAMP}: Successful authentication:username=\"${username}\"." >> ${LOG_FILE}
exit 0
fi
echo "${TIME_STAMP}: Incorrect password:username=\"${username}\", password=\"${password}\".">> ${LOG_FILE}
exit 1

賦予可執行權限

chmod u+x checkpsw.sh

新建密碼文件/etc/open***/psw-file,前面是用戶,後面是密碼,每行一條,中間用空格或者tab鍵隔開

client01        111111
client02        123456

修改密碼文件權限

 chmod 400 psw-file

重啓open***

pkill open***
ps -ef|grep open***
/etc/init.d/open*** start
ps -ef|grep open***

5.2.2   客戶端配置

5.2.2.1 windows客戶端配置

編輯test用戶的客戶端配置文件test-192.168.3.201.o***,新增紅色部分配置,修改後的配置如下:

client
dev tun
proto tcp
remote 192.168.3.201 52115
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
;cert test.crt
;key test.key
ns-cert-type server
comp-lzo
verb 3
auth-user-pass


 

5.2.2.2 linux客戶端配置

Linux客戶端配置文件如下:

;cert test.crt
;key test.key
auth-user-pass    auth-user-pass/etc/open***/psw-file


新建密碼文件/etc/open***/psw-file,第一行爲用戶名,第二行爲密碼

client02
123456

修改權限爲400

chmod 400 /etc/open***/psw-file

添加到開機自啓動

echo “/usr/local/sbin/open***--config /etc/open***/client.conf >/dev/null &”>>/etc/rc.local

此功能需要編譯時加入--enable-password-save參數,即

./configure --enable-password-save --with-lzo-lib=/usr/local/lib --with-lzo-headers=/usr/local/include

否則會報如下錯誤:

'Auth' password cannot be read from a file

5.2.3   連接測試

windows客戶端直接拔號測試,會彈出用戶密碼輸入框,輸入client01,111111

linux客戶端直接啓動服務即可


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