Fedora 8 openvpn服务端图形界面安装配置

 windows xp openvpn gui客户端安装配置

 

曼.查罗(Samsun Xu) 03/07/200

 

 

一、   安装环境

1.         服务器:Fedora 8,内核2.6.15

2.         客户端:Windows xp SP2

 

二、   安装openvpn

Linux作服务器应该用text模式才是正道,但是发现很多朋友都有用图形界面的习惯,有些朋友甚至问一些很奇怪的问题,因此特地在图形界面下做了一次图形界面下的vpn安装配置,本篇文章用的是中文书写,为了照顾到广大中文用户,系统语言环境用的也是中文,如果有必要会再发布一份纯英文版的图形界面安装配置文档。

 

1、  Fedora 8下安装openvpn

a)         通过添加/删除软件来进行安装openvpn


 

b)        在软件管理界面,通过搜索功能输入openvpn找到安装源,并选中安装包进行安装,在安装过程中会检测到openvpn安装所需的其他软件包,这些包是让openvpn包正常安装的前提,你可以将他们纪录下来,下次等你用手动安装(纯文本模式)的时候或许对你有用。



三、   什么是VPN
总的来说vpn运行起来是围绕证书验证机制,这里我用一个易懂的图示简单解释一下证书机制。(为了让更多人明白vpn原理,这里写的比较直白,各位老鸟请不要笑我的表达方式)

VPN
的理念,为什么我们要做VPN呢? VPN的字面意思是虚拟局域网,这个大家都知道,就是让一群不在一个办公室工作的人在一起工作,让一群在不同省市的甚至不同国家的玩家,变成好像是在同一个网吧里一起玩游戏一样(比如:浩方游戏平台),但是,VPN是通过什么原理让不同地方的电脑变相的放在了一起呢?

l  证书验证机制:相当于一个网管,把电脑放在虚拟出来的网吧,并给它一个ip

l  服务端钥匙:服务端是给大家共用的,所以它的体系一旦设置好后基本是不变的,简称服务端公钥。相当于网管配了一台服务器,放在网吧里,没有特殊情况不用改变什么设置,网吧里的玩家么,通过这个服务器上网、游戏等等。

l  客户端钥匙:好比是你去网吧上网,网管要给你开个账号并给你密码,或者你是会员,你就用你的会员卡上的账号密码登录一台电脑连接上服务器,由于这是属于你私人的,每个人都不一样,简称客户端私钥匙。


一开始客户端还没进行通讯连接的时候,服务端和客户端是没有在一起的,当一个用户通过他自己的私人钥匙打开这扇虚拟大门的时候,他就进入了这个虚拟的局域网,越来越多的用户通过他们自己的钥匙进入到这个虚拟局域网,这时候就形成用户们虚拟的坐在了一起,他们的爱机都放在了同一个局域网内,这时他们可以一起工作,一起游戏了,这就是所谓的VPN

四、   证书制作

1、  制作证书前的准备
复制openvpn证书工具包,在安装完openvpn后,系统会在/etc下建一个openvpn的目录,这样我们可以把openvpn证书工具包拷贝到/etc/openvpn目录下

l  证书工具包默认位置:/usr/share/openvpn/easy-rsa

l  准备配置证书位置:/etc/openvpn/

l  证书生成位置:/etc/openvpn/easy-rsa/2.0/keys

# cp -r /usr/share/openvpn/easy-rsa /etc/openvpn/

# mkdir /etc/openvpn/easy-rsa/2.0/keys

 

2、  修改vars变量初始化配置文件,编辑easy-rsa/2.0/vars文件

l  注释掉export CA_EXPIRE=3650,在前面加个#号即可

l  注释掉export KEY_EXPIRE=3650,在前面加个#号即可

l  修改证书默认值

export KEY_COUNTRY="CN"

export KEY_PROVINCE="SH"

export KEY_CITY="Shanghai"

export KEY_ORG="mediaman"

export KEY_EMAIL="samsun.xu@mediaman.com.cn"

 

3、  初始化证书仓库

a)         初始化变量库

#. vars

 

b)        清空证书库

#./clean-all

注意:命令前有个点的,别漏了。

 

4、  证书验证机制

#./build-ca

........++++++

writing new private key to 'ca.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [Shanghai]:

Organization Name (eg, company) [mediaman]:

Organizational Unit Name (eg, section) []:vpn

Common Name (eg, your name or your server's hostname) []:server

Email Address [samsun.xu@mediaman.com.cn]:

执行过程中,输入对应的信息,中间有询问y/n的都输入y,完成后在keys目录下,会生成ca.crtca.key这两个文件

 

5、  服务器证书

#./build-key-server server

Generating a 1024 bit RSA private key

......++++++

....................++++++

writing new private key to 'server.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [Shanghai]:

Organization Name (eg, company) [mediaman]:

Organizational Unit Name (eg, section) []:vpn

Common Name (eg, your name or your server's hostname) [server]:

Email Address [samsun.xu@mediaman.com.cn]:

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:q1w2e3r4

An optional company name []:mediaman

Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'SH'

localityName          :PRINTABLE:'Shanghai'

organizationName      :PRINTABLE:'mediaman'

organizationalUnitName:PRINTABLE:'vpn'

commonName            :PRINTABLE:'server'

emailAddress          :IA5STRING:'samsun.xu@mediaman.com.cn'

Certificate is to be certified until Mar 19 08:15:31 2016 GMT (3650 days)

Sign the certificate? [y/n]:y

 

 

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

              执行完成后在keys目录下,会生成server.crtserver.csrserver.key这三个文件

 

 

6、  客户端证书
openvpn中,这种配置方法是每一个登陆的VPN客户端需要有一个证书,每个证书在同一时刻只能供一个客户端连接(如果有两个机器安装相同证书,同时拨服务器,都能拨上,但是只有第一个拨上的才能连通网络)。所以需要建立许多份证书。

#./build-key client1

Generating a 1024 bit RSA private key

.....++++++

......++++++

writing new private key to 'client1.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [Shanghai]:

Organization Name (eg, company) [mediaman]:

Organizational Unit Name (eg, section) []:vpn

Common Name (eg, your name or your server's hostname) [client1]:

Email Address [samsun.xu@mediaman.com.cn]:client1@mediaman.com.cn

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:q1w2e3r4

An optional company name []:mediaman

Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'SH'

localityName          :PRINTABLE:'Shanghai'

organizationName      :PRINTABLE:'mediaman'

organizationalUnitName:PRINTABLE:'vpn'

commonName            :PRINTABLE:'client1'

emailAddress          :IA5STRING:'client1@mediaman.com.cn'

Certificate is to be certified until Mar 19 08:22:00 2016 GMT (3650 days)

Sign the certificate? [y/n]:y

 

 

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

执行完成后在keys目录下,会生成client1.crtclient1.csrclient1.key这三个文件。
一个服务器端可以配多个客户端证书,但是每个客户端都不能一样,主要体现在Common Name这里,每一个客户端的Common Name都必须不一样,你可以再继续建出client2client3。。。如下

#./build-key client2

#./build-key client3

 

7、编译证书
将刚刚生成出来的证书和钥匙等等进行了一次加密算法,具体是怎么样的算法我也不知道,然后证书和钥匙我们就都作好了。

#./build-dh

此时在keys目录下,会生成dh1024.pem文件。

 

五、   配置服务端

如果第四步都正常的情况下,我们就开始配置服务端了,如果中间过程有出现什么问题,建议清空证书库,重新来过,执行./clean-all来清空库。

 

1、  首先把几个证书、钥匙和验证机制都拷贝到/etc/openvpn目录下

# cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt /etc/openvpn/

# cp /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem /etc/openvpn/

# cp /etc/openvpn/easy-rsa/2.0/keys/server.crt /etc/openvpn/

# cp /etc/openvpn/easy-rsa/2.0/keys/server.key /etc/openvpn/

 

2、  然后把服务器的配置文件拷贝到/etc/openvpn目录下

# cp /usr/share/doc/openvpn-2.1/sample-config-files/server.conf /etc/openvpn/

 

3、  编辑/etc/openvpn/server.conf配置文件

去掉前面的;分号

;user nobody

;group nobody

 

4、  启动openvpn

#/etc/init.d/openvpn start

查看一下端口1194是否已开放,如果1194已开放那就恭喜你,你的openvpn服务端已经配置成功了。

 

5、  设置开机自启动openvpn

#ntsysv

找到openvpn服务,并选中服务确认即可,下次系统启动的时候会自动加载openvpn服务。ntsysv是管理通过软件安装工具安装的软件的自启动列表,如果你没有安装ntsysv的话建议你安装(都安装了整个图形界面了,还差安装这么一个小工具?)或者用chkconfig直接配置openvpn开关,这个就不说了。

 

6、  设置防火墙

    

在系统管理中,打开防火墙配置,开启OpenVPNSSH(前面打沟即可)。

 

六、   配置客户端

客户端用的是Windows XP Sp2,其他版本没试过,想来应该也不会有什么问题。到openvpn.se网站下载openvpn gui客户端,默认安装一路next下去即可。默认安装是安装在C:\Program Files\OpenVPN位置。从服务器上把生成的客户端证书和客户端私钥以及验证机制拷贝到C:\Program Files\OpenVPN\config目录下,如前面我们生成了client1客户端证书和私钥,那这里我们就把ca.crtclient1.crtclient1.key三个文件拷贝到config目录下。

 

1  制作客户端连接器

a)    C:\Program Files\OpenVPN\config目录下新建一个文件,名为client.ovpn

b)    或者到服务器上把/usr/share/doc/openvpn-2.1/sample-config-files/client.conf文件弄到本地C:\Program Files\OpenVPN\config目录下,并重命名为client.ovpn

2  配置客户端连接器

client

dev tap

;dev tun

 

;dev-node MyTap

 

;proto tcp

proto udp

 

remote 服务器ip地址 1194

 

;remote-random

 

resolv-retry infinite

 

nobind

 

user nobody

group nobody

 

route 192.168.0.0 255.255.252.0

 

persist-key

persist-tun

 

;http-proxy-retry # retry on connection failures

;http-proxy [proxy server] [proxy port #]

 

ca ca.crt

cert client1.crt

key client1.key

 

comp-lzo

 

# Set log file verbosity.

verb 4

 

3  连接VPN服务器

       运行客户端OpenVPN GUI,在右下角已运行软件的工作条中,出现一个小图标,右键小图标,选择connect进行连接,如果一切都配置正确,连接后小图标会变成

 

       如果出现异常,请检查网络连接中,是否有TAP-Win32 Adapter V8驱动的连接,如果没有这个驱动的网络连接,请通过OpenVPN GUI添加一个

   

 

       更多的异常请查看连接日志,根据日志的提示,进行解决,至此已介绍完整个VPN服务端和客户端的安装与配置。