找回密码
 注册
查看: 4623|回复: 1

centos操作系统为企业搭建稳固的SSL VPN服务

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2020-1-19 08:52:01 | 显示全部楼层 |阅读模式
一、OpenVPN是靠虚拟的TUN/TAP设备实现SSL VPN的,因此内核必须支持TUN/TAP设备模块,这个配置选项在2.6.x内核中,位于Device Drivers ->Network device support 菜单中,全称是Universal TUN/TAP device driver support ,通常在标准内核 中,会以模块方式提供,在Open VPN启动时,它会自动加载此模块,因此不需要手工加载此模块。: [1 M; [3 d) W5 {& z9 Z* M, D4 i! }
[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# pwd6 v  h; ]: K* ^& r4 X! ]/ {
/usr/src/kernels/2.6.18-238.12.1.el5-i6869 s7 A  V! a" F$ O9 |. ~3 F$ n
[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# make menuconfig  #打开内核菜单
- J/ F9 r; @% h; R; ^) O* D Device Drivers  --->            
+ y/ b' r1 e! G& E& P( h2 n Network device support  --->      
+ R, h& l4 Y+ ^8 {) U: s<M> Universal TUN/TAP device driver support     #<M>即表示以模块化加载到内核中
  j0 C1 C7 d2 m3 C
二、在安装OpenVPN之前,还需要安装一些支持包,包括OpenSSL开发库和LZO压缩开发库  l1 j- R+ j8 T- f+ v
1、可使用yum安装OpenSSL开发库,但需要手工下载并安装LZO开发包。
4 Z0 S( F- y6 a& r& s! q& t3 `: _#yum install  openssl  
: X5 @0 W$ c9 t- o# yum install openssl-devel
#yum install pam-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下载LZO
9 U6 W$ i3 E) A7 ^# tar -zxvf lzo-2.10.tar.gz
5 {0 Z7 |) ~$ C; [# cd lzo-2.10+ O# i) v; _1 C, n
#./configure; W7 s# I8 E' z; z& E
# make " y2 ~0 H' A  ]- g* }' p  a, R
# make install
三、配置SSL VPN服务
8 m" F: o7 E. L1、到  http://openvpn.net/release/ 下载openvpn-2.0.9.tar.gz并安装# }6 m3 @5 v9 `) e2 i6 k* F
# tar -zxvf openvpn-2.1.1.tar.gz 9 o! a+ |7 ?$ ^. |1 o% z. b
# cd openvpn-2.1.1/ B, Z/ g' f% \+ K. W
[root@webbs168x openvpn-2.1.1]# ./configure --prefix=/usr/local/openvpn4 V5 _7 X5 F7 Y5 n5 h: s" r0 D
[root@webbs168x openvpn-2.1.1]# make 8 ^1 @) p0 `1 s
[root@webbs168x openvpn-2.1.1]# make install: w" L! S- u5 E
[root@webbs168x openvpn-2.1.1]#cp -p sample-scripts/openvpn.init /etc/init.d/openvpn( G8 {& B. U% C0 T, I0 p
[root@webbs168x openvpn-2.1.1]# chkconfig --add openvpn
! G3 m/ `. e, m% [[root@webbs168x openvpn-2.1.1]# service openvpn status  #查看服务状态/ H) r/ f/ w7 B) a) }) G8 i7 A
openvpn: service not started% X7 w2 i! ?/ K) n! |. g+ {
& s* L3 x5 Y9 i% E
# chkconfig --list openvpn" B1 E. C" Z1 O# e: q. j+ R9 J
openvpn         0:off   1:off   2:on    3:on    4:on    5:on    6:off
2、开启IP转发功能* {8 e1 z( {2 f' ]8 d
#vi /etc/sysctl.conf
. c* e% a8 P1 [7 A! xnet.ipv4.ip_forward = 1
/ G; r2 S% D' t, r% g/ V  Q# sysctl -p
" d- G; @/ M6 h" x! E3、定义OpenVPN的配置目录为/etc/openvpn,把服务器配置文件定义为/etc/openvpn/server.conf
# X% u4 M3 s! X. qOpenVPN是一个SSL VPN实现,因此,认证中最重要的是服务器和客户端的SSL证书管理,如果管理员之前没有SSL证书发布机制,那么可以使用OpenVPN附带的一组工具来完成所有的工作。
9 _$ X0 X  K/ f+ S在/root/openvpn-2.1.1中,有一个easy-rsa目录,这下面就是一些一成和管理SSL证书的工具,以下为生成证书操作。) ^' z, k# t; g. v
#mkdir -p /etc/openvpn) x+ C0 Y* s! I
#cp -p sample-config-files/server.conf /etc/openvpn/   #将样本配置文件复制到/etc/openvpn/,后面再做修改
4、修改vars文件变量,设置国家代码、省份、地市、机构名单、单位名称邮件等
; `1 m7 A% U4 t; P#cd easy-rsa/3 y% }& p7 R- Z  W/ s; @: `6 ^
# grep -v "#" vars
4 E! X" d' K7 c# p; K6 s  xexport D=`pwd`' ?& K. \( U& W9 O. \
export KEY_CONFIG=$D/openssl.cnf
! j1 h* b% _: w0 w  Texport KEY_DIR=$D/keys
4 A. R" b3 H" ?echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR+ U0 Q# |# q5 I& p
export KEY_SIZE=1024
9 @" z: C: t+ _8 |export KEY_COUNTRY=CN
, a: u" c2 T' _( O4 aexport KEY_PROVINCE=GD& n% Y% m. h3 H) @: P
export KEY_CITY=SZ4 D# y# w: ]2 \# K- W, g
export KEY_ORG="DIC"
- b6 @' V; L; q$ Z" p9 Oexport KEY_EMAIL="tghfly222@126.com". F1 [3 `, S) S  T5 \
easy-rsa# source vars+ Y$ p: `' v' @( f
NOTE: when you run ./clean-all, I will be doing a rm -rf on /usr/src/openvpn-2.0.9/easy-rsa/keys  #提示可使用./clean-all清除所有包括CA在内的所有证书
5、使用clean-all脚本清除包括CA在内的所有证书,再创建CA证书。& [* Q" ?3 M  `
[root@www.linuxidc.com easy-rsa]# ./clean-all   #先清除证书,再创建证书
8 y. q; F5 s2 J( u% B5 i1 f3 W! p[root@www.linuxidc.com easy-rsa]# ./build-ca  #创建CA证书
  S* S+ }) h- g# S+ |; `+ \Generating a 1024 bit RSA private key. x  ~2 a4 Q! g9 {7 }: x) w
..........++++++
' G6 H: H5 k+ V................++++++
8 q/ W# C4 K. O6 o2 Jwriting new private key to 'ca.key'2 b& m# d8 v. K7 G
-----' \6 m  W$ S; A' v) j0 ~# U
You are about to be asked to enter information that will be incorporated
  W$ I9 V9 j3 t( t* _5 h; Pinto your certificate request.
' S, P) V2 s6 HWhat you are about to enter is what is called a Distinguished Name or a DN.
9 H0 d- T' {5 W8 I* |; fThere are quite a few fields but you can leave some blank* W. r' y' s1 f, ?$ L
For some fields there will be a default value,% H' d5 \$ m0 ~4 f! h; j1 }
If you enter '.', the field will be left blank.
( u+ G: N2 P9 M1 G0 Y) G-----. {5 r% v2 P& _0 ]1 L
Country Name (2 letter code) [CN]:
" Y8 T; M' E" u$ B2 T+ @) kState or Province Name (full name) [GD]:
" r" O( V, n6 q% _1 y, F6 JLocality Name (eg, city) [SZ]:
9 n. Y" D' D- LOrganization Name (eg, company) [DIC]:
: C% K4 t, w5 t: V+ q, a# IOrganizational Unit Name (eg, section) []:
8 z4 s/ A: ^$ g5 O0 MCommon Name (eg, your name or your server's hostname) []:dic172   #服务器主机名
2 l9 i$ T3 B. j8 o% w" NEmail Address [tghfly222@126.com]:
6、创建服务器密钥。( q, t6 C0 Z( x( }
[root@www.linuxidc.com easy-rsa]# ./build-key-server server  #创建服务器端密钥
1 y, i) M* q( SGenerating a 1024 bit RSA private key5 Z1 p# M  v! ?7 n/ a7 {
............................................++++++, `9 o, t! y8 ]( x5 i- M
....++++++
5 p" \8 {( h7 a. H4 zwriting new private key to 'server.key'
/ R5 P& x2 O* J1 F1 |- f8 h-----6 j2 H0 H4 b/ e0 d/ B, ^! v
You are about to be asked to enter information that will be incorporated$ O" \0 n$ N" f& {3 J& s# }6 D
into your certificate request.! n. h' o# c/ f  M- Y/ Q
What you are about to enter is what is called a Distinguished Name or a DN.9 ?/ R4 ]' f, B+ X/ f$ B0 f& K# t$ F% `
There are quite a few fields but you can leave some blank
; L& r3 r% s2 ?, _: NFor some fields there will be a default value,( E' V/ q# ]. Z7 t9 N' T( J0 C
If you enter '.', the field will be left blank.
4 c$ H. F* w3 ^7 \& C3 A+ H-----& J2 r' E8 Z- D" R3 m
Country Name (2 letter code) [CN]:8 Z8 h* H! a/ D& N+ i- z% k1 F
State or Province Name (full name) [GD]:' C6 I$ K; m" d$ {) T# H" X
Locality Name (eg, city) [SZ]:
! C0 Y5 T0 B4 @9 r) V& q( L* \Organization Name (eg, company) [DIC]:
4 \  O7 }8 h- k- a, b1 jOrganizational Unit Name (eg, section) []:, A: u6 w$ R. J1 B5 j+ _
Common Name (eg, your name or your server's hostname) []:dic172  #服务器主机名
9 A! p. b7 t/ e- _: ^- fEmail Address [tghfly222@126.com]:
Please enter the following 'extra' attributes. J; X  m) m8 |5 J1 h
to be sent with your certificate request1 u- P, V1 x7 G; s8 {0 n0 r6 {
A challenge password []:dic1720 l. L3 i5 y8 w: |# B
An optional company name []:dic1726 ?/ f$ y+ G$ Q  j
Using configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf8 H5 @" v9 H9 T! s2 A8 N
Check that the request matches the signature3 l2 o' [. K" X$ K4 Y. ]4 G" s5 J  v
Signature ok( R/ m7 O7 T8 t) [# j$ i( B* W
The Subject's Distinguished Name is as follows* l2 L! o. J1 H
countryName           :PRINTABLE:'CN'; X7 T6 p5 i+ q( J
stateOrProvinceName   :PRINTABLE:'GD'
3 a6 ?- h* p7 K* `+ `0 W" UlocalityName          :PRINTABLE:'SZ'
- y( ^& m; P/ corganizationName      :PRINTABLE:'DIC'9 k7 P8 I+ h* d
commonName            :PRINTABLE:'dic172'
2 V. X+ W+ o( w5 Q" G6 o* AemailAddress          :IA5STRING:'tghfly222@126.com'
0 e  B; A2 h# V3 ECertificate is to be certified until Jul 16 05:51:08 2021 GMT (3650 days)
( H1 N+ z7 f" q, d2 ?2 @; \Sign the certificate? [y/n]:y
0 }: O  b! n' Z  d$ b' x1 out of 1 certificate requests certified, commit? [y/n]y
' R( v# d4 M* z, E( g( p. ~2 ]Write out database with 1 new entries) `8 t' n# n, [, p- e7 ]
Data Base Updated. [+ T. ~+ b9 D; w7 \$ D
7、创建客户端密钥,客户端密钥名可随意命名。: H. C5 w& e8 l, K5 E6 N
[root@www.linuxidc.com easy-rsa]# ./build-key client
) f1 p6 y/ e+ `  o* w7 S  t- HGenerating a 1024 bit RSA private key  j4 t. i/ b. ^% @9 j: w
.....++++++
) u+ m$ K+ M+ u- I% a* r3 N1 i.......................++++++& M# L3 Z% @2 q, ]
writing new private key to 'client.key'- f! e+ H/ L! Q6 w
-----
7 [7 [3 |" G5 ?5 wYou are about to be asked to enter information that will be incorporated
% N" o; Q& T; A, \5 x9 c0 u1 ]into your certificate request.4 o9 T( m" U0 g) w& \0 |' Y- e
What you are about to enter is what is called a Distinguished Name or a DN.
/ {! U7 W$ G% A6 Y1 R( YThere are quite a few fields but you can leave some blank
; M1 I  x, e9 F; r3 MFor some fields there will be a default value,
0 Y* ^5 P% _4 ?If you enter '.', the field will be left blank." d" K# @9 g3 `  w. R) t+ R+ ~
-----/ H! B2 y. S" e
Country Name (2 letter code) [CN]:0 L6 @& y1 Y2 t$ D( U' o9 v
State or Province Name (full name) [GD]:, L; Z6 f* R5 K! M3 D
Locality Name (eg, city) [SZ]:
' r5 ]' u. Q: g, M7 |1 SOrganization Name (eg, company) [DIC]:
. k1 L3 [7 F* }/ ZOrganizational Unit Name (eg, section) []:, j# A  G$ E- W" D5 j
Common Name (eg, your name or your server's hostname) []:tgh  #不同客户端,命名绝不能一样
, ~/ x2 }6 O+ `$ A4 }& Y! x/ O, e* {" UEmail Address [tghfly222@126.com]:
Please enter the following 'extra' attributes4 U/ L& l5 }! Q
to be sent with your certificate request
. n% K( q) N5 E8 gA challenge password []:dic172
% L0 D% V/ q  f2 F* k- [An optional company name []:dic172
$ Z- m  t, c0 hUsing configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf9 z; o. K( f1 I- N1 f2 |. f6 y+ ?
Check that the request matches the signature3 q/ P5 c( m: X1 a+ r% k
Signature ok
1 Z. [# R& X6 j5 x; v) TThe Subject's Distinguished Name is as follows6 U8 B" i9 Y' D) H
countryName           :PRINTABLE:'CN'
. _$ {, O: {6 o% R. k2 q) J# U: nstateOrProvinceName   :PRINTABLE:'GD'
, R( Y( F+ A: \" r0 {8 Z/ ^localityName          :PRINTABLE:'SZ'$ K; E# g. ^+ }9 e$ ~: H4 [
organizationName      :PRINTABLE:'DIC'+ ?  \; f4 l, g" v/ P* f7 h+ r
commonName            :PRINTABLE:'tgh'
% Y" L3 E' k5 @3 }emailAddress          :IA5STRING:'tghfly222@126.com'( `6 w2 A, }# H9 h+ O3 v3 F
Certificate is to be certified until Jul 16 05:52:27 2021 GMT (3650 days)
: B! C  V, t7 O1 U% b5 ?, x' ZSign the certificate? [y/n]:y

" A' K7 h' J3 D( ^: u1 out of 1 certificate requests certified, commit? [y/n]y
/ a# t( n$ M; m2 x+ rWrite out database with 1 new entries
: J$ q0 N/ G: x0 R5 [Data Base Updated
8、创建dhDiffie-Hellman )密钥算法文件
8 u( Z' T0 o# V[root@www.linuxidc.com easy-rsa]# ./build-dh . ~+ e# h* L, z( A; f; ~4 e8 a
Generating DH parameters, 1024 bit long safe prime, generator 23 D0 |: L6 _$ q! J) W
This is going to take a long time. z) d7 a7 b4 W8 g3 t7 N
...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成  tls-auth 密钥 ,tls-auth密钥可以为点对点的VPN连接提供了进一步的安全验证,如果选择使用这一方式,服务器端和客户端都必须拥有该密钥文件。
$ t7 w  m: I9 P( G- z# R9 w1 i$ \[root@www.linuxidc.com easy-rsa]# openvpn --genkey --secret keys/ta.key    & L7 H' N3 H- U8 n/ S
[root@www.linuxidc.com easy-rsa]# cp -rp keys/ /etc/openvpn/    #将证书文件复制到/etc/openvpn/   
10、修改server.conf配置文件, w( M. ~' e/ O2 T! ], c1 u
[root@www.linuxidc.com openvpn]# grep -v "#" server.conf
local 192.168.161.172     #服务器所使用的IP
- X' m! V1 `$ |0 c7 Fport 1194                      #使用1194端口8 v  u& T4 G; P7 F6 z7 P( u; H2 i
proto udp                      #使用UDP协议3 W9 p. l! q2 D' `5 c
dev tun                         #使用tun设备
- t# C6 q0 Q, {ca /etc/openvpn/keys/ca.crt    #指定CA证书文件路径% F* p( J2 j# B" O
cert /etc/openvpn/keys/server.crt* K' @' s' @, j8 B1 `: w; K6 d2 }
dh /etc/openvpn/keys/dh1024.pem, |4 e' |; ^, h' ^9 B" g& S
tls-auth /etc/openvpn/keys/ta.key 0/ H. W' H4 E7 a9 d: Q
server 172.16.10.0 255.255.255.0   #VPN客户端拨入后,所获得的IP地址池  s- T1 V2 b3 k% P8 V6 a1 `
ifconfig-pool-persist ipp.txt
9 k5 j9 v5 f& w8 Ipush "dhcp-option DNS 202.96.134.133"   #客户端所获得的DNS2 |2 D! I- p- m, X- n
client-to-client
6 T% k" @* h& u' G+ F! Qkeepalive 10 120
; O' r7 R9 B$ ^8 `  K3 Hcomp-lzo
- I& S% {& M: gpersist-key2 {5 M+ S8 r: T+ x  Z$ P+ P
persist-tun0 |8 a& M7 {, {6 E& [# C! ?- j
status openvpn-status.log
; v  j5 h! R% T4 Z- I; T0 Yverb 3( z9 z& u% e9 w6 c# \% q$ O/ c# Q
mute 20
[root@www.linuxidc.com openvpn-2.0.9]# service openvpn start
( u3 ~( Q; J1 \( ?5 X4 @- o- G6 @" A. VStarting openvpn: [  OK  ]6 h: Q" h0 T5 z, t! m: N
[root@www.linuxidc.com openvpn-2.0.9]# netstat -anp |grep :11946 Q7 {2 u$ [0 b* y+ R* Q& ^6 s. {
udp        0      0 192.168.161.172:1194        0.0.0.0:*                               25162/openvpn   
! A9 q  W; O4 K1 j% x0 p
四、在XP客户端配置SSL VPN(客户端IP 192.168.163.96)
( |1 V$ L( G: Y1 `  a. }1、到http://openvpn.se/files/install_packages/下载openvpn-2.0.9-gui-1.0.3-install.exe
, d+ [( ~- s" d0 ~7 B5 R. F2、安装openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由于只是做客户端使用,不必安装OpenVPN Service
& w7 o+ g! U3 v3 @/ R" x" R8 t
安装完成后,在任务栏会新增加一个OpenVPN GUI和本地连接图标。
3、配置客户端,把服务器上/etc/openvpn/keys/ca.*,client.*,ta.* 复制客户端C:\Program Files\OpenVPN\config下;再从C:\Program Files\OpenVPN\sample-config复制一个客户端配置样本文件client.ovpn到C:\Program Files\OpenVPN\config下。
- K9 ?& [$ C) [  g4 W) L

( O# j7 ?  A; O& E) A+ u
4、修改client.ovpn文件如下并保存。) t5 O. w) b; j- {$ M" K# f& _0 S/ l: k
client
2 ?4 h& b! N9 p- P4 R5 J5 ?5 b6 k4 Zdev tun9 r( b2 L4 f+ z4 }! {7 n; F8 Q% P
proto udp
( `7 x& y( U& z" C' Aremote 192.168.161.172 1194
* Y/ K" p1 ~7 h% ^6 o0 v/ Vresolv-retry infinite1 M" r  b7 {6 L5 ^
nobind
9 ~" K' Q, ?0 M" sca ca.crt3 [9 C& j( U; M( u0 O
cert client.crt( [6 P. h1 X7 P
key client.key2 H6 M0 w. c2 ~0 {
tls-auth ta.key 1* |' [3 J! G- j$ {/ L1 A( x  y
comp-lzo
0 ^, z6 y( \; g/ l2 e8 Xverb 3. H( O" k5 Q5 i5 [+ |
mute 20
! ?* ~& y! B7 c3 {7 J; S5、启动连接。右击右下角的OpenVPN GUI图标,连接
6、连接成功后,图标如下。到此,SSL VPN服务就配置好了。

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2020-1-19 09:02:06 | 显示全部楼层
lzo安装包
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 03:02 , Processed in 0.028666 second(s), 30 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表