找回密码
 注册
查看: 4624|回复: 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启动时,它会自动加载此模块,因此不需要手工加载此模块。% L3 q3 C+ s5 h9 j
[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# pwd( Y: _" R* p2 h+ O5 @: G
/usr/src/kernels/2.6.18-238.12.1.el5-i686
# p; J! z: {. Y  m# p& j[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# make menuconfig  #打开内核菜单
& H  K. S( x( k Device Drivers  --->            
) T  p( _4 F6 S1 M, }4 o Network device support  --->      
; C$ }- I) G% _" q4 ^8 l<M> Universal TUN/TAP device driver support     #<M>即表示以模块化加载到内核中
  I: c  {) v- j! U* i0 ?& W0 P
二、在安装OpenVPN之前,还需要安装一些支持包,包括OpenSSL开发库和LZO压缩开发库9 _. Y4 `5 u9 \# q4 z* H
1、可使用yum安装OpenSSL开发库,但需要手工下载并安装LZO开发包。
% D" Y5 X5 D3 l7 G" P8 B7 L#yum install  openssl  # G8 V$ P$ l+ Y2 D% n8 ?
# yum install openssl-devel
#yum install pam-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下载LZO
& m- F2 H5 Y3 I' d4 [  r# tar -zxvf lzo-2.10.tar.gz
+ }: F+ l6 ?- F; @/ u- H6 R# cd lzo-2.10' @6 ~2 X( c$ w+ Z  x' L
#./configure2 g8 f0 W' A4 [! @
# make ; R7 }2 e: S3 A! a
# make install
三、配置SSL VPN服务
) N7 p& ?, n. E8 f$ `1、到  http://openvpn.net/release/ 下载openvpn-2.0.9.tar.gz并安装2 K( |7 a* A) @" f7 C
# tar -zxvf openvpn-2.1.1.tar.gz ! l$ U% h* y# X/ r- _
# cd openvpn-2.1.1
+ R% ]4 G; [+ t$ B; H( G[root@webbs168x openvpn-2.1.1]# ./configure --prefix=/usr/local/openvpn
0 q1 e! n8 }. i& `3 Q, a[root@webbs168x openvpn-2.1.1]# make
  s" s& T/ A" y# w[root@webbs168x openvpn-2.1.1]# make install$ L3 X6 h0 I5 s7 r' U6 [% x4 J
[root@webbs168x openvpn-2.1.1]#cp -p sample-scripts/openvpn.init /etc/init.d/openvpn0 B3 ]0 O+ G4 U' b- X, ~3 Z8 t
[root@webbs168x openvpn-2.1.1]# chkconfig --add openvpn* P4 `- g4 ^$ ^5 ?2 G9 A, x
[root@webbs168x openvpn-2.1.1]# service openvpn status  #查看服务状态
7 D" ^1 a8 ]+ dopenvpn: service not started  K; z3 c0 B' Z; y

; M( u& u5 z3 A# N! ?4 k" D2 ]# chkconfig --list openvpn# G9 }" ?# A) a& Q" r; F! o
openvpn         0:off   1:off   2:on    3:on    4:on    5:on    6:off
2、开启IP转发功能
# y7 D8 M( W. }+ p4 i3 H8 x1 o#vi /etc/sysctl.conf0 Z9 D6 q" Q4 l* X9 ^1 H! D
net.ipv4.ip_forward = 1
# U' g# T8 X) S# ?0 }# sysctl -p- h9 a8 n) a, [2 ^# s
3、定义OpenVPN的配置目录为/etc/openvpn,把服务器配置文件定义为/etc/openvpn/server.conf% V( r& S2 S- ~3 U
OpenVPN是一个SSL VPN实现,因此,认证中最重要的是服务器和客户端的SSL证书管理,如果管理员之前没有SSL证书发布机制,那么可以使用OpenVPN附带的一组工具来完成所有的工作。
( V# V7 v- S" u1 B1 R4 }/ w& t9 N* A在/root/openvpn-2.1.1中,有一个easy-rsa目录,这下面就是一些一成和管理SSL证书的工具,以下为生成证书操作。
3 K$ \6 C- y% W2 c) O4 u, y$ Z#mkdir -p /etc/openvpn. Q' e( b7 T) F
#cp -p sample-config-files/server.conf /etc/openvpn/   #将样本配置文件复制到/etc/openvpn/,后面再做修改
4、修改vars文件变量,设置国家代码、省份、地市、机构名单、单位名称邮件等
5 ?( |, m6 a3 }#cd easy-rsa/& \& C! [+ X. v  S( A1 r
# grep -v "#" vars
: T/ W4 E9 ~. ^6 W3 qexport D=`pwd`. c# O$ L2 n3 ?* J. d
export KEY_CONFIG=$D/openssl.cnf- @, V7 e7 e0 w6 Y* Q# o
export KEY_DIR=$D/keys
  o8 \( ^9 {+ G! _) A3 S& pecho NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
( ?" f3 [$ ^! E4 Vexport KEY_SIZE=10249 @# O3 r* |% p& l. o
export KEY_COUNTRY=CN
$ v+ t: h) Y" ?" A6 Kexport KEY_PROVINCE=GD
. Z5 }3 T, z; k8 q( G* Wexport KEY_CITY=SZ
1 W6 P' |: G7 N! M4 Hexport KEY_ORG="DIC"* c; g. m7 s, k  o( F1 S  l7 E
export KEY_EMAIL="tghfly222@126.com"
2 n: V* T+ i1 c% @* }easy-rsa# source vars7 B! _- V% O4 H5 a+ p
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证书。  Y0 j9 U+ p5 ~' s$ [2 J
[root@www.linuxidc.com easy-rsa]# ./clean-all   #先清除证书,再创建证书
1 c$ B1 h1 _5 H[root@www.linuxidc.com easy-rsa]# ./build-ca  #创建CA证书
# A& f2 C  t* F4 m. dGenerating a 1024 bit RSA private key
8 d/ S  b+ `$ e8 `..........++++++
' G5 D# Q3 B4 j( H................++++++4 f8 P8 S5 Z  H. G1 `$ m
writing new private key to 'ca.key'* Y; |+ R, \2 O: A$ z( s/ e0 N
-----; W, A- w% p- G( K/ n6 {( V+ r' I$ o
You are about to be asked to enter information that will be incorporated
; s7 f9 t8 [( \5 T' r5 C/ ointo your certificate request.! X0 D9 _0 k9 H- K: M9 ?/ h/ X
What you are about to enter is what is called a Distinguished Name or a DN.) B) S; i) C. J% T" `: s
There are quite a few fields but you can leave some blank
# C/ n& S6 _5 Q9 ^  z( L6 X( KFor some fields there will be a default value,* i* l; C  J( D! u! M. B& P0 g* z
If you enter '.', the field will be left blank.
* c1 T- k  @, }$ Q-----
* l, J! G1 J1 Y5 m3 k# dCountry Name (2 letter code) [CN]:) `- b% H3 i  u" g2 [. K) F7 J2 l
State or Province Name (full name) [GD]:
5 h3 a9 f, R8 e; M  C) ~Locality Name (eg, city) [SZ]:
9 u2 k1 c  e! m% G$ VOrganization Name (eg, company) [DIC]:4 W2 {' B( |9 }3 U$ @* S
Organizational Unit Name (eg, section) []:
. D" f  H* L- H9 x% T# yCommon Name (eg, your name or your server's hostname) []:dic172   #服务器主机名
' V2 p/ W+ F" M' {Email Address [tghfly222@126.com]:
6、创建服务器密钥。% l7 I. }! y( y; @  I6 ]* o
[root@www.linuxidc.com easy-rsa]# ./build-key-server server  #创建服务器端密钥1 h9 y' m! k% D7 s, i
Generating a 1024 bit RSA private key* Y# V- N, \3 A$ ^8 D( Q' l; \9 y  Q
............................................++++++
- M2 a0 j# M0 X' a  b) b8 d....++++++
  x+ `2 i- {2 I* K7 l8 {writing new private key to 'server.key'3 x3 A* [- n: E: a/ \7 A
-----
' \: g; j/ ~* b  I/ EYou are about to be asked to enter information that will be incorporated$ z# |; ^+ @/ N8 G% H1 X
into your certificate request.
( T8 U# z' a0 o  HWhat you are about to enter is what is called a Distinguished Name or a DN.
& i" p9 l5 J* Z7 iThere are quite a few fields but you can leave some blank5 d  q8 z9 P% W. n: l! E& X
For some fields there will be a default value,+ H' Q: ]; I0 z# s) x( l, w
If you enter '.', the field will be left blank.
0 @# c. U1 g: t-----
- |& e' }4 `" a/ [$ V4 a0 y0 iCountry Name (2 letter code) [CN]:
( e2 T" s$ V# g% E- mState or Province Name (full name) [GD]:! R( T4 p# O% t. a
Locality Name (eg, city) [SZ]:
2 }7 ^1 E8 z9 V! e9 ?) I. L/ \* k, vOrganization Name (eg, company) [DIC]:1 U" g( z; i0 q/ q- C& h
Organizational Unit Name (eg, section) []:; ]1 O' @$ W0 _7 c2 L
Common Name (eg, your name or your server's hostname) []:dic172  #服务器主机名, `$ a! F& m9 d  w0 A
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes
, h& E+ m" f+ b" F- ito be sent with your certificate request3 \* y: F  m3 k+ R% W. p; r9 |
A challenge password []:dic172% t$ _$ l; j7 |$ b5 p
An optional company name []:dic1729 Q) V0 _( z: B0 q  D
Using configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf
& }5 w( ?. _$ S& ?. S  WCheck that the request matches the signature! o6 j$ j' W! n( @( S
Signature ok2 h* X2 N9 H' ]' [
The Subject's Distinguished Name is as follows
9 `! ?" r  m+ N+ ]. xcountryName           :PRINTABLE:'CN': X, s5 D8 f$ `$ A6 ?, L( N  [5 K
stateOrProvinceName   :PRINTABLE:'GD'
" |0 u' a6 |0 g+ MlocalityName          :PRINTABLE:'SZ'* O3 g- `2 ]( N
organizationName      :PRINTABLE:'DIC') i  ?5 X7 m' M  }$ [4 Z- e/ _
commonName            :PRINTABLE:'dic172'! X$ q. @# H' N' w2 X+ T' ]
emailAddress          :IA5STRING:'tghfly222@126.com'2 a  s9 |5 Q# H  G0 g  O
Certificate is to be certified until Jul 16 05:51:08 2021 GMT (3650 days)/ ?! N' k7 ?+ }" {% I! s
Sign the certificate? [y/n]:y
: g* X5 Z+ G  G$ v1 out of 1 certificate requests certified, commit? [y/n]y
2 S$ Q+ M3 Q) T& RWrite out database with 1 new entries
  n: n3 Q  ]' n* VData Base Updated
: T9 J  o% [3 U) E7、创建客户端密钥,客户端密钥名可随意命名。" E" f4 f3 b# y( f6 K! I
[root@www.linuxidc.com easy-rsa]# ./build-key client9 d( b4 ?5 E5 [6 {, T4 y5 t
Generating a 1024 bit RSA private key
) |! G+ a; h0 X) E, @: @.....++++++
4 [9 r3 l$ g0 A; [.......................++++++7 X1 N: h( k+ g3 G, }4 c+ W
writing new private key to 'client.key'
* r* K( q4 y2 ?2 p. r+ `& x9 o' O6 [-----. r2 K* O; j9 H3 u
You are about to be asked to enter information that will be incorporated
0 l( J+ M0 [; u+ B2 m: ~6 Jinto your certificate request.% Q& S# Y9 h1 o, Z. Q; U3 t
What you are about to enter is what is called a Distinguished Name or a DN.
3 `' F2 ?* }- k  iThere are quite a few fields but you can leave some blank/ {* |& @2 n2 _3 H9 u. h
For some fields there will be a default value,
- E+ c3 r, i2 _& lIf you enter '.', the field will be left blank.3 l! _+ Y' V3 a. t! f* I
-----# a, B6 K0 X  L" A( ~: e
Country Name (2 letter code) [CN]:" P/ X) I3 @5 y, w. m' ?$ k: {+ r3 w* U3 K% c
State or Province Name (full name) [GD]:# V8 v6 j3 p# z* ^; M
Locality Name (eg, city) [SZ]:
, w) \5 E! v: [3 @5 r3 MOrganization Name (eg, company) [DIC]:( p4 l. P# }+ T9 s6 p
Organizational Unit Name (eg, section) []:
3 `# S4 }6 q: j2 n% U1 ?Common Name (eg, your name or your server's hostname) []:tgh  #不同客户端,命名绝不能一样, L. _# q5 H/ _
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes
* O5 l/ ~7 S: [" m, M3 Hto be sent with your certificate request5 g: e' B/ t# K( |3 K  B) D0 S
A challenge password []:dic172  \8 ]+ E2 C! I  l5 h* ?  P: A* K4 S
An optional company name []:dic172
3 _# N3 Y$ _4 [# B; g# YUsing configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf
% w6 Y% Y3 ]/ @" \4 QCheck that the request matches the signature( ~3 L: L' a: I) ^& [" I
Signature ok9 k" e! H, o3 M6 D
The Subject's Distinguished Name is as follows6 k9 c7 l& e0 c  g% A2 J: s8 e
countryName           :PRINTABLE:'CN'% \/ [- V" @8 `& U  D9 r$ d" L
stateOrProvinceName   :PRINTABLE:'GD', Z: I& V' e- ~8 t
localityName          :PRINTABLE:'SZ'
5 w# @# Y3 b/ b0 f! F2 l% morganizationName      :PRINTABLE:'DIC'3 G: D$ J6 _$ s2 [2 ^: e. |
commonName            :PRINTABLE:'tgh'
% Y3 r1 P; k5 YemailAddress          :IA5STRING:'tghfly222@126.com'# `, A% B% G2 @1 O
Certificate is to be certified until Jul 16 05:52:27 2021 GMT (3650 days), l) g! T  l7 s$ F
Sign the certificate? [y/n]:y
# l" x2 E8 o6 k& v0 q
1 out of 1 certificate requests certified, commit? [y/n]y
! U+ q" C& L' s5 |3 T' @6 b# z0 }Write out database with 1 new entries; O/ y. y" d3 C
Data Base Updated
8、创建dhDiffie-Hellman )密钥算法文件
2 d' O& h; |9 K% @0 j[root@www.linuxidc.com easy-rsa]# ./build-dh ' P4 X- w$ S% [7 N
Generating DH parameters, 1024 bit long safe prime, generator 2
' p0 d# c5 z2 n; u# BThis is going to take a long time* C$ b0 q- \! |4 Y5 }# s) X
...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成  tls-auth 密钥 ,tls-auth密钥可以为点对点的VPN连接提供了进一步的安全验证,如果选择使用这一方式,服务器端和客户端都必须拥有该密钥文件。 2 c1 r' @1 c; F- D
[root@www.linuxidc.com easy-rsa]# openvpn --genkey --secret keys/ta.key    3 [0 R% E5 L/ ?8 j% t; \" Y
[root@www.linuxidc.com easy-rsa]# cp -rp keys/ /etc/openvpn/    #将证书文件复制到/etc/openvpn/   
10、修改server.conf配置文件
1 h9 h$ z2 L0 I1 N& U  T[root@www.linuxidc.com openvpn]# grep -v "#" server.conf
local 192.168.161.172     #服务器所使用的IP! c+ J3 k- b' z8 k  d9 b: w
port 1194                      #使用1194端口
* e: D( ~+ W; H! l5 iproto udp                      #使用UDP协议
& o# ^/ m: g4 e1 o7 w4 Ydev tun                         #使用tun设备$ }3 o4 Z, F2 m$ [" Q1 f
ca /etc/openvpn/keys/ca.crt    #指定CA证书文件路径) w$ k/ h) t$ Q/ s5 {0 H
cert /etc/openvpn/keys/server.crt  |/ j5 W* g4 U% O
dh /etc/openvpn/keys/dh1024.pem
$ D* h2 \* D4 n$ ^9 n9 G5 Htls-auth /etc/openvpn/keys/ta.key 0
- a6 n" u0 y! V) H* e9 Cserver 172.16.10.0 255.255.255.0   #VPN客户端拨入后,所获得的IP地址池
: M8 q( N2 u& ~5 L) x1 _8 mifconfig-pool-persist ipp.txt
1 ?+ j5 i  ?( P8 o$ Y; t; r4 wpush "dhcp-option DNS 202.96.134.133"   #客户端所获得的DNS
4 c. Q; H, M, e  ^" h6 l' _* c" Gclient-to-client% P, r/ L7 S; u% r) f8 q4 R! Z* H  C
keepalive 10 120
0 E2 f2 c! [0 B( H( }comp-lzo' M! e2 q# [! [2 }1 x- Y
persist-key6 P. G- A2 ~: r# f4 ~
persist-tun  K3 A" ]- J3 i
status openvpn-status.log7 N6 b0 B5 [/ ?& |1 h
verb 3
8 s# }! C" s* I  f1 Mmute 20
[root@www.linuxidc.com openvpn-2.0.9]# service openvpn start) S3 P6 @* k9 k3 Q! z
Starting openvpn: [  OK  ]
) T& E" f. g9 r# S/ M: O, X* Y[root@www.linuxidc.com openvpn-2.0.9]# netstat -anp |grep :11948 P; u( [; e; ]7 @' r, L3 _
udp        0      0 192.168.161.172:1194        0.0.0.0:*                               25162/openvpn   
7 T4 f/ ^. a  H2 _
四、在XP客户端配置SSL VPN(客户端IP 192.168.163.96)6 E4 W; ?% E, p& r
1、到http://openvpn.se/files/install_packages/下载openvpn-2.0.9-gui-1.0.3-install.exe5 b/ J6 p' g0 h$ i, t5 L
2、安装openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由于只是做客户端使用,不必安装OpenVPN Service

" J4 G, f& D" y
安装完成后,在任务栏会新增加一个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下。
+ h( l5 j) O& d6 z% b, w/ G

  r& w0 S( r' H# D& V* x
4、修改client.ovpn文件如下并保存。1 d' G$ i( y! D' Y% n* @: \
client, u9 `# h- p" i  u" r( g
dev tun: R+ D7 O# M# {& z
proto udp1 @0 y# A) L" k
remote 192.168.161.172 1194
+ X+ O) V  e6 b" b: [) Uresolv-retry infinite
7 i0 I$ C! e1 ynobind
# N% N) o3 B* q' U8 ?1 R2 e. wca ca.crt
' M7 g9 k4 L$ |( Vcert client.crt
6 T+ ^! U/ }+ w" mkey client.key
, w9 |! Z4 S3 J" d2 S. ntls-auth ta.key 1
8 L  q0 s7 L% ~, Z8 rcomp-lzo6 R2 }' z8 n/ l$ V" D$ M
verb 3
8 r8 q: P& U  ]3 A5 F& p. W7 Zmute 20# j$ K7 t- u* _  f, u0 B' s
5、启动连接。右击右下角的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 04:09 , Processed in 0.032272 second(s), 30 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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