在Windows下安装OpenVPN经验分享
在Windows下安装OpenVPN经验分享
发布时间:2017-01-05 来源:查字典编辑
摘要:这里我仅仅做了在Windows2003Server上的OpenVPN客户端,其实要做成Server的话,也差不多。系统环境:Windows2...

这里我仅仅做了在Windows 2003 Server上的OpenVPN客户端,其实要做成Server的话,也差不多。

系统环境:Windows 2003 Server。双路网卡,一路接192.168.0.0/24网段,此网段出局,网关为192.168.0.101。另一路接192.168.1.0/24网段。让此台Win2k3作为Client段接入之前交代过的OpenVPN Server。OpenVPN Server的IP地址为123.123.123.233。

在Windows下使用的是基于NT系统的安装包

openvpn-2.0.9-gui-1.0.3-install.exe 下载地址: http://www.jb51.net/softs/120505.html

安装:双击+下一步+完成(这里我使用的默认安装路径 C:Program FilesOpenVPN )

1.首先通过找到安装的路径,并且查看下面有些什么东西。可以通过资源浏览器或者Cmd,个人认为Cmd可能看的比较清楚。(另外下面dir出来的东西当中很多其实是默认没有的,是我后来加进去的,比如一些Client的证书密钥以及ta密钥等等,要添加什么东西,放在什么位置,之后我都会详细讲。)

---------------------------------------------------------------

Microsoft Windows [Version 5.2.3790]

(C) Copyright 1985-2003 Microsoft Corp.

切换工作目录到OpenVPN的默认安装路径下

C:Documents and SettingsAdministrator>cd C:Program FilesOpenVPN

通过dir命令看看安装路径下面有些什么内容

C:Program FilesOpenVPN>dir

Volume in drive C is system

Volume Serial Number is 785C-92D5

Directory of C:Program FilesOpenVPN

2007-08-2816:48 .

2007-08-2816:48 ..

2007-08-2816:34 bin

2007-08-2714:09 1,233 ca.crt(这个是CA根证书文件,是从Server端拿过来的。和Server端用的是同一个CA根证书)

2007-08-2817:33 config (存放OpenVPN主配置文件的目录,无论是作为Client还是Server)

2007-08-2816:34 driver

2007-08-2816:34 easy-rsa

2006-10-0120:37 83 INSTALL-win32.txt

2007-08-2816:39 3,530 kcvpn1.crt(这个是Client端的证书文件,是根据CA根证书签发的)

2007-08-2816:39 684 kcvpn1.csr(这个荂lient端的SSL请求连接证书文件,也是根据CA根证书签发的)

2007-08-2816:39 887 kcvpn1.key(这个是Client端的密钥文件,也是根据CA根证书签发的)

2005-04-2117:54 28,387 license.txt

2007-08-2816:45 log

2005-08-1814:20 8,705 OpenVPN GUI ReadMe.txt

2004-05-1615:30 766 openvpn.ico

2007-08-2816:34 sample-config

2007-08-2714:09 636 ta.key (这个是ta.key密钥文件,从Server那里拿过来的,和Server端用的是同一个ta密钥文件)

2007-08-2816:35 72,907 Uninstall.exe

10 File(s) 117,818 bytes

8 Dir(s) 1,629,716,480 bytes free

------------------------------------------------------------------------

还记得在一套OpenVPN系统中一个Client需要从服务器那里得到些什么吗?

当然就是5个文件:

(1)CA根证书文件

(2)TA密钥文件

(3)Client端的证书文件

(4)Client端的密钥文件

(5)Client端的SSL请求连接文件

还有一样东西就是根据自己的Server实际情况配置的:

(6)Client主配置文件。(注意,与Linux系统不同的是在Windows系统下主配置文件后缀名为.ovpen,而在Linux系统下后缀名为.conf)

所以基本上一共需要以上这6样东西。

2.整备Client主配置文件

在Windows系统下,OpenVPN的主配置文件是放在安装目录下的一个叫config的目录中的。

转到安装路径下的一个叫config的目录下,里面放的就是VPN Client端的配置文件。

C:Program FilesOpenVPN>cd config

查看整个文件下的内容

C:Program FilesOpenVPNconfig>dir

------------------------------------------------------------------------------------

Volume in drive C is system

Volume Serial Number is 785C-92D5

Directory of C:Program FilesOpenVPNconfig

2007-08-2817:33 .

2007-08-2817:33 ..

2007-08-2817:33 383 client.ovpn(默认安装好后是没有这个文件的,需要手动创造编辑,并且后缀名为.ovpn)

2007-08-2817:24 385 client.ovpn.bak(这个文件也是默认没有的,是我对主配置文件的模版备份,请养成良好的习惯)

2007-08-2816:34 213 README.txt

3 File(s) 981 bytes

2 Dir(s) 1,638,834,176 bytes free

C:Program FilesOpenVPNconfig>

----------------------------------------------------------

3.编辑client.ovpn这个主配置文件

----------------------------------------------------------

dev tun

dev-node VPN

(设定VPN的网络接口名。注意在Windows系统中必须要有这一条,在启动OpenVPN进程的时候会启动一个虚拟虚拟网络接口,它必须要有一个名字,可以随便起,当运行OpenVPN进程时,可以通过ipconfig/all来看到多出来这个名字的网络连接。而在Linux系统中就不需要配置这一项,会自动启动一个tun0的网络接口。)

proto udp

remote 123.123.123.233 9988

resolv-retry infinite

nobind

#user nobody

#group nobody

(注意在Windows系统中这两行必须注释掉,这是在Linux系统中指定OpenVPN服务的宿主用户的,而在Windows系统中用不上,如果不注释的话会引起报错)

persist-key

persist-tun

ca "C:Program FilesOpenVPNca.crt"

cert "C:Program FilesOpenVPNkcvpn1.crt"

key "C:Program FilesOpenVPNkcvpn1.key"

(这里就是指定根证书CA,客户端证书,客户端密钥的路径。顺便提一下,由于我对Windows命令行下的路径表示不是很熟悉,所以这里我一共吃药3次。也希望大家能够注意一下:1.首先,不像Linux下有默认的主配置路径/etc/openvpn/,至少我用Set命令没有看到过OpenVPN在Windows下所用的变量路径,以致于直接打文件名的话在运行OpenVPN的时候会提示你找不到正确证书和密钥这样错误,所以必须要在这里打上绝对路径,囧。2.其次,在Windows系统中路径使用的是反斜杠杆,但是在配置文件中,你必须要像我这样使用双反斜杠表示,单斜杠就会报错,囧。3.最后,即时你注意到了上面两点也还是不够,你会发现如“Program Files”这样的目录名当中有空格,因此你必须要像我这样在输入完整的路径之后加上双引号才行,否则也会抱错,囧)

ns-cert-type server

tls-auth "C:Program FilesOpenVPNta.key" 1

(指定TA密钥的路径,请使用绝对路径来表示,路径格式要求请参考上面。另外作为Client的话后面要跟上参数1,如果作为Server的话后面要跟上参数0)

comp-lzo

verb 3

;mute 20

---------------------------------------------

这里我偷懒,我直接把一些证书密钥直接丢安装路径下了,其实可以做的规范些,就是自己在安装路径下建立一个Key或者别的名字的目录,将证书密钥这些文件都统一整理到这个目录下,然后再在主配置文件中写明这些文件的位置(反正也是要打绝对路径的- -),还是那句话,请严格仔细的核准主配置文件中的文件路径。

4.未启动OpenVPN进程时先察看网络接口。

这个是我这台主机上原有的网络接口信息。安装好OpenVPN-GUI后会多出一张网络接口,不过默认是未连接的。

------------------------------------------------------

Microsoft Windows [Version 5.2.3790]

(C) Copyright 1985-2003 Microsoft Corp.

C:Documents and SettingsAdministrator>ipconfig/all

Windows IP Configuration

Host Name . . . . . . . . . . . . : kserver

Primary Dns Suffix. . . . . . . :

Node Type . . . . . . . . . . . . : Unknown

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter VPN:

Media State . . . . . . . . . . . : Media disconnected

Description . . . . . . . . . . . : TAP-Win32 Adapter V8

Physical Address. . . . . . . . . : 00-FF-6F-CB-56-CF

Ethernet adapter NET1:

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : Broadcom 440x 10/100 Integrated Controller

Physical Address. . . . . . . . . : 00-18-8B-82-52-1A

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.1.102

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.1.1

DNS Servers . . . . . . . . . . . : 202.96.209.5

202.96.209.133

Ethernet adapter NET0:

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : ADMtek AN983 10/100 PCI Adapter

Physical Address. . . . . . . . . : 00-E0-4C-B3-F3-43

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.0.198

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . :

DNS Servers . . . . . . . . . . . : 192.168.0.201

202.96.209.133

C:Documents and SettingsAdministrator>

--------------------------------------------------

5.运行OpenVPN进程

运行方法很多:

(1)可以通过图形界面的方式用鼠标点击操作 C:Program FilesOpenVPNbinopenvpn-gui.exe

(2)也可以在Cmd命令行里输入执行命令openvpn-gui --connect client.ovpn

(3)也可以用鼠标右击你的client.ovpn主配置文件(如果是服务端的话右击server.ovpn文件),然后在弹出的快捷菜单中选中“Start OpenVPN on this config file”。

6.查看成功运行OpenVPN后的信息

显示

--------------------------------------------------------

Thu Aug 30 08:52:41 2007 OpenVPN 2.0.9 Win32-MinGW [SSL] [LZO] built on Oct1 2

006

Thu Aug 30 08:52:41 2007 IMPORTANT: OpenVPN's default port number is now 1194, b

ased on an official port number assignment by IANA.OpenVPN 2.0-beta16 and earl

ier used 5000 as the default port.

Thu Aug 30 08:52:41 2007 Control Channel Authentication: using 'C:Program Files

OpenVPNta.key' as a OpenVPN static key file

Thu Aug 30 08:52:41 2007 Outgoing Control Channel Authentication: Using 160 bit

message hash 'SHA1' for HMAC authentication

Thu Aug 30 08:52:41 2007 Incoming Control Channel Authentication: Using 160 bit

message hash 'SHA1' for HMAC authentication

Thu Aug 30 08:52:41 2007 LZO compression initialized

Thu Aug 30 08:52:41 2007 Control Channel MTU parms [ L:1542 D:166 EF:66 EB:0 ET:

0 EL:0 ]

Thu Aug 30 08:52:41 2007 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:

0 EL:0 AF:3/1 ]

Thu Aug 30 08:52:41 2007 Local Options hash (VER=V4): '504e774e'

Thu Aug 30 08:52:41 2007 Expected Remote Options hash (VER=V4): '14168603'

Thu Aug 30 08:52:41 2007 UDPv4 link local: [undef]

Thu Aug 30 08:52:41 2007 UDPv4 link remote: 123.123.123.233:9988

Thu Aug 30 08:52:41 2007 TLS: Initial packet from 123.123.123.233:9988, sid=2080

0d3a 0b281635

Thu Aug 30 08:52:41 2007 VERIFY OK: depth=1, /C=CN/ST=Shanghai/L=Shanghai/O=Center/O

[email=U=Center/CN=VPN01/emailAddress=kanecruisesisgod@hotmail.com]U=Center/CN=VPN01/emailAddress=kanecruisesisgod@hotmail.com[/email]

Thu Aug 30 08:52:41 2007 VERIFY OK: nsCertType=SERVER

Thu Aug 30 08:52:41 2007 VERIFY OK: depth=0, /C=CN/ST=Shanghai/O=Center/OU=Center/CN=VPN

[email=SRV01/emailAddress=kanecruisesisgod@hotmail.com]SRV01/emailAddress=kanecruisesisgod@hotmail.com[/email]

Thu Aug 30 08:52:42 2007 Data Channel Encrypt: Cipher 'BF-CBC' initialized with

128 bit key

Thu Aug 30 08:52:42 2007 Data Channel Encrypt: Using 160 bit message hash 'SHA1'

for HMAC authentication

Thu Aug 30 08:52:42 2007 Data Channel Decrypt: Cipher 'BF-CBC' initialized with

128 bit key

Thu Aug 30 08:52:42 2007 Data Channel Decrypt: Using 160 bit message hash 'SHA1'

for HMAC authentication

Thu Aug 30 08:52:42 2007 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES2

56-SHA, 1024 bit RSA

Thu Aug 30 08:52:42 2007 [VPNSRV01] Peer Connection Initiated with 123.123.123.233:9988

Thu Aug 30 08:52:43 2007 SENT CONTROL [VPNSRV01]: 'PUSH_REQUEST' (status=1)

Thu Aug 30 08:52:43 2007 PUSH: Received control message: 'PUSH_REPLY,route 111.111.111.36 255.255.255.0,route 222.222.0.98 255.255.0.0,route 123.123.123.2

34 255.255.255.255,route 10.99.0.0 255.255.255.0,ping 10,ping-restart 120,ifconf

ig 10.99.0.10 10.99.0.9'

Thu Aug 30 08:52:43 2007 OPTIONS IMPORT: timers and/or timeouts modified

Thu Aug 30 08:52:43 2007 OPTIONS IMPORT: --ifconfig/up options modified

Thu Aug 30 08:52:43 2007 OPTIONS IMPORT: route options modified

Thu Aug 30 08:52:43 2007 TAP-WIN32 device [VPN] opened: .Global{6FCB56CF-B12

5-4D24-91A3-822CE03972DD}.tap

Thu Aug 30 08:52:43 2007 TAP-Win32 Driver Version 8.4

Thu Aug 30 08:52:43 2007 TAP-Win32 MTU=1500

Thu Aug 30 08:52:43 2007 Notified TAP-Win32 driver to set a DHCP IP/netmask of 1

0.99.0.10/255.255.255.252 on interface {6FCB56CF-B125-4D24-91A3-822CE03972DD} [D

HCP-serv: 10.99.0.9, lease-time: 31536000]

Thu Aug 30 08:52:43 2007 Successful ARP Flush on interface [2] {6FCB56CF-B125-4D

24-91A3-822CE03972DD}

Thu Aug 30 08:52:43 2007 TEST ROUTES: 0/0 succeeded len=4 ret=0 a=0 u/d=down

Thu Aug 30 08:52:43 2007 Route: Waiting for TUN/TAP interface to come up...

Thu Aug 30 08:52:44 2007 TEST ROUTES: 0/0 succeeded len=4 ret=0 a=0 u/d=down

Thu Aug 30 08:52:44 2007 Route: Waiting for TUN/TAP interface to come up...

Thu Aug 30 08:52:45 2007 TEST ROUTES: 4/4 succeeded len=4 ret=1 a=0 u/d=up

Thu Aug 30 08:52:45 2007 route ADD 111.111.111.36 MASK 255.255.255.0 10.99.0.9

Thu Aug 30 08:52:45 2007 route ADD 222.222.0.98 MASK 255.255.0.0 10.99.0.9

Thu Aug 30 08:52:45 2007 route ADD 123.123.123.234 MASK 255.255.255.255 10.99.0.

9

Thu Aug 30 08:52:45 2007 Route addition via IPAPI succeeded

Thu Aug 30 08:52:45 2007 route ADD 10.99.0.0 MASK 255.255.255.0 10.99.0.9

Thu Aug 30 08:52:45 2007 Route addition via IPAPI succeeded

Thu Aug 30 08:52:45 2007 Initialization Sequence Completed

----------------------------------------------------------------------------

(连接成功)连接成功的话,你应该在桌面右下角的托盘当中看到一个小电脑它的小屏幕颜色从红(未连接)-黄(正在连接)-绿(已经连接上)这样的过程。

再察看网络接口

-------------------------------------------------------------------------------

Microsoft Windows [Version 5.2.3790]

(C) Copyright 1985-2003 Microsoft Corp.

C:Documents and SettingsAdministrator>ipconfig/all

Windows IP Configuration

Host Name . . . . . . . . . . . . : kserver

Primary Dns Suffix. . . . . . . :

Node Type . . . . . . . . . . . . : Unknown

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter VPN:

(这个名字叫“VPN”的网路接口就是通过OpenVPN运行起来的虚拟网络接口,并且这个“VPN”的名字也是由之前主配置文件中dev-node配置项定义的。)

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : TAP-Win32 Adapter V8

Physical Address. . . . . . . . . : 00-FF-6F-CB-56-CF

DHCP Enabled. . . . . . . . . . . : Yes

Autoconfiguration Enabled . . . . : Yes

IP Address. . . . . . . . . . . . : 10.99.0.10

(这个IP地址也是连接成功后由Server分配的)

Subnet Mask . . . . . . . . . . . : 255.255.255.252

Default Gateway . . . . . . . . . :

DHCP Server . . . . . . . . . . . : 10.99.0.9

Lease Obtained. . . . . . . . . . : 2007年8月30日 8:52:44

Lease Expires . . . . . . . . . . : 2008年8月29日 8:52:44

Ethernet adapter NET1:

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : Broadcom 440x 10/100 Integrated Controller

Physical Address. . . . . . . . . : 00-18-8B-82-52-1A

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.1.102

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.1.1

DNS Servers . . . . . . . . . . . : 202.96.209.5

202.96.209.133

Ethernet adapter NET0:

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : ADMtek AN983 10/100 PCI Adapter

Physical Address. . . . . . . . . : 00-E0-4C-B3-F3-43

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 192.168.0.198

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . :

DNS Servers . . . . . . . . . . . : 192.168.0.201

202.96.209.133

C:Documents and SettingsAdministrator>

---------------------------------------------------------------------------

察看路由表

------------------------------------------------------------------------

C:Documents and SettingsAdministrator>route PRINT

IPv4 Route Table

===========================================================================

Interface List

0x1 ........................... MS TCP Loopback interface

0x2 ...00 ff 6f cb 56 cf ...... TAP-Win32 Adapter V8

0x10004 ...00 18 8b 82 52 1a ...... Broadcom 440x 10/100 Integrated Controller

0x10005 ...00 e0 4c b3 f3 43 ...... ADMtek AN983 10/100 PCI Adapter

===========================================================================

===========================================================================

Active Routes:

Network Destination Netmask Gateway InterfaceMetric

0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.102 20

10.99.0.0 255.255.255.0 10.99.0.9 10.99.0.10 1

10.99.0.8255.255.255.252 10.99.0.10 10.99.0.10 30

10.99.0.10255.255.255.255 127.0.0.1 127.0.0.1 30

10.255.255.255255.255.255.255 10.99.0.10 10.99.0.10 30

127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1

192.168.0.0 255.255.255.0 192.168.0.198 192.168.0.198 20

192.168.0.198255.255.255.255 127.0.0.1 127.0.0.1 20

192.168.0.255255.255.255.255 192.168.0.198 192.168.0.198 20

192.168.1.0 255.255.255.0 192.168.1.102 192.168.1.102 20

192.168.1.102255.255.255.255 127.0.0.1 127.0.0.1 20

192.168.1.255255.255.255.255 192.168.1.102 192.168.1.102 20

123.123.123.234255.255.255.255 10.99.0.9 10.99.0.10 1

111.111.111.0 255.255.255.0 10.99.0.9 10.99.0.10 1

222.222.0.0 255.255.0.0 10.99.0.9 10.99.0.10 1

224.0.0.0 240.0.0.0 10.99.0.10 10.99.0.10 30

224.0.0.0 240.0.0.0 192.168.0.198 192.168.0.198 20

224.0.0.0 240.0.0.0 192.168.1.102 192.168.1.102 20

255.255.255.255255.255.255.255 10.99.0.10 10.99.0.10 1

255.255.255.255255.255.255.255 192.168.0.198 192.168.0.198 1

255.255.255.255255.255.255.255 192.168.1.102 192.168.1.102 1

Default Gateway: 192.168.1.1

===========================================================================

Persistent Routes:

None

C:Documents and SettingsAdministrator>

--------------------------------------------------------------------------

这里10.99.0.0网段出现,还有其他的一些新增路由如111.111.111.0/24和222.222.0.0/16这些路由,这些都是由Server那里Push过来的。并且他们的Metric是1,因此他们是优先匹配这些路由出局的。

ping远端VPN Server主机虚拟地址

C:Documents and SettingsAdministrator>ping 10.99.0.1

Pinging 10.99.0.1 with 32 bytes of data:

Reply from 10.99.0.1: bytes=32 time=22ms TTL=64

Reply from 10.99.0.1: bytes=32 time=22ms TTL=64

Reply from 10.99.0.1: bytes=32 time=22ms TTL=64

Reply from 10.99.0.1: bytes=32 time=21ms TTL=64

Ping statistics for 10.99.0.1:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 21ms, Maximum = 22ms, Average = 21ms

C:Documents and SettingsAdministrator>

连接成功

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新网络通讯学习
热门网络通讯学习
软件教程子分类