易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 4618|回复: 1
收起左侧

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

[复制链接]
发表于 2020-1-19 08:52:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
一、OpenVPN是靠虚拟的TUN/TAP设备实现SSL VPN的,因此内核必须支持TUN/TAP设备模块,这个配置选项在2.6.x内核中,位于Device Drivers ->Network device support 菜单中,全称是Universal TUN/TAP device driver support ,通常在标准内核 中,会以模块方式提供,在Open VPN启动时,它会自动加载此模块,因此不需要手工加载此模块。. }  R# ^! A+ ~/ W
[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# pwd, \2 d: v# ^4 g8 d
/usr/src/kernels/2.6.18-238.12.1.el5-i686
3 u8 p; R" e8 P; d' c[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# make menuconfig  #打开内核菜单. K6 j9 T; U, @6 `9 S+ R1 ^
Device Drivers  --->            : m: }9 c5 O# a7 A0 k
Network device support  --->      
. j: I4 f$ G8 E' k" b<M> Universal TUN/TAP device driver support     #<M>即表示以模块化加载到内核中

, |0 ~9 D/ a* x4 J( R二、在安装OpenVPN之前,还需要安装一些支持包,包括OpenSSL开发库和LZO压缩开发库
( h, @- j! H4 M9 p, {7 U( _1、可使用yum安装OpenSSL开发库,但需要手工下载并安装LZO开发包。, Q( K1 j$ J. N; W/ N5 G
#yum install  openssl  4 w+ e- G' Y, K' o
# yum install openssl-devel
#yum install pam-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下载LZO  l9 p* q4 x% k! P' l  ~
# tar -zxvf lzo-2.10.tar.gz - W8 [) h+ v* T$ A
# cd lzo-2.10: U; I/ c# X! j# `+ @  G% R! T! i
#./configure
8 f9 S: _# I+ i# make ' ~, Z8 a' v7 |- U8 i8 p8 X
# make install
三、配置SSL VPN服务, `' H6 e0 a# \0 a
1、到  http://openvpn.net/release/ 下载openvpn-2.0.9.tar.gz并安装
1 H8 S$ O2 l: b6 v. I  H/ k& {8 d, D. Q# tar -zxvf openvpn-2.1.1.tar.gz ' z, ?2 R& [6 R2 g* z
# cd openvpn-2.1.1
0 C1 T- e; h: j: }( T6 h9 V7 l[root@webbs168x openvpn-2.1.1]# ./configure --prefix=/usr/local/openvpn
  S5 F. C- g! [[root@webbs168x openvpn-2.1.1]# make 3 u1 c/ D8 |$ _" g* s0 i
[root@webbs168x openvpn-2.1.1]# make install
+ Z5 }! f# @& }4 H[root@webbs168x openvpn-2.1.1]#cp -p sample-scripts/openvpn.init /etc/init.d/openvpn
; n6 [6 N( R* T2 Y4 i$ F, y' _[root@webbs168x openvpn-2.1.1]# chkconfig --add openvpn
- t: D6 s" l  o8 S4 k4 f9 R[root@webbs168x openvpn-2.1.1]# service openvpn status  #查看服务状态4 ^, N5 k9 O0 @' J6 b
openvpn: service not started( X: B4 f) y, X' G& Z6 ^2 o; w1 O

+ V( _$ H: L7 l1 E! C# chkconfig --list openvpn
( \- K) g8 G; @openvpn         0:off   1:off   2:on    3:on    4:on    5:on    6:off
2、开启IP转发功能$ H/ n- {% o8 w( k# U" o4 ]
#vi /etc/sysctl.conf
1 g/ p  B1 c* l9 x7 V' Y7 `net.ipv4.ip_forward = 1
2 ]1 z4 v* m0 A8 g& f# sysctl -p/ ~4 L5 a. H" \/ _9 g' x$ R
3、定义OpenVPN的配置目录为/etc/openvpn,把服务器配置文件定义为/etc/openvpn/server.conf
; p: H/ p! Q' o& D, _$ L' s# IOpenVPN是一个SSL VPN实现,因此,认证中最重要的是服务器和客户端的SSL证书管理,如果管理员之前没有SSL证书发布机制,那么可以使用OpenVPN附带的一组工具来完成所有的工作。: |) w/ R9 @: F  \2 [( k
在/root/openvpn-2.1.1中,有一个easy-rsa目录,这下面就是一些一成和管理SSL证书的工具,以下为生成证书操作。. x) Z* f& `. k6 [$ m. p( J
#mkdir -p /etc/openvpn
& {: |* b# I5 e! e: l/ q#cp -p sample-config-files/server.conf /etc/openvpn/   #将样本配置文件复制到/etc/openvpn/,后面再做修改
4、修改vars文件变量,设置国家代码、省份、地市、机构名单、单位名称邮件等
8 O/ t1 ^( H1 t* D) i#cd easy-rsa/
( E1 B- Q9 T8 `4 S+ M# grep -v "#" vars
) L$ b) \( N- L: k' T) `! N+ D1 r. xexport D=`pwd`' Z% L: Z( s* a& R4 ^+ L
export KEY_CONFIG=$D/openssl.cnf
% b4 y5 u2 {/ j. Z6 sexport KEY_DIR=$D/keys
! G/ e# t/ e1 \$ @% j- g  yecho NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR6 u) J, ^( m6 I1 G* O/ M) X8 H- X
export KEY_SIZE=1024
2 U$ f) v- o$ w6 e( P/ Pexport KEY_COUNTRY=CN
2 k% _( C: x. C: V, G6 o0 B  p6 [export KEY_PROVINCE=GD
) G0 f, P. G$ X* M% o0 w' m2 y. T! ^export KEY_CITY=SZ
5 u/ @% P# ?! y3 l% c  E9 Xexport KEY_ORG="DIC"
6 z, r& L* h6 c% Q1 t, iexport KEY_EMAIL="tghfly222@126.com"1 t2 S( X' K& T# ?4 {8 n  R
easy-rsa# source vars
* Z/ q0 f" l, Q% YNOTE: 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证书。( W; W# r. L; v; S
[root@www.linuxidc.com easy-rsa]# ./clean-all   #先清除证书,再创建证书& x3 o5 e& F0 N
[root@www.linuxidc.com easy-rsa]# ./build-ca  #创建CA证书- f% G+ b8 U/ D
Generating a 1024 bit RSA private key) j' t# }# g- C, ^0 o8 a7 V, I
..........++++++0 S5 @' E! U! J) I6 C/ u& b8 C. R
................++++++5 R1 |5 M$ n- A$ ?
writing new private key to 'ca.key'; [4 G* C8 v+ m8 c
------ A$ ]9 v* G) i8 e! A9 h
You are about to be asked to enter information that will be incorporated! B* y- c+ ^) H. F& b+ w# U# y
into your certificate request.+ q* H' S5 k9 }2 y3 S, h
What you are about to enter is what is called a Distinguished Name or a DN./ N" C& b2 l+ h5 X/ B
There are quite a few fields but you can leave some blank! T( y# n- H: A2 @
For some fields there will be a default value,
  z3 O) Y4 G& |5 Z( iIf you enter '.', the field will be left blank.
. ?' f9 J( Y* E: M% C3 E9 W-----7 R5 W/ G& Q) r: M
Country Name (2 letter code) [CN]:. ?9 Q! r0 n7 m; K5 ~, N
State or Province Name (full name) [GD]:& ]1 d9 p8 W9 Z' G% `5 n
Locality Name (eg, city) [SZ]:1 R; e0 ~4 w% Z5 u$ M+ S
Organization Name (eg, company) [DIC]:
- ~' y( f+ d* N3 G" m# ]8 s* ]! TOrganizational Unit Name (eg, section) []:1 G$ b0 ?1 B# A/ x+ Q% J
Common Name (eg, your name or your server's hostname) []:dic172   #服务器主机名% B4 Y+ J/ C8 l7 O% }' N$ s5 A
Email Address [tghfly222@126.com]:
6、创建服务器密钥。& I0 Y2 x( s5 T
[root@www.linuxidc.com easy-rsa]# ./build-key-server server  #创建服务器端密钥, a9 M) u7 c/ Q* _6 x
Generating a 1024 bit RSA private key
+ A0 W7 k2 v  E+ l. t5 h- W............................................++++++* L+ Y6 h0 b$ C/ M) ~  g8 }
....++++++
4 T8 m6 @! U9 x: m* Cwriting new private key to 'server.key'. @8 @' O0 b+ B9 @  |
-----5 u* A2 r) n+ g% g& u% k
You are about to be asked to enter information that will be incorporated) v( E1 @6 t9 O% M
into your certificate request.
! C3 m3 L4 p3 }1 i& pWhat you are about to enter is what is called a Distinguished Name or a DN." f2 J7 r2 h; U9 h) t2 `% V% t
There are quite a few fields but you can leave some blank
9 G0 k# C' ]5 T3 q+ sFor some fields there will be a default value,! C" F$ f( x6 w1 i6 E  A
If you enter '.', the field will be left blank.
9 J, h( m/ \% w3 e-----
0 E; D  H/ S% ?Country Name (2 letter code) [CN]:1 U: }9 Y% t% O- X7 v& O
State or Province Name (full name) [GD]:
/ `# g# V3 E9 P9 Q7 l9 z" sLocality Name (eg, city) [SZ]:
# s6 w6 h4 R1 K) B7 ^: {Organization Name (eg, company) [DIC]:2 L9 d/ a. ?* b1 N2 X
Organizational Unit Name (eg, section) []:0 ?& j3 H+ @7 Y4 u) U  O+ A
Common Name (eg, your name or your server's hostname) []:dic172  #服务器主机名* x5 \& s6 @* v; g1 ]4 J, n; E2 j
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes+ _5 i0 f2 i. y1 U1 P" w
to be sent with your certificate request
0 u  h; W+ e8 z8 J3 {A challenge password []:dic1724 Y& O6 }4 {; ~' l3 i; S
An optional company name []:dic1723 d0 {8 {+ B- N7 L- B# Z
Using configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf/ ^& u  z6 d: ]) `; I( @4 n
Check that the request matches the signature2 k/ g, _! E4 p5 r7 ~2 v
Signature ok4 i& I- _) o$ a5 z
The Subject's Distinguished Name is as follows6 J( D. `: S1 Z/ l- S+ U
countryName           :PRINTABLE:'CN'
/ k  k) ?# B9 g! k* L, ystateOrProvinceName   :PRINTABLE:'GD'2 F2 U6 c1 y* R  f/ M7 S
localityName          :PRINTABLE:'SZ'8 p! Y6 @! S) F% I( `- z, Y! B
organizationName      :PRINTABLE:'DIC'
- \& c9 I- J/ |( p3 scommonName            :PRINTABLE:'dic172'
* m% K3 f/ u5 g6 s( Y' hemailAddress          :IA5STRING:'tghfly222@126.com'
9 V9 M% [; s3 f' mCertificate is to be certified until Jul 16 05:51:08 2021 GMT (3650 days)4 _- I) p* Q! D% a
Sign the certificate? [y/n]:y  s) g) W8 a% V8 I5 N6 W+ G( z
1 out of 1 certificate requests certified, commit? [y/n]y6 P' c: b3 o& j6 G8 [) u
Write out database with 1 new entries& ]" g% W$ A2 v  ^* f9 w7 N
Data Base Updated9 f3 t/ u" a* Y! E! g
7、创建客户端密钥,客户端密钥名可随意命名。
: k! Z" M: o' A* O2 k* |0 b[root@www.linuxidc.com easy-rsa]# ./build-key client1 G2 j: D' P, w
Generating a 1024 bit RSA private key- f4 R$ X$ ]  t0 u+ A: c
.....++++++, ]' a% \8 {7 I9 C0 Z% m" f
.......................++++++
. f2 [3 w1 ]  b# z6 m" xwriting new private key to 'client.key': G+ u% p2 |. Q: D
-----) d: x* i  R1 W. r2 C6 a
You are about to be asked to enter information that will be incorporated
8 _! ~! Y% z3 P4 [' X, v( D( {into your certificate request.
; W4 K8 W, _2 P7 K- k6 eWhat you are about to enter is what is called a Distinguished Name or a DN., Q4 \5 F1 X+ s6 J: t1 P, E
There are quite a few fields but you can leave some blank
8 y& `- q* A8 B$ d* S% iFor some fields there will be a default value,
! L, A& _% S+ [6 V/ q, j  vIf you enter '.', the field will be left blank.8 s3 A3 d/ i* ~+ Z0 f! B& V
-----' d# I3 Q: h1 x) o4 A
Country Name (2 letter code) [CN]:( L5 M: G5 j/ d. {  z4 I& I  q; X
State or Province Name (full name) [GD]:) W  b3 e& s' W/ Z
Locality Name (eg, city) [SZ]:' y; V2 e- s9 m* D. A/ j5 H
Organization Name (eg, company) [DIC]:% n3 ^  Q1 U5 j' ^+ N5 ]
Organizational Unit Name (eg, section) []:
9 [) Z$ r+ a$ V, YCommon Name (eg, your name or your server's hostname) []:tgh  #不同客户端,命名绝不能一样
( V/ g, `' \$ N- o* B7 y5 T* rEmail Address [tghfly222@126.com]:
Please enter the following 'extra' attributes
# M! o3 f& _4 I; k: S$ B8 Xto be sent with your certificate request
. r: I0 _, F' X8 ^) @! ]$ q9 VA challenge password []:dic172
6 C; H4 w0 y. V1 tAn optional company name []:dic172
4 H8 a% t( g: f% e$ m1 ^Using configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf# J9 X  R" t2 L+ A
Check that the request matches the signature. S4 |1 `  t: m/ ]/ L/ P! b
Signature ok# T7 z) }' f3 \% W' E3 _% J
The Subject's Distinguished Name is as follows
9 E# Y% m7 b% K6 g0 o8 Y- ~5 {, l- E7 p  fcountryName           :PRINTABLE:'CN'6 h8 C; D9 Q5 y2 h, H* E
stateOrProvinceName   :PRINTABLE:'GD'
& F/ C$ c  ]9 ]* plocalityName          :PRINTABLE:'SZ'
% Y9 q/ l1 n& C& F4 G+ zorganizationName      :PRINTABLE:'DIC'
2 J$ a# Z$ M" N- RcommonName            :PRINTABLE:'tgh'
6 E- z# {) g& \* FemailAddress          :IA5STRING:'tghfly222@126.com'  G( ]- E) ?: u1 ]" G
Certificate is to be certified until Jul 16 05:52:27 2021 GMT (3650 days)
# n' n: F9 X+ o; T/ m$ \Sign the certificate? [y/n]:y
/ c0 M# D; z* r
1 out of 1 certificate requests certified, commit? [y/n]y
$ y* R  L6 ?4 B8 N# l! W3 ^" A% BWrite out database with 1 new entries$ q, i/ g$ i. W* Q5 d" }$ i
Data Base Updated
8、创建dhDiffie-Hellman )密钥算法文件, e- `3 x' C( G( ~% z  v" D
[root@www.linuxidc.com easy-rsa]# ./build-dh 2 |# F2 ?& J" }% O0 A
Generating DH parameters, 1024 bit long safe prime, generator 2" z. X) E3 c" L2 j- M
This is going to take a long time
3 d5 |' I6 ^4 j# p) F* @...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成  tls-auth 密钥 ,tls-auth密钥可以为点对点的VPN连接提供了进一步的安全验证,如果选择使用这一方式,服务器端和客户端都必须拥有该密钥文件。 0 @) \8 U" y# t3 l, t2 X
[root@www.linuxidc.com easy-rsa]# openvpn --genkey --secret keys/ta.key    % t7 y3 p6 R  K* l9 E
[root@www.linuxidc.com easy-rsa]# cp -rp keys/ /etc/openvpn/    #将证书文件复制到/etc/openvpn/   
10、修改server.conf配置文件4 {3 i5 g; w5 U9 S4 @1 \! ]* N" o
[root@www.linuxidc.com openvpn]# grep -v "#" server.conf
local 192.168.161.172     #服务器所使用的IP+ }9 n& T9 h6 w! ]3 S" }
port 1194                      #使用1194端口9 D# g- H9 e" I% Y
proto udp                      #使用UDP协议
$ j  A# u, B3 d9 A) W9 h7 rdev tun                         #使用tun设备
9 }# V! P- u% p! b6 [3 }- \ca /etc/openvpn/keys/ca.crt    #指定CA证书文件路径
. J8 Z. |4 V/ z# B+ b" Scert /etc/openvpn/keys/server.crt7 ]: p% m( t, [) W5 J# P
dh /etc/openvpn/keys/dh1024.pem
0 J3 s1 _! i" j; O+ i" c, u$ stls-auth /etc/openvpn/keys/ta.key 0
# S/ \5 E$ A' O" eserver 172.16.10.0 255.255.255.0   #VPN客户端拨入后,所获得的IP地址池- U! J% D5 X- K' Y* n
ifconfig-pool-persist ipp.txt
$ e' x7 A6 L% Q5 s* xpush "dhcp-option DNS 202.96.134.133"   #客户端所获得的DNS- ~3 {) A0 E2 {
client-to-client
4 W, J9 l2 h. ?! O. W5 o9 hkeepalive 10 120
8 t' {( S1 V$ G& i, Q" M8 q1 qcomp-lzo: a) `! Z% s/ e# h, u: t4 }
persist-key) W; C& m) D4 y4 L1 E
persist-tun: u# y' a7 [% Y
status openvpn-status.log( A- \0 _1 H3 @  i* W6 D1 v( c/ _1 g2 n
verb 3
' b6 ~& {' y+ s1 {mute 20
[root@www.linuxidc.com openvpn-2.0.9]# service openvpn start5 I+ V$ j" H2 P% j' Z
Starting openvpn: [  OK  ]
3 Z: ~. X* P7 U6 Q& a9 b: Z[root@www.linuxidc.com openvpn-2.0.9]# netstat -anp |grep :11947 H( V  c* P( u
udp        0      0 192.168.161.172:1194        0.0.0.0:*                               25162/openvpn   
) u1 g1 W" N: z1 e9 g
四、在XP客户端配置SSL VPN(客户端IP 192.168.163.96)3 _1 p' V& e6 R# M8 t! I6 h/ O, h
1、到http://openvpn.se/files/install_packages/下载openvpn-2.0.9-gui-1.0.3-install.exe
+ o0 i: i5 z+ I2、安装openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由于只是做客户端使用,不必安装OpenVPN Service

! ]# E+ e  E4 }1 Z% E# B# v- }$ z1 M
安装完成后,在任务栏会新增加一个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下。( V( M$ Q& u2 @2 e: [* s

& ?0 f4 A- q9 q- @: L+ `; X5 T
4、修改client.ovpn文件如下并保存。) x( M' b5 @3 h4 l2 B' G
client! y/ v5 M- m" ~
dev tun
# ^* ]3 i  e: Zproto udp
6 E7 Q" |% V5 a$ {9 b9 {5 tremote 192.168.161.172 1194
9 ^, D; t( p  L! {resolv-retry infinite2 q+ j8 o* w- }* C7 J
nobind
! _9 m, [# G0 \2 wca ca.crt" \9 E; f! y& j
cert client.crt
) U$ p" ~8 ~, k3 W% qkey client.key/ `2 K- l0 x& m$ I
tls-auth ta.key 1
6 v2 L; v6 j9 S9 N$ jcomp-lzo" _2 J$ W: T  g
verb 3
' Q8 m+ X+ H- P* `mute 20, N3 `/ w5 X2 N: q" k. G3 L0 w
5、启动连接。右击右下角的OpenVPN GUI图标,连接
6、连接成功后,图标如下。到此,SSL VPN服务就配置好了。
 楼主| 发表于 2020-1-19 09:02:06 | 显示全部楼层
lzo安装包

lzo-2.10.tar.gz

586.54 KB, 下载次数: 0

售价: 2 金钱  [记录]  [购买]

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 23:58 , Processed in 0.060031 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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