网上关于Openvpn的帖子已经很多了,我这里也就不多讲了,初学者可以去狗狗上搜一下,总有几篇不错的帖子,自己看了一下,大部分是将windows平台和Linux平台的,都还可以的。这里呢,洒家只想讲一下麒麟上openvpn的配置中特殊的问题以及一些注意事项,希望促进麒麟的推广,支持国有软件吗!:)
1. 关于Openvpn
OpenVPN 是一个基于 OpenSSL 库的应用层 VPN 实现。和传统 VPN 相比,它的优点是简单易用。详细信息可以参考 http://www.openvpn.net (http://www.openvpn.net/)。
利用Openvpn可以实现网络上的安全传输、安全认证,从而实现虚拟专用网络的应用模式。Openvpn配置简单,可选项多,包括认证方式(证书或用户名+密码)、加密算法及强度(常用的加密算法,也可以自己在Openssl里面添加)、证书形式(证书管理形式)、传输模式(压缩与否)等等。
一般说来,利用Openvpn可以实现以下安全传输模式:
1、 点对点的安全通信(认证加加密传输);
2、 点对多点的安全通信(client/ server模式);
3、 虚拟专用网(上等武功^_^)。
更多的说明去网站看吧。这里主要讲基于证书的虚拟专网配置。
目前,Openvpn已经出到了稳定版本2.0.7,测试版本2.1_beta14,更新的很快哦,已经支持PKCS11#的硬件设备了。
2. 不同版本麒麟上的Openvpn配置方法
网上的帖子大多是针对windows和Linux下的Openvpn的配置和使用。
Windows下面最简单了,Setup——〉修改Sample config files——〉启动服务。基本一下就OK了。
Linux下面稍微复杂些,看说明文档来安置lzo、openssl和openvpn。然后也是修改配置文件,作为基本篇,改一下Sample config files就可以了。然后启动服务,连接也就OK了。
当然,记得要生成证书阿!看Openvpn的How to,基本上是Step by Step了。
下面咱们来用麒麟配一下Openvpn。
1、软件安装
首先,下载安装所需的文件:lzo-ver.tar.gz 和openvpn-ver –tar.gz。
接下来,安装软件
lzo-ver.tar.gz
tar –xzf lzo-ver-.tar.gz
cd lzo*
./configure
make
make install
然后就不用管它了。
openvpn-ver –tar.gz
tar –xzf openvpn-ver-.tar.gz
cd openvpn*
./configure
make
make install
软件安装完毕。
2、生成证书
然后,来生成需要的密钥对。
进入目录openvpn/easy-rsa
运行如下命令:
. ./vars (注意,两个点之间有空格的)
./clean-all
./build-ca(初始化PKI)
./build-key-server server(为服务器生成证书和私钥)
./build-key client1 (为客户端1生成证书和私钥)
./build-key client2
./build-dh 生成diffie Hellman参数
完成后,按照密钥文件表格存放文件
Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dh{n}.pem server only Diffie Hellman parameters NO
server.crt server only Server Certificate NO
server.key server only Server Key YES
client1.crt client1 only Client1 Certificate NO
client1.key client1 only Client1 Key YES
client2.crt client2 only Client2 Certificate NO
client2.key client2 only Client2 Key YES
3、配置服务器和客户端
证书和密钥都放好了,就可以开始配置Openvpn。为了简单,我们可以把证书和密钥都放在sample_config_files目录下面,然后修改配置文件。
先来Server端的,修改server.conf。
贴个例子上来说明一下:
#################################################
# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d
#侦听地址,可以不改
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194
#侦听端口号,想省事也可以不动
# TCP or UDP server?
;proto tcp
proto udp
#传输协议,二选一,客户端和服务器端一致就行啦
;dev tap
dev tun
#VPN需要的虚拟网络设备。如果是以太网桥接模式才选择TAP,否则一般都用TUN。不过Windows系统上都叫TAP32,但是这里还是要写TUN的。
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
#Windows下需要让TAP的名字和网络设备上的名字一样(手工修改一下了)
#其实不用管它的,就这样注释着好了。
# 此处删去E文若干行
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
#这里要把文件路径和名字都制定对了。如果证书和server.conf都放在一个目录下,就比较省事了,管它什么系统都不用改配置文件了。否则,记得别把路径写错了阿。、
# Diffie hellman parameters.
dh dh1024.pem
#不用改动
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
#服务器的IP地址分配定义。OPENVPN缺省是DHCP的,每个证书对应一个IP(实际是一对以Point-to-point相连的IP)。
# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt
#不用改动
# Configure server mode for ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.5