找回密码
 注册
查看: 4621|回复: 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启动时,它会自动加载此模块,因此不需要手工加载此模块。
0 H# d5 v0 i( s) W[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# pwd' s8 H# z* A& W) [; j# |6 A. p
/usr/src/kernels/2.6.18-238.12.1.el5-i686
# n: v9 S8 W; I7 i9 s- Y[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# make menuconfig  #打开内核菜单
  n( e! T& @' s  J% Y6 m6 Y) {% ]" h Device Drivers  --->            , i: G# G+ S. j* E" d: I
Network device support  --->       " Y2 |% o, @( d5 x
<M> Universal TUN/TAP device driver support     #<M>即表示以模块化加载到内核中
/ I  P2 a! E3 U7 r) }" N& @
二、在安装OpenVPN之前,还需要安装一些支持包,包括OpenSSL开发库和LZO压缩开发库( v0 p4 S/ u1 @% a  r, `: K+ t3 @
1、可使用yum安装OpenSSL开发库,但需要手工下载并安装LZO开发包。
; B; K' V4 f8 j( E1 g  A#yum install  openssl  # q7 s. ]6 H& @" D5 {# J" ?" |6 f
# yum install openssl-devel
#yum install pam-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下载LZO
* P+ j$ F1 b) Z3 z: |3 z! A# tar -zxvf lzo-2.10.tar.gz : }- i/ [& m" }% P  |: X6 X
# cd lzo-2.10
: b( O) Y3 D: E1 U1 e2 z  A! P( D1 ~#./configure
  ^: w/ A/ Z5 c) O0 F7 ]* M# make 0 A( A" R! U1 H1 r" O
# make install
三、配置SSL VPN服务' O/ W% _! }- a/ `+ c. i+ n
1、到  http://openvpn.net/release/ 下载openvpn-2.0.9.tar.gz并安装7 y' J. X0 f6 x$ M* r' {: G6 m
# tar -zxvf openvpn-2.1.1.tar.gz $ G% [' }" f2 p: R  _7 o
# cd openvpn-2.1.13 [8 J. Y/ B% J' A5 E, Y# p+ F
[root@webbs168x openvpn-2.1.1]# ./configure --prefix=/usr/local/openvpn
  n9 K* K- i6 C' _* U1 r& [* m1 e0 Z[root@webbs168x openvpn-2.1.1]# make
2 U( E; j" a  ^% f; e[root@webbs168x openvpn-2.1.1]# make install
/ k# g! q: [2 c  K* A) Z. E[root@webbs168x openvpn-2.1.1]#cp -p sample-scripts/openvpn.init /etc/init.d/openvpn
( _# }% ^+ W* Y4 v! a7 F' |- C[root@webbs168x openvpn-2.1.1]# chkconfig --add openvpn
- K8 l$ }# G  r- D# d3 t[root@webbs168x openvpn-2.1.1]# service openvpn status  #查看服务状态
+ f; g9 N; l7 w" N4 nopenvpn: service not started
' d. |' O! F. t, d1 R2 M+ L$ y; G2 ]% g, ^/ ?1 w  b) K
# chkconfig --list openvpn
# m* E2 B' H$ `( H, Y" J/ j9 s: gopenvpn         0:off   1:off   2:on    3:on    4:on    5:on    6:off
2、开启IP转发功能
) x: U: e2 p  `: {; H#vi /etc/sysctl.conf
9 b6 M: }- r3 c$ L8 q% Knet.ipv4.ip_forward = 1
( }" x! K1 Y5 t7 m6 v# sysctl -p! g" Y  R4 {! k- ]) g# x
3、定义OpenVPN的配置目录为/etc/openvpn,把服务器配置文件定义为/etc/openvpn/server.conf
  P$ ?4 E4 V3 N* fOpenVPN是一个SSL VPN实现,因此,认证中最重要的是服务器和客户端的SSL证书管理,如果管理员之前没有SSL证书发布机制,那么可以使用OpenVPN附带的一组工具来完成所有的工作。
6 l% h& U$ `: D( u7 h; q在/root/openvpn-2.1.1中,有一个easy-rsa目录,这下面就是一些一成和管理SSL证书的工具,以下为生成证书操作。
+ ?5 z, ]! H4 n1 [; l& {9 V  R#mkdir -p /etc/openvpn
0 @$ r' Z& x- {7 O/ G#cp -p sample-config-files/server.conf /etc/openvpn/   #将样本配置文件复制到/etc/openvpn/,后面再做修改
4、修改vars文件变量,设置国家代码、省份、地市、机构名单、单位名称邮件等
  m7 e% `: c9 @# Z8 Y1 a#cd easy-rsa/
4 L4 O( D+ {! G9 a# grep -v "#" vars + i& ^( ~6 J. P, \& g% ]. y
export D=`pwd`$ @9 ~3 K  k2 |  y  U/ F
export KEY_CONFIG=$D/openssl.cnf
# }! M  W( Q% h1 S8 J1 Lexport KEY_DIR=$D/keys& N/ k5 ^# U2 v' W6 y; h" f7 C
echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
4 s5 a4 ~: o" q& r1 f, E3 nexport KEY_SIZE=1024' w& X$ u4 W) N5 S
export KEY_COUNTRY=CN
& Z  \4 U! k, \8 X, s+ t+ ^export KEY_PROVINCE=GD
" N8 Y% H+ s  O7 K6 Aexport KEY_CITY=SZ1 L! q# b$ D. }3 s7 d2 x
export KEY_ORG="DIC"& ?- Q) r7 C) n3 t/ F$ {3 y
export KEY_EMAIL="tghfly222@126.com"  n8 _! ?9 w2 N) }) H# w) C
easy-rsa# source vars
; o0 B+ B5 y* G+ lNOTE: 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证书。9 X/ s8 C2 g2 t/ \3 T. H
[root@www.linuxidc.com easy-rsa]# ./clean-all   #先清除证书,再创建证书
9 p% ?" N: A9 f' o/ E5 l$ q1 U5 N[root@www.linuxidc.com easy-rsa]# ./build-ca  #创建CA证书
9 Z. c- Z- d: eGenerating a 1024 bit RSA private key3 e' ~) n& H7 X' W, U5 K) a  V6 q
..........++++++
* s1 F" i" j/ Q- o) y9 c" O................++++++9 f8 b! p; A" N' J
writing new private key to 'ca.key'. X) A/ ~- M1 i% u' ]* W
-----
$ R- I2 X/ B2 [You are about to be asked to enter information that will be incorporated2 J+ J! j$ B7 K2 g+ s- O
into your certificate request.4 Q, q. E: o- C1 K4 t. w
What you are about to enter is what is called a Distinguished Name or a DN.& d4 z2 E* Y( d1 C/ T9 w. c! [
There are quite a few fields but you can leave some blank! F6 z, R+ ?1 _. ]4 r' f
For some fields there will be a default value,
) `- r/ g+ Y0 B2 q5 H. K9 AIf you enter '.', the field will be left blank.! r4 H0 ?1 e, P1 R: ^0 G$ r' L
-----
* G; i7 I8 k6 o8 a; ?Country Name (2 letter code) [CN]:7 R& o/ T" ^( e* D# c: H- s
State or Province Name (full name) [GD]:
4 Z6 ]' M8 z2 i- g) Z+ F* }Locality Name (eg, city) [SZ]:5 @$ ]8 ^% |  L: U( K
Organization Name (eg, company) [DIC]:: Q) s- B7 ]; V" ]8 S& o
Organizational Unit Name (eg, section) []:
0 M* A8 x/ N: n' TCommon Name (eg, your name or your server's hostname) []:dic172   #服务器主机名
" A$ o3 m% f$ z7 d  Q$ a* KEmail Address [tghfly222@126.com]:
6、创建服务器密钥。, p' D) x4 ~+ _9 p1 {
[root@www.linuxidc.com easy-rsa]# ./build-key-server server  #创建服务器端密钥9 o' E7 M1 z2 y5 y  k
Generating a 1024 bit RSA private key
+ R+ ^; u+ t2 {; k# f) S, {............................................++++++8 R  {' `( n' d+ ]7 K  H) N
....++++++. N9 I* Y4 \; h( d
writing new private key to 'server.key'1 p( \! f; e, [1 h( l
-----
( D5 z: H4 ^, j, MYou are about to be asked to enter information that will be incorporated$ n  n5 f" Y5 Z* [' u, t3 z
into your certificate request.
8 r1 h' \- ?) ~$ Y/ cWhat you are about to enter is what is called a Distinguished Name or a DN.) e6 ^( |3 R! A% D% o6 `
There are quite a few fields but you can leave some blank8 N* |: X0 F2 G. ^
For some fields there will be a default value,' K- g6 S* s4 _
If you enter '.', the field will be left blank.4 P) G2 b0 p" ?, Z
-----
' a7 M6 w; G  x! O, O5 \Country Name (2 letter code) [CN]:& H( s$ G3 {' a3 S' t
State or Province Name (full name) [GD]:, }/ h2 K1 T7 S2 R# l
Locality Name (eg, city) [SZ]:
% Y4 o; p; Z% D$ [* jOrganization Name (eg, company) [DIC]:
7 S. H1 l  R( S1 K5 [: K: H' FOrganizational Unit Name (eg, section) []:
" i/ p' d" c' C: uCommon Name (eg, your name or your server's hostname) []:dic172  #服务器主机名# v$ W% K* D( o; {
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes9 s$ O% V4 V, X
to be sent with your certificate request
9 Y1 e7 }: I/ Q% ]7 e, [/ \) cA challenge password []:dic172
2 P0 ^, F" M& EAn optional company name []:dic172
+ z: s+ L2 F- J2 z; w9 }' qUsing configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf5 a! |& A% u5 p9 j- a6 a) y4 n
Check that the request matches the signature
- c4 s/ e1 @5 Y" R$ ^Signature ok
2 ]$ Y5 x: n( ~( k$ s8 M1 E& _7 \The Subject's Distinguished Name is as follows
3 V9 h9 `4 x' Y4 p+ bcountryName           :PRINTABLE:'CN'
$ S( h' b0 K9 v* ~stateOrProvinceName   :PRINTABLE:'GD'# X& G( i% Y) M9 R8 f  U# O
localityName          :PRINTABLE:'SZ'
/ Y, \& E8 ~) d6 G) ]6 j7 eorganizationName      :PRINTABLE:'DIC'
8 V: X# s; g3 |* y* V9 v; w8 EcommonName            :PRINTABLE:'dic172'
6 Y; N2 a5 O8 J+ Z, BemailAddress          :IA5STRING:'tghfly222@126.com'' V; p: N; `$ `, d# n6 n
Certificate is to be certified until Jul 16 05:51:08 2021 GMT (3650 days)5 r) T1 M. {. P
Sign the certificate? [y/n]:y- N2 Q) [& G9 v# `' x9 @
1 out of 1 certificate requests certified, commit? [y/n]y  \2 A$ t2 j% r0 t! Z- F9 b
Write out database with 1 new entries
# z" v4 o- [1 x5 @Data Base Updated
% b, e+ t) `, v; J1 l0 {7、创建客户端密钥,客户端密钥名可随意命名。; j5 C  L5 r* R4 {
[root@www.linuxidc.com easy-rsa]# ./build-key client
8 ^3 N9 R0 H5 K' |  L& \" [8 ]. bGenerating a 1024 bit RSA private key
) ~5 ~6 q) u' R( E$ m/ @* a6 ~.....++++++$ a% R. X' s( w7 \) l+ x" G
.......................++++++
& Z2 \( J+ P" o) @writing new private key to 'client.key'
  E8 D6 _6 I2 C& s5 r2 W+ m, X-----& a. h. d& M& a4 n! v) U
You are about to be asked to enter information that will be incorporated
/ J: {5 \9 Y8 V$ P' Yinto your certificate request.
+ j! ?1 \% e# f, P" V8 y' t( ^7 l  z6 XWhat you are about to enter is what is called a Distinguished Name or a DN.8 O. |0 W. Z) w, S
There are quite a few fields but you can leave some blank/ M# ^+ u1 g& s3 a& ^# [
For some fields there will be a default value,
, p# K$ @% @- `8 k  u. l! FIf you enter '.', the field will be left blank.* s& M$ m- P4 ~
-----
4 T# {. S& m& I5 |, E( ]Country Name (2 letter code) [CN]:
/ a# ]  L' [& C, t: p* c. I4 zState or Province Name (full name) [GD]:7 q9 q5 a2 O! z3 B2 @
Locality Name (eg, city) [SZ]:3 @' H0 y% ?: e& B. j& Q
Organization Name (eg, company) [DIC]:/ F8 o0 m6 M0 T/ s! C7 L& x9 ?+ S" ^
Organizational Unit Name (eg, section) []:
2 n, m/ w1 M6 q' r9 J5 V) wCommon Name (eg, your name or your server's hostname) []:tgh  #不同客户端,命名绝不能一样0 L4 k2 ?7 x- }# T
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes1 E5 D7 |9 x' Z0 J5 J! Y7 D
to be sent with your certificate request) g) r; l2 Z* r2 K3 I6 Q
A challenge password []:dic172( c! r6 k/ W9 Q- n
An optional company name []:dic172
' [5 `) G& q+ V  y8 nUsing configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf8 X" q0 J% m6 G9 C
Check that the request matches the signature
5 b1 z. m" f8 x! p7 h1 b6 P% W2 KSignature ok. u; H% p- z! T' f8 w- ^8 `  {2 ?
The Subject's Distinguished Name is as follows
# v7 t# ^0 k$ n- Z# N! LcountryName           :PRINTABLE:'CN'
# C1 G- \% j* p5 D& ?3 `8 rstateOrProvinceName   :PRINTABLE:'GD'
8 F, m- f: ~( ?# D9 z1 L8 ClocalityName          :PRINTABLE:'SZ'; @7 O! }7 }! Y; m
organizationName      :PRINTABLE:'DIC'
6 {( H0 N1 v: S& _7 A; EcommonName            :PRINTABLE:'tgh'
1 G5 A+ _+ S' @5 i& [& remailAddress          :IA5STRING:'tghfly222@126.com'
. p8 ^3 q5 T1 G, G: M! Q3 VCertificate is to be certified until Jul 16 05:52:27 2021 GMT (3650 days)
: A9 |  S9 K1 I6 O4 @7 [- F% vSign the certificate? [y/n]:y

2 {. W8 }  E" o+ x0 e) B1 out of 1 certificate requests certified, commit? [y/n]y% @' G5 N: h% N+ s4 }) g+ x; q
Write out database with 1 new entries
% ^- m+ U( M4 PData Base Updated
8、创建dhDiffie-Hellman )密钥算法文件
( S$ [$ F  u0 G* s( ^( M[root@www.linuxidc.com easy-rsa]# ./build-dh 8 `( `, H* o+ R' J# r$ Z
Generating DH parameters, 1024 bit long safe prime, generator 26 @" ~; v' k6 [
This is going to take a long time
$ s5 L6 e/ K1 ?5 x...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成  tls-auth 密钥 ,tls-auth密钥可以为点对点的VPN连接提供了进一步的安全验证,如果选择使用这一方式,服务器端和客户端都必须拥有该密钥文件。 . }8 _6 V% q; h% z2 B
[root@www.linuxidc.com easy-rsa]# openvpn --genkey --secret keys/ta.key    ' c+ N0 J5 x3 K! D4 r0 B. P
[root@www.linuxidc.com easy-rsa]# cp -rp keys/ /etc/openvpn/    #将证书文件复制到/etc/openvpn/   
10、修改server.conf配置文件1 O6 |$ F- F/ g: S* _$ R
[root@www.linuxidc.com openvpn]# grep -v "#" server.conf
local 192.168.161.172     #服务器所使用的IP& c6 v0 S; ^$ P$ f; c! ]
port 1194                      #使用1194端口9 N! E9 i3 ?4 E+ N* P3 j
proto udp                      #使用UDP协议
. W& L8 G8 O; ?, k8 gdev tun                         #使用tun设备
; M5 r. @1 `% c- V, T3 H  yca /etc/openvpn/keys/ca.crt    #指定CA证书文件路径
% A' i. W# u% k- d- Ccert /etc/openvpn/keys/server.crt7 Z2 \- l4 Q% |, l  o+ k
dh /etc/openvpn/keys/dh1024.pem
1 {/ o7 W; ~4 v# J+ U5 |2 x7 F2 gtls-auth /etc/openvpn/keys/ta.key 0
  C, _' B7 v; T$ |- ^. Bserver 172.16.10.0 255.255.255.0   #VPN客户端拨入后,所获得的IP地址池# o- a- m9 x0 i3 _$ ~8 h/ q( \
ifconfig-pool-persist ipp.txt5 f7 r+ ]- y$ A! ]
push "dhcp-option DNS 202.96.134.133"   #客户端所获得的DNS: L2 T& o7 j" i* v3 l' p
client-to-client6 ~' i, p/ x6 B% B7 O0 V% z0 s
keepalive 10 120( G, P3 v& r$ J! o" z
comp-lzo
/ V6 @2 }% J8 u0 F1 {: h4 wpersist-key, d- q1 W& n5 H% R
persist-tun9 k' L. C: A- R  V, _. Q
status openvpn-status.log. d5 C* o' N! |8 m7 R( q; Q
verb 3* S* j/ i0 N0 q; K# O! c% s; ^6 `
mute 20
[root@www.linuxidc.com openvpn-2.0.9]# service openvpn start6 @9 `; l, o! @9 L- y
Starting openvpn: [  OK  ]) r$ ]& a- G7 e3 o
[root@www.linuxidc.com openvpn-2.0.9]# netstat -anp |grep :1194
$ Q7 b2 p* x7 K6 L8 Oudp        0      0 192.168.161.172:1194        0.0.0.0:*                               25162/openvpn   

# p9 q4 r3 \- F) C# V
四、在XP客户端配置SSL VPN(客户端IP 192.168.163.96)
& A, L9 {1 s( l* ]1、到http://openvpn.se/files/install_packages/下载openvpn-2.0.9-gui-1.0.3-install.exe' T: Y! i. n8 Z" q5 u6 e
2、安装openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由于只是做客户端使用,不必安装OpenVPN Service
( _% i1 ~$ `" g8 ^4 S- E6 h
安装完成后,在任务栏会新增加一个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下。2 `" }+ x9 C) H6 _, x

/ K8 Q: v* Y$ Y2 P/ o
4、修改client.ovpn文件如下并保存。
0 E3 M6 l9 v4 W9 Pclient0 n9 c9 m/ v, x) x, I
dev tun
7 l0 ^9 P4 D" S- [% wproto udp
: S* ?8 K: c# \* Vremote 192.168.161.172 1194
# m1 S% t  K1 Bresolv-retry infinite1 H' r) R( x0 n# t- S9 D) z& a
nobind
: P+ H% Y! B5 R# G2 t: S% {ca ca.crt
! C/ l% F+ P& U6 n0 x1 scert client.crt
( e1 [! T3 \  i/ [key client.key
- V8 s4 J) o+ q/ N/ ]6 ztls-auth ta.key 1
: l9 r, z% q; G( G' scomp-lzo/ R7 ]9 d" h* O$ Z' l0 w" |
verb 3/ c( f9 \% ^6 P3 F% y/ _
mute 20' [; j1 S1 z, ?' n' G/ _% [
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 01:56 , Processed in 0.045862 second(s), 33 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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