爱爽爽

Redhat Linux企业版4 OpenVPN安装

上一篇 / 下一篇  2007-09-14 21:18:07 / 天气: 阴雨 / 心情: 平静 / 个人分类:Linux

DOIT博客7h F5u"W`\ h5e7Khn'N

一、 需求DOIT博客~#J0A4r'q"Sf:T
1、 安装方便,平台兼容性高,不用编译内核。(我比较反感动不动就要重新编译内核的软件);
dV4G#x9k3}%K|$]u02、 能够没有限制的穿透NAT内网;(这个非常关键,因为现在我的服务器是在学校拖管,我们实验室内部都是一层一层NAT出去的,)
G^Ec)g+^0由于以上两点限制,在现有许多种方案中,我试用了两种:pptpd和opensvn。pptpd是网上比较推荐使用的,因为配置非常方便,就改两个小文件就可以配置成功。但是有一个致命的弱点是起了两个端口,大多数情况下穿透NAT是个障碍,所以我最终放弃了。改用opensvn后解决了NAT的问题,在内网和公网上测试没有任何问题。DOIT博客(C Z:C~Q:fH3E#g%b{$P
openvpn的唯一缺限是不能够使用Windows内置的vpn客户端,需要另外安装软件,所幸安装过程很简单。DOIT博客6@V A'yA!R&t#h
DOIT博客-],pQJIq\Dx)o
二、 安装环境
&c]Z7OM01. 服务器:Dell 6850服务器,Redhat Linux 企业版4 Update 2,内核2.6.9-22.ELsmp。DOIT博客t%}/?\y%b
2. 客户端:Windows xp SP2DOIT博客!G_:w~,v W)YY!o%n
3. 网络结构:
A.qg2R2D:v%j0
^P9hcY!z i0DOIT博客dFgE9k._BD0p

'U#wI2m7n5h0a) 我们是北航校园网里面的一个实验室局域网,在学校网络中心托管了一台服务器gait.buaa.edu.cn。
:z0N2n4DZ2l!fd^!f+z_0b) 从我们实验室到校园网是一层NAT出去的。实验室里面是192.168.48.xxx的内网地址。
@ cPq"m EO`J0c) 服务器有对外的独立地址(属于教育网内的独立地址),目前由于网管中心的疏忽,对内、对外都没有做任何端口限制(由此可见北航网管的整体水平),因此开通VPN服务是有可能的。
t{,wn[ L5{(G o0d) 经过我的配置,gait.buaa.edu.cn上面起了VPN服务,默认的子网地址是10.0.0.1。这样在公网上的机器就可以拨入,而且可以连通到任何已经拨入这台服务器的校园网主机。形成一个虚拟的10.0.0.x子网。从这个意义上,VPN服务也像是一个“虚拟HUB”,使得学校内、外的计算机可以互通,使得经过层层NAT和防火墙拦截的计算机连到了一个局域上。
6A5k0M3v3dx1r'B.z0
7l1ha&u)X.T{&Y;B0三、 安装服务器
FFyAd01、 到http://openvpn.net/上下载openvpn的最新版,时至今日是openvpn-2.0.9.tar.gz。DOIT博客IPJ1}t8gl&Pt4J
a) 网上都说还需要lzo这个压缩库。我没有安装,在编译程序的时候只需要加上--disable-lzo就可以了。这样所有要安装的就是一个包openvpn-2.0.9.tar.gz。
X&H.Yx&Sw02、 上传到服务器gait.buaa.edu.cn上,解开成为/root/openvpn-2.0.9。DOIT博客2Pv'd-_6{
3、 cd /root/openvpn-2.0.9
;j,b7|2p+~ S$c04、 ./configure --disable-lzo。DOIT博客!tdw-r#N+PX W3u$e
a) 这个过程很可能需要Redhat的一些开发包,我安装的时候又打上了openssl-devel-0.9.7a-43.2.i386.rpm、zlib-devel-1.2.1.2-1.2.i386.rpm、e2fsprogs-devel-1.35-12.2.EL4.i386.rpm,当然如果是完全安装的服务器就不用了。DOIT博客r\r B#v;Hj!s:l
5、 make ; make install
-K0|'`rF6A.T0a) 我在很多机器上都做了编译,不应该出现任何问题。这个软件做的还是不错的。
}-D['}nC C sl06、 生成证书
'{2g,N-W Q/j0a) cd /root/openvpn-2.0.9/easy-rsa 
u]5E&fR%E#T0i. export D=`pwd` DOIT博客 zAO^S+A#f
ii. export KEY_CONFIG=$D/openssl.cnf 
+u^eK6d!M v2`E0iii. export KEY_DIR=$D/keys DOIT博客8FR1_ E.[
iv. export KEY_SIZE=1024 
R`i8Z[UN0v. export KEY_COUNTRY=CN DOIT博客:\5M#p+minKc)s~
vi. export KEY_PROVINCE=BJ 
;ncM!CP\HD0vii. export KEY_CITY=BJ DOIT博客S \@f-r'L,]
viii. export KEY_ORG="buaa" DOIT博客'W Ol-ghx0j
ix. export KEY_EMAIL=guojie.jin@hotmail.comDOIT博客%z6fH,n's c
b) ./clean-all 
son6nY&GV0c) ./build-ca
in`7_s){l8hB0./clean-all DOIT博客{ogqcN.wY$Iz5K
./build-ca 
XX9||yU#_j,|0
Sq&|!Q _Wp0Generating a 1024 bit RSA private key DOIT博客5^ e:yy {pg6I
................++++++ 
%H$[ YJR O%pQB0........++++++ 
){3wPgi p Wg1k!VQCZ0writing new private key to 'ca.key' DOIT博客8l4h;w\.s3u/l
----- DOIT博客\Xe9R$Y H9E3Y
You are about to be asked to enter information that will be incorporated DOIT博客r-r \0Gw%C)Z
into your certificate request. 
(J3cL0E0r'T_1F0What you are about to enter is what is called a Distinguished Name or a DN. 
8] Ma!aG:d9OZq0There are quite a few fields but you can leave some blank 
-fR)yh"f h)V1\ VV0For some fields there will be a default value, 
[t@.b"s0z&sH,~9lE0If you enter '.', the field will be left blank. 
8BQ+aA%K%m0----- 
s9i8M9ym0Country Name (2 letter code) [CN]: 
Nbt3bL,_ `}{0State or Province Name (full name) [BJ]: 
5X8S]+fO2b0Locality Name (eg, city) [BJ]: DOIT博客F?.V:dD"J
Organization Name (eg, company) [dvdmaster]: buaa
t.oi%F"q_Y1b0Organizational Unit Name (eg, section) []:gaitDOIT博客-v8f{0m3N^sXY
Common Name (eg, your name or your server's hostname) []:serverDOIT博客-Az@1sfk7n#Z
Email Address [[email]guojie.jin@hotmail.com[/email]]:
*gg$J)C)\:z0[$a0
v/Qjr1D#m(W hW0eh0DOIT博客V6@0w e9D _)G
DOIT博客3clg,a#R/v c+k/kr@ E"E
d) ./build-key-server serverDOIT博客1^ c1T_oDZ
./build-key-server server DOIT博客4[S%J;f$@,B2Qmy[

u;n$x sB5un X0Generating a 1024 bit RSA private key DOIT博客7c n1Ci L*m~s dt A
......++++++ DOIT博客:O$PTHF%L q?G+h
....................++++++ 
TfT,]1iJ0writing new private key to 'server.key' DOIT博客 ~@ D6W!rR
----- DOIT博客`d_f%g0TvMC
You are about to be asked to enter information that will be incorporated 
3?/QJ3F"}0into your certificate request. DOIT博客VHL(c5[ S u
What you are about to enter is what is called a Distinguished Name or a DN. DOIT博客.t;C~yC;gH.f
There are quite a few fields but you can leave some blank 
;l&p&}:PX0For some fields there will be a default value, DOIT博客!]A {7_*g!M1a
If you enter '.', the field will be left blank. 
AS#O7{!zD3Z D ?0----- DOIT博客C.c^4W4nI
Country Name (2 letter code) [CN]: 
"o1j1He5O R,Th\0State or Province Name (full name) [BJ]: 
C _rr&E3|ff o}0Locality Name (eg, city) [BJ]: DOIT博客}8h$I!pL$R
Organization Name (eg, company) [buaa]: DOIT博客s9j.O"WCJ-N
Organizational Unit Name (eg, section) []:gait
F k+i6LZk!P0Common Name (eg, your name or your server's hostname) []:server DOIT博客$Au;\y-U/?$P4h[]_,s
Email Address [[email]support@cooldvd.com[/email]]: DOIT博客jFF-Wy.|
DOIT博客RjDr:@K2wb`
Please enter the following 'extra' attributes DOIT博客,|3I#En.O2H_"@y:f
to be sent with your certificate request DOIT博客sk gj L2kG
A challenge password []:abcd1234 
#RC.Z {^ u/}7Q0An optional company name []:dvdmaster DOIT博客;Cq hAT`1{$E N
Using configuration from /openvpn-2.0.5/easy-rsa/openssl.cnf 
@3ZZU7fM0Check that the request matches the signature 
)t/Frz}7^Q0M%AU0Signature ok 
$dHiM tG @a w0The Subject's Distinguished Name is as follows 
n#{J1M_^0countryName :PRINTABLE:'CN' 
{k Qgj*]*}0stateOrProvinceName :PRINTABLE:'GD' 
%j:I }v])h-U-o$[*E0localityName :PRINTABLE:'SZ' DOIT博客$b c P"j NcG
organizationName :PRINTABLE:'dvdmaster' 
$|BQK V/^#PyvV0organizationalUnitName:PRINTABLE:'dvdmaster' 
?5T:z2Px.t0commonName :PRINTABLE:'server' DOIT博客/gQv.fe`
emailAddress :IA5STRING:'[email]support@cooldvd.com[/email]' 
g [(f*g1Lb0Certificate is to be certified until Mar 19 08:15:31 2016 GMT (3650 days) DOIT博客 \MdXY/qr,t
Sign the certificate? [y/n]:y DOIT博客2k/b[$DNqJ8n
DOIT博客&Pkpt${N-^,j
DOIT博客 d'B9qOe
1 out of 1 certificate requests certified, commit? [y/n]y 
4Pz D4s|#Lei}u0Write out database with 1 new entries DOIT博客H%BEw+bpB#Fq
Data Base Updated DOIT博客9d]I^7d3m
DOIT博客aO+z4NC
DOIT博客V#c(U#MQ

#X+~^-@2m|0e) 客户端证书
%aOJ ~"A2X0在openvpn中,这种配置方法是每一个登陆的VPN客户端需要有一个证书,每个证书在同一时刻只能供一个客户端连接(如果有两个机器安装相同证书,同时拨服务器,都能拨上,但是只有第一个拨上的才能连通网络)。所以需要建立许多份证书。下面建立三份,名称分别为client1 – client3。
MP'I4O*P@Da v6|j[0./build-key client1 
Pb'VL4ES'kIg,_s0Generating a 1024 bit RSA private key DOIT博客.Cq*l*B`y(y
.....++++++ 
9aK2{ IY"}N0......++++++ DOIT博客B*j @aa*]#G"I
writing new private key to 'client1.key' 
_2Q)Y#@ep `0----- 
*c V#a!fH0You are about to be asked to enter information that will be incorporated 
X D*T!u.B@9O9b0into your certificate request. 
&I y[:o C6T0What you are about to enter is what is called a Distinguished Name or a DN. DOIT博客%Hh-~ ]K DsHOB
There are quite a few fields but you can leave some blank DOIT博客9|?9[.kdn8A;P k?*I
For some fields there will be a default value, DOIT博客!J@8l Yt N
If you enter '.', the field will be left blank. 
+M7~%czmz5f0----- 
m#QMlB'DZ0Country Name (2 letter code) [CN]: DOIT博客5gJk[9a4t
State or Province Name (full name) [BJ]: 
+r~$\z-y y+@:v5MPD*Ed0Locality Name (eg, city) [BJ]: DOIT博客F,g/Z| e.et
Organization Name (eg, company) [buaa]: 
,g"p0VHA\l0Organizational Unit Name (eg, section) []:gait
~r*MZ)G0Common Name (eg, your name or your server's hostname) []:client1 #重要: 每个不同的 client 生成的证书, 名字必须不同. DOIT博客%h7C3D&D y/F
Email Address [[email]support@cooldvd.com[/email]]: 
8nDt5e|*g[&Y%Y0
gH&p4TtUp}0Please enter the following 'extra' attributes 
d2l:Nn$qx/H0to be sent with your certificate request 
FZ n)p^8@oC_0ML0A challenge password []:abcd1234 
x;K'S'b*o/Ardn \0An optional company name []:gait DOIT博客3Hy3jX1R ELa)R
Using configuration from /openvpn-2.0.5/easy-rsa/openssl.cnf 
Cs}#YnV8w%fdy0Check that the request matches the signature 
)g"G$c` ` cp:X0Signature ok 
L9P?#D? dp0The Subject's Distinguished Name is as follows DOIT博客i|7o6A*V
countryName :PRINTABLE:'CN' 
|[%}$P \T)Q:_;Z0stateOrProvinceName :PRINTABLE:'GD' 
Ti _S0XV!\*\0localityName :PRINTABLE:'SZ' 
3F3UF)v&uu&Ax&[b?0organizationName :PRINTABLE:'dvdmaster' 
;Mp,\C"~3e2@}D"[5z0organizationalUnitName:PRINTABLE:'dvdmaster' DOIT博客 `s Bz/sfQT
commonName :PRINTABLE:'client1' 
'Xu$Uc7nd'p+f`%lP R9y0emailAddress :IA5STRING:'[email]support@cooldvd.com[/email]' 
nC|?S!@5t!r }0Certificate is to be certified until Mar 19 08:22:00 2016 GMT (3650 days) 
^i0hjqzf0Sign the certificate? [y/n]:y DOIT博客sKs#n%e(x

~w @'B9A:]L0DOIT博客%cA+Z#Z^ S'I(n
1 out of 1 certificate requests certified, commit? [y/n]y 
ij1p.K+pc1@*\w Y0Write out database with 1 new entries DOIT博客 t"l6@!QL'm(dc
Data Base Updated 
'TY|Y(rGx;O/n0DOIT博客I9]vI2{8`F$`Q

s3wzL+eJ1CBI0f) 依次类推生成其他客户端证书/key: 
ASyNS)J\0./build-key client2 
(B^.b _W9D5g0P K0./build-key client3DOIT博客!C4dK n4fz$F#i+N9L
注意在进入 Common Name (eg, your name or your server's hostname) []: 的输入时, 每个证书输入的名字必须不同.DOIT博客"RQI6s'jjag4?/d
g) 执行./build-dh
#O&g'{E _ n]x0h) 生成的所有证书在/root/openvpn-2.0.9/easy-rsa/keys下。
{G+X-F`0U_5X(v0i. 其中服务器需要的是ca.crt、server.crt、server.key、dh1024.pem,每个客户端需要的是ca.crt、client1-3.crt、client1-3.key。DOIT博客6L;t$ac.`,l PT4E
7、 配置文件DOIT博客 ah-u'zW8ki x
a) cp /root/openvpn-2.0.9/sample-config-files/server.conf /usr/local/etc/server.confDOIT博客pv:N8eV
b) vi /usr/local/etc/server.confDOIT博客4E1G;Ij*W Sx.Fd
i. proto udp改成proto tcp
Z2`9r-G'd p)g0ii. ca那四行改成
!ef#v-U^,t {0ca /root/openvpn-2.0.9/easy-rsa/keys/ca.crt
#U%v,JN:NmMp X0cert /root/openvpn-2.0.9/easy-rsa/keys/server.crtDOIT博客X'B#mBD*xZ T|:C
key /root/openvpn-2.0.9/easy-rsa/keys/server.key
,Q0v!L4Bt6c4M0dh /root/openvpn-2.0.9/easy-rsa/keys/dh1024.pemDOIT博客'G5Cc!iW9r'p#m7s
iii. server那行改成
J4t T8P G!y0server 10.0.0.0 255.255.255.0DOIT博客T k)g[4z9wd
iv. 注释掉comp-lzo
|/x8A(s cs0v. 改成verb 5可以多查看一些调试信息
)TOjS}R&N08、 启动服务:
1VK+?#k!x:ji4C0a) 关闭服务器、防火墙上所有对SSH(22)、openvpn(1194)的拦截。DOIT博客)F3u{@n y
b) echo 1> /proc/sys/net/ipv4/ip_forwardDOIT博客6i0tb,Sb.B1s"@
c) /usr/local/sbin/openvpn --config /usr/local/etc/server.confDOIT博客,d.h%O ]6o:u T
d) 为了实现开机启动,在/etc/rc.local后面添加DOIT博客N.H A"Gp
/usr/local/sbin/openvpn --config /usr/local/etc/server.conf > /dev/null 2>&1 &DOIT博客h(T-L&a*n VV
4. 安装客户端DOIT博客1i-S}w?Ad
1、 从http://openvpn.se/上下载与openvpn服务器版本一致的Windows客户端“OpenVPN GUI For Windows”DOIT博客 SGtk;tE
a) 例如, 服务器装的是 OpenVPN 2.09, 那么下载的 OpenVPN GUI fow windows应该是: openvpn-2.0.9-gui-1.0.3-install.exeDOIT博客*d9D^:?;p
2、 执行openvpn-2.0.9-gui-1.0.3-install.exe。一切采用默认设置。DOIT博客PUhan/? pp
3、 将ca.crt、client1.crt、client1.key复制到C:\Program Files\OpenVPN\config。(不同用户使用不同的证书,每个证书包括.crt和.key两个文件,如client2.crt和client2.key)DOIT博客9jV4?MNxz ^h,c
4、 在/root/openvpn-2.0.9/sample-config-files/client.conf 的基础上建立客户端配置文件,改名为C:\Program Files\OpenVPN\config\client.ovpn
9f[^*Q,@"D0a) proto udp改成proto tcp
IF U+~~%|p {0b) remote那行改成DOIT博客3\d/gH7R0f3c'hxs
gait.buaa.edu.cn 1194DOIT博客,~*Pn;J)|
c) ca那3行改为DOIT博客f`)Hu2]y
ca ca.crtDOIT博客ZS.?2yHa ^ dC
cert client1.crtDOIT博客geSa{\AI!@q
key client1.keyDOIT博客TY4I'?4J
d) 注释掉comp-lzoDOIT博客)Ib-_#lhxO cG+U6a4en
5、 连接:在右下角的openvpn图标上右击,选择“Connect”。正常情况下应该能够连接成功,分配正常的IP。
+M&SL G0Wi!W0a) 在使用中发现,openvpn不是连续分IP,而是10.0.0.6、10.0.0.10、10.0.0.14、……这样分下去,不知是何用意。DOIT博客i+F(}$uYk-|H


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-05  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 3475
  • 日志数: 22
  • 图片数: 1
  • 建立时间: 2007-09-13
  • 更新时间: 2007-10-02

RSS订阅

Open Toolbar