找回密码
 注册
查看: 4622|回复: 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启动时,它会自动加载此模块,因此不需要手工加载此模块。
" G; n9 @8 {$ r" B$ E2 z3 Q[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# pwd
) E- X+ c2 Y4 m3 [3 H/usr/src/kernels/2.6.18-238.12.1.el5-i6860 s# r( X4 Y2 }
[root@www.linuxidc.com 2.6.18-238.12.1.el5-i686]# make menuconfig  #打开内核菜单
8 `' A9 X# A6 ~. f  [ Device Drivers  --->            5 \. q8 P. j- ?) F
Network device support  --->       6 H/ a  }5 c! O$ {1 N( }& k8 C
<M> Universal TUN/TAP device driver support     #<M>即表示以模块化加载到内核中
, g+ V/ D% e8 x( h. ?. M% V3 C8 O
二、在安装OpenVPN之前,还需要安装一些支持包,包括OpenSSL开发库和LZO压缩开发库7 H' e1 d+ ]% e  Y8 {) m  M  p  D
1、可使用yum安装OpenSSL开发库,但需要手工下载并安装LZO开发包。
) S- F. k2 Y  D5 N% U#yum install  openssl  
1 q( l4 K5 F9 l+ `5 S7 T# yum install openssl-devel
#yum install pam-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下载LZO
$ @- z4 [$ R% G8 E, x# tar -zxvf lzo-2.10.tar.gz 2 l: P4 G  ~' ^- V
# cd lzo-2.10
% ^, }0 B- j& ^, `7 ^% t) K#./configure
8 I1 T5 ]+ ^2 R1 y7 k# make
* K% K8 a" J9 n* M6 \# make install
三、配置SSL VPN服务3 {4 x1 W6 \, ~5 ]- b7 h
1、到  http://openvpn.net/release/ 下载openvpn-2.0.9.tar.gz并安装1 r( H; G/ n; M: f$ N- P0 T. t
# tar -zxvf openvpn-2.1.1.tar.gz
# L  O5 v2 n. F8 I: Z# cd openvpn-2.1.1
, c8 ~8 N. D; f[root@webbs168x openvpn-2.1.1]# ./configure --prefix=/usr/local/openvpn
( w" f- w; a: i' s[root@webbs168x openvpn-2.1.1]# make
5 F9 z, {4 [' a1 }* x& F[root@webbs168x openvpn-2.1.1]# make install; A1 L  k1 [3 Q1 }  s4 q
[root@webbs168x openvpn-2.1.1]#cp -p sample-scripts/openvpn.init /etc/init.d/openvpn& q' |9 a' v& {  n
[root@webbs168x openvpn-2.1.1]# chkconfig --add openvpn
. c; z" G) {9 C. n[root@webbs168x openvpn-2.1.1]# service openvpn status  #查看服务状态0 R& m: T9 U( m
openvpn: service not started3 z0 q3 f8 g# B/ i( W6 d( x) |
( I$ M2 _4 h, q
# chkconfig --list openvpn
' \% R1 F- {! Z3 j+ H+ Mopenvpn         0:off   1:off   2:on    3:on    4:on    5:on    6:off
2、开启IP转发功能- ^0 E. V6 a" ?3 ?% w
#vi /etc/sysctl.conf
  h5 V$ R! F' C( xnet.ipv4.ip_forward = 1
  W7 c. K6 L4 s( Q2 C# sysctl -p! K) o! _0 P! x" {' H
3、定义OpenVPN的配置目录为/etc/openvpn,把服务器配置文件定义为/etc/openvpn/server.conf: |4 s3 K! Y0 W( T1 \
OpenVPN是一个SSL VPN实现,因此,认证中最重要的是服务器和客户端的SSL证书管理,如果管理员之前没有SSL证书发布机制,那么可以使用OpenVPN附带的一组工具来完成所有的工作。
  _4 d7 T) }# ~; x; Q% s$ k- h0 e" {在/root/openvpn-2.1.1中,有一个easy-rsa目录,这下面就是一些一成和管理SSL证书的工具,以下为生成证书操作。
! ]9 d/ a! K. l' S/ O, s#mkdir -p /etc/openvpn
% ]6 `* z4 D: r8 `) v- H#cp -p sample-config-files/server.conf /etc/openvpn/   #将样本配置文件复制到/etc/openvpn/,后面再做修改
4、修改vars文件变量,设置国家代码、省份、地市、机构名单、单位名称邮件等
) y9 v$ z; U8 U, W: ?- a#cd easy-rsa/. a: G7 h3 N2 Y) w  s4 l6 c3 [# J6 d
# grep -v "#" vars 2 B# _: z3 G! C
export D=`pwd`
/ d. E1 M1 T5 e9 A  ]export KEY_CONFIG=$D/openssl.cnf
3 V5 q; }! l2 K% |export KEY_DIR=$D/keys. s6 w! B: N) ~* I4 l% G% K, I
echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR% i  F$ z6 @+ K. i  ^! {
export KEY_SIZE=1024
8 ~. T5 ~3 Q; S/ g3 T+ l( Cexport KEY_COUNTRY=CN* {$ A" h! c1 k8 K' D$ e: U5 O
export KEY_PROVINCE=GD5 ]2 y2 ^: e1 w9 u3 i: W- a4 A8 i
export KEY_CITY=SZ
, A3 G7 `5 s6 {9 p4 {export KEY_ORG="DIC"
' p8 |+ b6 O4 o- I0 y2 j. y; \export KEY_EMAIL="tghfly222@126.com"
0 y1 D5 ?: c+ v. i* |. R) M  ^easy-rsa# source vars
1 [' Y: C. x0 G0 H4 v4 JNOTE: 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证书。
8 u/ T) `. p5 `& [$ g$ q7 P[root@www.linuxidc.com easy-rsa]# ./clean-all   #先清除证书,再创建证书
6 }$ t5 V' Z1 q) g0 t/ d, p[root@www.linuxidc.com easy-rsa]# ./build-ca  #创建CA证书
4 V% y3 Z/ Z" H: K3 t; F, r1 I1 [Generating a 1024 bit RSA private key+ _# F* T& e5 ?
..........++++++% V- z0 y9 t: h
................++++++" A1 s- j2 _% w7 |$ a
writing new private key to 'ca.key'
4 A+ j! t; g) Z# u-----
. L4 G" V6 U& W  pYou are about to be asked to enter information that will be incorporated7 i; u$ ^7 y4 j6 b9 C/ C/ V
into your certificate request.& l( u* w) {( ]
What you are about to enter is what is called a Distinguished Name or a DN." i, J5 R" `8 s' X
There are quite a few fields but you can leave some blank
+ k3 s5 c! U' e9 m, `/ l7 L+ SFor some fields there will be a default value,0 `/ f8 |: c& V& c9 O; }6 \7 a5 }
If you enter '.', the field will be left blank.) N, F5 D9 O! ~4 V) m
-----
2 u# v- i. R1 UCountry Name (2 letter code) [CN]:
' G$ C  J: |3 |" f$ O6 _State or Province Name (full name) [GD]:# I/ K# O, D( ^5 d. P9 ]
Locality Name (eg, city) [SZ]:! Z7 P8 p: s$ ^# e; U. z; C% b- u
Organization Name (eg, company) [DIC]:
: I( l; e' s. O6 C, K1 [' \Organizational Unit Name (eg, section) []:
0 K3 }# h1 r: v8 W0 OCommon Name (eg, your name or your server's hostname) []:dic172   #服务器主机名9 b5 M* Z$ x& t" R  D
Email Address [tghfly222@126.com]:
6、创建服务器密钥。
9 h' a. l0 |( b4 P( s  U, C1 d[root@www.linuxidc.com easy-rsa]# ./build-key-server server  #创建服务器端密钥0 V+ p1 _1 U6 x! ?/ G( V  B
Generating a 1024 bit RSA private key
5 ]" K! F" ?5 j& H& P$ W............................................++++++
3 B& i. P3 P3 ^0 F....++++++
8 J) B2 U! X$ k% P0 w2 Kwriting new private key to 'server.key'( c* v5 I! I& A6 X
-----4 N9 _1 f8 a# d' ?3 x# C% ?; O
You are about to be asked to enter information that will be incorporated
# y( J3 G: V! G3 q) ?into your certificate request.9 i5 Q" q6 S2 s, B8 v
What you are about to enter is what is called a Distinguished Name or a DN.
8 ]/ j' O' H- l6 nThere are quite a few fields but you can leave some blank/ f* d8 k9 T9 |. [+ V
For some fields there will be a default value," C2 x7 `" |$ ]: d) e! V
If you enter '.', the field will be left blank.
+ k( o, O0 ~8 P-----
6 e7 n! p1 v. C" t5 KCountry Name (2 letter code) [CN]:
9 y0 U  K) s' V( \( jState or Province Name (full name) [GD]:
: Q- l. x1 u& gLocality Name (eg, city) [SZ]:
. Q  _* v7 v( gOrganization Name (eg, company) [DIC]:
/ f  G) q% f/ ]0 q$ x( x( p2 z+ MOrganizational Unit Name (eg, section) []:5 q& X3 `: ^9 p8 a
Common Name (eg, your name or your server's hostname) []:dic172  #服务器主机名2 j4 H6 e+ E4 B# h
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes  `; P% |; M  G8 f
to be sent with your certificate request% b" N& r; I5 b3 s$ T  W: L' X
A challenge password []:dic172' g" Z9 z8 \0 b0 q* @
An optional company name []:dic172' c2 N" d5 F3 C: U' l' H0 V
Using configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf
5 \/ d& L5 l3 f, zCheck that the request matches the signature7 B$ Q" `; Z" ?; _2 a. T7 |8 s
Signature ok- L4 g. P3 \* x; m# {
The Subject's Distinguished Name is as follows
8 ?% R) [5 w) Z- N0 ncountryName           :PRINTABLE:'CN'4 q4 C- O6 N- a0 a: K4 `
stateOrProvinceName   :PRINTABLE:'GD'
! Z4 H; d9 }# s% n+ l8 K! E# QlocalityName          :PRINTABLE:'SZ'& S; c4 V* D" Q7 m1 d$ s' W- W, c
organizationName      :PRINTABLE:'DIC'% F* Y, b& w) ~8 X" N6 f
commonName            :PRINTABLE:'dic172'3 }9 ^# h( u2 U/ ^
emailAddress          :IA5STRING:'tghfly222@126.com'
5 v& G+ l. B* @7 n. n8 J, M' BCertificate is to be certified until Jul 16 05:51:08 2021 GMT (3650 days)+ M( J/ D$ F3 F3 U$ J7 o
Sign the certificate? [y/n]:y# ?  a- ?) F0 a$ Y5 C
1 out of 1 certificate requests certified, commit? [y/n]y
6 i- j; R$ n( ^: Z! Y& p  hWrite out database with 1 new entries$ m' ^( s  u) x* l
Data Base Updated
8 W# _, H' H$ ^* U/ R7、创建客户端密钥,客户端密钥名可随意命名。
7 ~* J! m" ^& y2 B: S/ h/ k2 F/ z3 S[root@www.linuxidc.com easy-rsa]# ./build-key client
0 Z) K/ h. U! MGenerating a 1024 bit RSA private key
* o0 T7 p/ ^5 e7 t$ d! a: ].....++++++5 E* p+ r- b( I: t& Y/ M# f5 ^
.......................++++++3 f; r! g1 K7 z4 L/ L7 A, Y& F$ m
writing new private key to 'client.key'
3 M/ `, G8 v; W# M0 v5 T6 K  r-----+ R7 S! n, R* |( ]% j! P7 f
You are about to be asked to enter information that will be incorporated
7 S3 d3 x, _1 Pinto your certificate request.! h  q; t* x( ^4 w( o. z
What you are about to enter is what is called a Distinguished Name or a DN.
5 d  O- @% |/ V% H5 t& dThere are quite a few fields but you can leave some blank! @, H/ J# t5 D% E" n$ V
For some fields there will be a default value,4 s6 d7 f4 e8 i) u! M
If you enter '.', the field will be left blank.9 B$ V' r% u, _6 `$ t- F' F
-----
; ~6 y+ T6 I$ d. ^Country Name (2 letter code) [CN]:/ Q7 r6 ~& O% P4 _5 I
State or Province Name (full name) [GD]:
+ V+ V$ w9 Y8 M" v" y" B: wLocality Name (eg, city) [SZ]:9 X0 f% A; [/ n* K5 ?
Organization Name (eg, company) [DIC]:8 L, G3 _( M0 o- E0 @
Organizational Unit Name (eg, section) []:/ w7 s" Z7 Y7 \: G* t' Z
Common Name (eg, your name or your server's hostname) []:tgh  #不同客户端,命名绝不能一样  k( X2 e! h- W& f6 s- `
Email Address [tghfly222@126.com]:
Please enter the following 'extra' attributes& e5 k0 P4 o+ `1 e6 S7 a
to be sent with your certificate request
/ W6 y% v4 }; R, vA challenge password []:dic172- [& @. n! K4 b! J3 z9 q; X: W
An optional company name []:dic172
9 Z- W) ]! P* u' _1 L& ^+ bUsing configuration from /usr/src/openvpn-2.0.9/easy-rsa/openssl.cnf
0 v$ T$ q/ Q7 C/ `; D3 N* zCheck that the request matches the signature
1 V0 J+ h, w* p& d' sSignature ok2 ~6 q! s: E( {
The Subject's Distinguished Name is as follows1 H" [/ h$ ^! D' z
countryName           :PRINTABLE:'CN'3 F6 W  [% @* w) L1 Z
stateOrProvinceName   :PRINTABLE:'GD'* P8 E; U, r, H, a/ t& F- Z
localityName          :PRINTABLE:'SZ'( H& ], l9 _9 |/ S$ k! ?
organizationName      :PRINTABLE:'DIC'
) j$ \* |+ f$ v8 z/ k  Q$ w8 gcommonName            :PRINTABLE:'tgh'- q% @( `$ Q) X9 E& h) U
emailAddress          :IA5STRING:'tghfly222@126.com'
( s: Y5 _6 b0 O. ^+ B( ZCertificate is to be certified until Jul 16 05:52:27 2021 GMT (3650 days)
- @0 y9 a3 v# o9 W$ aSign the certificate? [y/n]:y

. f5 v6 R$ d' X3 m1 out of 1 certificate requests certified, commit? [y/n]y
( y) c% C  }, |* U4 h. ~& S- s  bWrite out database with 1 new entries- v, u! J5 B+ _% S" p+ e
Data Base Updated
8、创建dhDiffie-Hellman )密钥算法文件
6 [) L4 P# U) V- G# F  w8 u[root@www.linuxidc.com easy-rsa]# ./build-dh
! \9 H( n) G! h  i  k$ }% y  [$ \Generating DH parameters, 1024 bit long safe prime, generator 2
$ Q* _4 t* p6 v. B8 E+ g# p* m: EThis is going to take a long time
! }; B1 L+ y8 m7 i5 N...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成  tls-auth 密钥 ,tls-auth密钥可以为点对点的VPN连接提供了进一步的安全验证,如果选择使用这一方式,服务器端和客户端都必须拥有该密钥文件。
) E( P. B4 m( v* ?3 J/ @[root@www.linuxidc.com easy-rsa]# openvpn --genkey --secret keys/ta.key      r5 x& k: j4 y9 Y% N. F, z
[root@www.linuxidc.com easy-rsa]# cp -rp keys/ /etc/openvpn/    #将证书文件复制到/etc/openvpn/   
10、修改server.conf配置文件
1 @- K+ p9 Q* X& l7 H- l& O[root@www.linuxidc.com openvpn]# grep -v "#" server.conf
local 192.168.161.172     #服务器所使用的IP( L+ N) r1 f  g9 K9 P! Z7 V
port 1194                      #使用1194端口
: l# n/ a! @; Yproto udp                      #使用UDP协议' q+ Q" P& F! p/ z" a) `  D
dev tun                         #使用tun设备
" a8 n- w& Y4 g+ gca /etc/openvpn/keys/ca.crt    #指定CA证书文件路径
! ~0 `4 i' v4 n$ K+ K, N' ?cert /etc/openvpn/keys/server.crt
) g8 z$ A3 s2 T8 d- Idh /etc/openvpn/keys/dh1024.pem" k! I% x* C/ [$ y: e: `* Q
tls-auth /etc/openvpn/keys/ta.key 0$ ?; ]( G( o$ W( x; w' ]* B4 |6 k
server 172.16.10.0 255.255.255.0   #VPN客户端拨入后,所获得的IP地址池  v& t" f6 Y3 T+ ~
ifconfig-pool-persist ipp.txt0 t4 U- R8 a: g7 S
push "dhcp-option DNS 202.96.134.133"   #客户端所获得的DNS; J& W5 H* w6 v) m& j! I4 `; j
client-to-client
2 j* r% l! `; g2 Dkeepalive 10 120
! M9 U( @  `$ ], o6 ~$ vcomp-lzo
. ^" Y# n$ c$ Z$ k) O' f! zpersist-key, B: M6 G5 }( ]9 y9 d
persist-tun
* Z6 g* p+ P* \+ Hstatus openvpn-status.log) ~$ I; `& _8 m+ J
verb 3% B# t* o8 _) n5 P6 r. A
mute 20
[root@www.linuxidc.com openvpn-2.0.9]# service openvpn start4 x) d) h& d) k' o$ P
Starting openvpn: [  OK  ]+ x# l+ }( @- m! L5 ^, p7 n* Z9 |/ S
[root@www.linuxidc.com openvpn-2.0.9]# netstat -anp |grep :11946 O- ~8 r! ?- X2 b$ K3 \6 S
udp        0      0 192.168.161.172:1194        0.0.0.0:*                               25162/openvpn   

4 `- V  E3 w4 F- g+ v
四、在XP客户端配置SSL VPN(客户端IP 192.168.163.96)
' g0 B4 O$ T& }% q$ n. _1、到http://openvpn.se/files/install_packages/下载openvpn-2.0.9-gui-1.0.3-install.exe# T/ J( e# e7 T# {5 @3 r
2、安装openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由于只是做客户端使用,不必安装OpenVPN Service

& N0 {9 M- S( b0 Q; g: @' U0 z
安装完成后,在任务栏会新增加一个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下。
7 Y! `" y4 B2 L
3 q3 O% W, j3 r( p* q$ c
4、修改client.ovpn文件如下并保存。
" M9 D& _; b8 P, E7 l' ^/ k! o/ kclient! C+ K; B8 u8 M  f! e6 W
dev tun, k, a4 V+ l% H" ]3 J
proto udp
) T. N3 \- G/ Yremote 192.168.161.172 1194
6 f5 e8 q! ]* ~resolv-retry infinite2 f& x, b& B+ }3 Z1 e% P& m
nobind2 Q* l$ [8 b  Y0 L$ R) B
ca ca.crt
% K* Q( V( T9 e) Y2 z( h/ p/ l: y* _cert client.crt
1 Q( N6 A  R2 F* @& Kkey client.key7 ]) D/ e7 y; `! C/ w
tls-auth ta.key 13 U" Y$ ]" l% |9 _- @( j
comp-lzo
; P+ S' j8 ^# s0 m! \verb 3
# o+ w/ p' f6 z* L; xmute 20& Y* U4 o7 f* S. x# l, \
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:59 , Processed in 0.040935 second(s), 30 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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