CentOS 6下利用Open***部署遠程***服務

2年前自己還是小白的時候就在老單位連總部OA時用過Open***這個客戶端,感覺還挺好用,而且覺得以後項目應該也能用得上,SO google了網上大量零碎資料,折騰了大半天,按照自己的理解就整理了如下文檔,給有興趣的朋友分享一下。

最近一直想把自己的短板,也就是Linux編程這塊好好研究下。。

不扯了,開始幹活。。

-------------------華麗的分割線-----------------------

Open***是一款在Linux網關服務器使用的開源的***軟件,顧名思義,其實就是用來打通一條安全的虛擬專用通道,實現用戶遠程辦公,獲取內網資源。

該軟件可跨平臺在在Linux、xBSD、Mac OS X與Windows間使用,並利用openssl作爲加密庫,使用加密證書或用戶名/密碼來實現身份驗證,是一款不可多得的開源***解決方案。

我們做這個實驗的目的就是模擬線上常見的公司外出人員在外需要訪問公司內網OA,實現遠程辦公自動化。

解決方案:

 

系統環境:CentOS6.3 x64

OPEN***: open***-2.3.0

 

*** server: eth0:192.168.100.90,eth1:172.24.30.1

*** client: 192.168.100.34

intranet server: 172.24.30.10

 

 

部署環境:

 

1.啓動並清空iptables規則

# iptables -t NAT -F

# iptables -F

# service iptables save

# service iptables restart

 

2.關閉SELINUX

# setenforce 0

# vi /etc/sysconfig/selinux

---------------

SELINUX=disabled

---------------

 

server端:

 

一.網絡設置

1.開啓服務器端路由轉發功能

# vi /etc/sysctl.conf

---------------------

net.ipv4.ip_forward = 1

---------------------

# sysctl -p

 

2.設置nat轉發:

注:保證***地址池可路由出外網

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

 

3.設置open***端口通過:

# iptables -A INPUT -p TCP --dport 1194 -j ACCEPT

# iptables -A INPUT -p TCP --dport 7505 -j ACCEPT

# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

 

3.時間同步(重要)

# ntpdate asia.pool.ntp.org

 

二.安裝依賴庫

# yum install -y openssl openssl-devel lzo lzo-devel pam pam-devel automake pkgconfig

 

三.安裝open***:

# wget -c http://swupdate.open***.org/community/releases/open***-2.3.0.tar.gz

# tar zxvf open***-2.3.0.tar.gz

# cd open***-2.3.0

# ./configure --prefix=/usr/local/open***

# make && make install

# mkdir -p /etc/open***

複製模板到open***配置目錄:

# cp -rf sample /etc/open***/

複製open***配置文件到主目錄:

# cp /etc/open***/sample/sample-config-files/server.conf /etc/open***/

# cd ..

 

四.下載easy-rsa:

注:該包用來製作ca證書,服務端證書,客戶端證書,open***2.3.0該版本源碼不包含easy-rsa,所以需要單獨下載安裝用來配合open***實現證書生成。

# wget -c https://github.com/Open***/easy-rsa/archive/master.zip

# unzip master

# mv easy-rsa-master easy-rsa

# cp -rf easy-rsa /etc/open***

# cd /etc/open***/easy-rsa/easy-rsa/2.0

***變量

# vi vars

修改如下參數

注:在後面生成服務端ca證書時,這裏的配置會作爲缺省配置

---------------------

export KEY_COUNTRY="CN"

export KEY_PROVINCE="SX"

export KEY_CITY="Xian"

export KEY_ORG="example"

export KEY_EMAIL="[email protected]"

---------------------

做SSL配置文件軟鏈:

# ln -s openssl-1.0.0.cnf openssl.cnf

修改vars文件可執行並調用

# chmod +x vars

# source ./vars

-----------------

NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/open***/easy-rsa/easy-rsa/2.0/keys

-----------------

注:也就是如果執行./clean-all,就會清空/etc/open***/easy-rsa/easy-rsa/2.0/keys下所有文件

 

開始配置證書:

1.清空原有證書:

# ./clean-all

注:下面這個命令在第一次安裝時可以運行,以後在添加完客戶端後慎用,因爲這個命令會清除所有已經生成的證書密鑰,和上面的提示對應

 

2.生成服務器端ca證書

./build-ca

注:由於之前做過缺省配置,這裏一路回車即可

 

3.生成服務器端密鑰證書, 後面這個open***.example.com就是服務器名,也可以自定義

./build-key-server open***.example.com

---------------------------

Generating a 2048 bit RSA private key

...................................................+++

..................................+++

writing new private key to 'open***.example.com.key'

-----

You are about to be asked to enter information that will be

 

incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or

 

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) [SX]:

Locality Name (eg, city) [Xian]:

Organization Name (eg, company) [example]:

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname)

 

[open***.example.com]:

Name [EasyRSA]:

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 []:example

Using configuration from /etc/open***/easy-rsa/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:'SX'

localityName :PRINTABLE:'Xian'

organizationName :PRINTABLE:'example'

commonName :PRINTABLE:'open***.example.com'

name :PRINTABLE:'EasyRSA'

emailAddress :IA5STRING:'[email protected]'

Certificate is to be certified until Jun 10 21:58:49 2023 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

---------------------------

 

4.生成所需客戶端證書密鑰文件:

# ./build-key client1

# ./build-key client2

注:這裏與生成服務端證書配置類似,中間一步提示輸入服務端密碼,其他按照缺省提示一路回車即可。

 

5.再生成diffie hellman參數,用於增強open***安全性(生成需要漫長等待)

# ./build-dh

 

6.打包keys

# tar zcvf keys.tar.gz keys/

 

7.終端發送到客戶端備用

# yum install lrzsz -y

# sz keys.tar.gz

五.配置open*** server:

# vi /etc/open***/server.conf

注:可按照默認模板配置,本例爲自定義配置文件:

--------------------------

# 設置監聽IP,默認是監聽所有IP

;local a.b.c.d

# 設置監聽端口,必須要對應的在防火牆裏面打開

port 1194

# 設置用TCP還是UDP協議?

;proto tcp

proto tcp

# 設置創建tun的路由IP通道,還是創建tap的以太網通道

# 路由IP容易控制,所以推薦使用它;但如果如IPX等必須

# 使用第二層才能通過的通訊,則可以用tap方式,tap也

# 就是以太網橋接

;dev tap

dev tun

# Windows需要給網卡一個名稱,這裏設置,linux不需要

;dev-node MyTap

# 這裏是重點,必須指定SSL/TLS root certificate (ca),

# certificate(cert), and private key (key)

# ca文件是服務端和客戶端都必須使用的,但不需要ca.key

# 服務端和客戶端指定各自的.crt和.key

# 請注意路徑,可以使用以配置文件開始爲根的相對路徑,

# 也可以使用絕對路徑

# 請小心存放.key密鑰文件

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

cert /etc/open***/easy-rsa/easy-rsa/2.0/keys/open***.example.com.crt

key /etc/open***/easy-rsa/easy-rsa/2.0/keys/open***.example.com.key

# This file should be kept secret

 

# 指定Diffie hellman parameters.

dh /etc/open***/easy-rsa/easy-rsa/2.0/keys/dh2048.pem

 

# 配置***使用的網段,Open***會自動提供基於該網段的DHCP

# 服務,但不能和任何一方的局域網段重複,保證唯一

server 10.8.0.0 255.255.255.0

 

# 維持一個客戶端和virtual IP的對應表,以方便客戶端重新

# 連接可以獲得同樣的IP

ifconfig-pool-persist ipp.txt

 

# 配置爲以太網橋模式,但需要使用系統的橋接功能

# 這裏不需要使用

;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100

 

# 爲客戶端創建對應的路由,以另其通達公司網內部服務器

# 但記住,公司網內部服務器也需要有可用路由返回到客戶端

;push "route 192.168.20.0 255.255.255.0"

push "route 172.24.30.0 255.255.255.0"

 

# 爲特定的客戶端指定IP或指定路由,該路由通常是客戶端後面的

# 內網網段,而不是服務端連接的網段

# ccd是/etc/open***下的目錄,其中建有希望限制的客戶端Common

# Name爲文件名的文件,並通過下面的命令寫入固定IP地址

# 例如Common Name爲client1,則在/etc/open***/ccd/client1寫有:

# ifconfig-push 10.9.0.1 10.9.0.2

;client-config-dir ccd

;route 192.168.40.128 255.255.255.248

 

# 爲可以對不同的客戶端設置防火牆等權限

# 可以讓其自動運行對應腳本,可參考man

;learn-address ./script

 

# 若客戶端希望所有的流量都通過***傳輸,則可以使用該語句

# 其會自動改變客戶端的網關爲***服務器,推薦關閉

# 一旦設置,請小心服務端的DHCP設置問題

;push "redirect-gateway"

 

# 用Open***的DHCP功能爲客戶端提供指定的DNS、WINS等

;push "dhcp-option DNS 10.8.0.1"

;push "dhcp-option WINS 10.8.0.1"

 

# 默認客戶端之間是不能直接通訊的,除非把下面的語句註釋掉

client-to-client

 

# 如果您希望有相同Common Name的客戶端都可以登陸

# 也可以註釋下面的語句,推薦每個客戶端都使用不用的Common Name

# 常用於測試

;duplicate-cn

 

# 設置服務端檢測的間隔和超時時間

keepalive 10 120

 

# 下面是一些對安全性增強的措施

# For extra security beyond that provided

# by SSL/TLS, create an "HMAC firewall"

# to help block DoS attacks and UDP port flooding.

#

# Generate with:

# open*** --genkey --secret ta.key

#

# The server and each client must have

# a copy of this key.

# The second parameter should be 0

# on the server and 1 on the clients.

;tls-auth ta.key 0 # This file is secret

 

# Select a cryptographic cipher.

# This config item must be copied to

# the client config file as well.

;cipher BF-CBC # Blowfish (default)

;cipher AES-128-CBC # AES

;cipher DES-EDE3-CBC # Triple-DES

 

# 使用lzo壓縮的通訊,服務端和客戶端都必須配置

comp-lzo

 

# 設置最大用戶數

;max-clients 100

 

# 讓Open***以nobody用戶和組來運行(安全)

;user nobody

;group nobody

 

# The persist options will try to avoid

# accessing certain resources on restart

# that may no longer be accessible because

# of the privilege downgrade.

persist-key

persist-tun

 

# 輸出短日誌,每分鐘刷新一次,以顯示當前的客戶端

status /var/log/open***/open***-status.log

 

# 缺省日誌會記錄在系統日誌中,但也可以導向到其他地方

# 建議調試的使用先不要設置,調試完成後再定義

log /var/log/open***/open***.log

log-append /var/log/open***/open***.log

 

# 設置日誌的級別

#

# 0 is silent, except for fatal errors

# 4 is reasonable for general usage

# 5 and 6 can help to debug connection problems

# 9 is extremely verbose

verb 3

 

# Silence repeating messages. At most 20

# sequential messages of the same message

# category will be output to the log.

;mute 20

--------------------------

創建日誌目錄:

# mkdir -p /var/log/open***/

啓動open*** server

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

設置開機啓動:

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

client端:

六.安裝WINDOWS客戶端(WIN7 64bit)

1.下載客戶端,並默認安裝:

http://***tech.googlecode.com/files/open***-2.1.1-gui-1.0.3-install-cn-64bit.zip

 

2.將服務端打包文件解壓,並將包內ca.crt、client1.crt、client1.key複製到客戶端C:\Program Files\Open***\config下.

 

3.在C:\Program Files\Open***\config下創建client.o***文件

內容如下:

-----------------------

# 定義是一個客戶端

client

 

# 定義使用路由IP模式,與服務端一致

;dev tap

dev tun

 

# 定義Windows下使用的網卡名稱,linux不需要

;dev-node MyTap

 

# 定義使用的協議,與服務端一致

;proto tcp

proto tcp

 

# 指定服務端地址和端口,可以用多行指定多臺服務器

# 實現負載均衡(從上往下嘗試)

remote 192.168.100.90 1194

;remote my-server-2 1194

 

# 若上面配置了多臺服務器,讓客戶端隨機連接

;remote-random

 

# 解析服務器域名

# Keep trying indefinitely to resolve the

# host name of the Open*** server. Very useful

# on machines which are not permanently connected

# to the internet such as laptops.

resolv-retry infinite

 

# 客戶端不需要綁定端口

# Most clients do not need to bind to

# a specific local port number.

nobind

 

# 也是爲了讓Open***也nobody運行(安全)

# 注意:Windows不能設置

;user nobody

;group nobody

 

# Try to preserve some state across restarts.

persist-key

persist-tun

# 若客戶端通過HTTP Proxy,在這裏設置

# 要使用Proxy,不能使用UDP爲***的通訊協議

;http-proxy-retry # retry on connection failures

;http-proxy [proxy server] [proxy port #]

# 無線網絡有很多多餘的頭文件,設置忽略它

;mute-replay-warnings

# 重點,就是指定ca和客戶端的證書

ca ca.crt

cert client1.crt

key client1.key

# 如果服務端打開了PAM認證模塊,客戶端需要另其有效

;auth-user-pass

# 一些安全措施

# Verify server certificate by checking

# that the certicate has the nsCertType

# field set to "server". This is an

# important precaution to protect against

# a potential attack discussed here:

# http://open***.net/howto.html#mitm

#

# To use this feature, you will need to generate

# your server certificates with the nsCertType

# field set to "server". The build-key-server

# script in the easy-rsa folder will do this.

;ns-cert-type server

 

# If a tls-auth key is used on the server

# then every client must also have the key.

;tls-auth ta.key 1

 

# Select a cryptographic cipher.

# If the cipher option is used on the server

# then you must also specify it here.

;cipher x

 

# 使用lzo壓縮,與服務端一致

comp-lzo

 

# Set log file verbosity.

verb 3

# Silence repeating messages

;mute 20

-----------------------

5.連接:

在右下角的open***圖標上右擊,選擇“Connect”,若能正常分配IP,則連接成功。

6.最終測試:

C:\Users\Administrator>ipconfig/all

---------------------------------------

...............

以太網適配器 本地連接* 12:

連接特定的 DNS 後綴 . . . . . . . :

描述. . . . . . . . . . . . . . . : TAP-Win32 Adapter V9

物理地址. . . . . . . . . . . . . : 00-FF-45-FB-F5-E2

DHCP 已啓用 . . . . . . . . . . . : 是

自動配置已啓用. . . . . . . . . . : 是

本地鏈接 IPv6 地址. . . . . . . . : fe80::848d:bd1d:c1f4:fb51%27(首選)

IPv4 地址 . . . . . . . . . . . . : 10.8.0.6(首選)

子網掩碼 . . . . . . . . . . . . : 255.255.255.252

獲得租約的時間 . . . . . . . . . : 2013年6月15日 22:36:59

租約過期的時間 . . . . . . . . . : 2014年6月15日 22:36:59

默認網關. . . . . . . . . . . . . :

DHCP 服務器 . . . . . . . . . . . : 10.8.0.5

DHCPv6 IAID . . . . . . . . . . . : 453050181

.....................

----------------------------------

在*** client上ping intranet server 主機IP:172.24.30.10

C:\Users\Administrator>ping 172.24.30.10

-------------------------

正在 Ping 172.24.30.10 具有 32 字節的數據:

來自 172.24.30.10 的回覆: 字節=32 時間=2ms TTL=63

來自 172.24.30.10 的回覆: 字節=32 時間<1ms TTL=63

來自 172.24.30.10 的回覆: 字節=32 時間<1ms TTL=63

來自 172.24.30.10 的回覆: 字節=32 時間<1ms TTL=63

--------------------------

大功告成。。。

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

linux


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