文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>vpn的配置文档

vpn的配置文档

时间:2006-06-28  来源:brave_script

 

安装 OpenVPN

OpenVPN 能够从 http://openvpn.net/download.html 下载.

OpenVPN 应该安装在做VPN的服务器和客户机上。

Linux Notes (using RPM package)

在SuSE,Fedora,Redhat上建议采用RPM包的方式安装:

建立RPM包依赖openssl,lzo,pam,openssl-devel,lzo-devel,pam-devel

rpmbuild -tb openvpn-[version].tar.gz

 

如果没有lzo可以如下方式建立:

rpmbuild -tb openvpn-[version].tar.gz --define ‘without_lzo 1’

 

建好的rpm包文件存放在/usr/src/redhat/RPMS/i386/

有了rpm包后就可以用以下方式来安装,

rpm -ivh openvpn-[details].rpm

或者用以下方式升级安装

rpm -Uvh openvpn-[details].rpm

 

Linux Notes (without RPM)

如果用的不是基于rpm的linux,比如Debian, Gentoo, 首先解压,然后进行./configure, make.

tar xfz openvpn-[version].tar.gz

cd openvpn-[version]

./configure

make

make install

 

Windows Notes

OpenVPN for Windows 安装文件可从http://openvpn.net/download.html下载

安装完成, OpenVPN 使用.ovpn 扩展名做为配置文件扩展名,有以下三种方式运行OpenVPN:

•   右键点击OpenVPN 的配置文件 (.ovpn) 然后选择“Start OpenVPN on this configuration file”. 如果运行,可以按F4键退出。

•   可以在windows的命令行下输入命令

openvpn myconfig.ovpn

如果运行,可以按F4键退出。

•   将配置文件放在\Program Files\OpenVPN\config 然后启动OpenVPN 服务。

 

 

场景配置举例:

服务器1

机房服务器内网192.168.72.0/24

机房服务器公网210.1.1.xx

机房服务器公网200.1.1.xx

服务器openvpn

Eth1:192.168.72.3

Eth0:210.1.1.2

服务器2

Eth0:200.1.1.2

Eth1:192.168.72.2

internet

本地接入NAT服务

本地接入内网192.168.100.0/24

客户机openvpn

Tun0:10.8.0.1

 

 

openvpn服务器配置过程

一、建立CA文件

openvpn服务器:

1.     在redhat el as4up2上openvpn的文档目录在/usr/share/doc/openvpn-2.0.7/,启动配置目录是/etc/openvpn

2.     首先复制 easy-rsa 目录到/etc/openvpn/下

#cp -rf /usr/share/doc/openvpn-2.0.7/easy-rsa /etc/openvpn/

3.     进入 /etc/openvpn/easy-vpn 建立CA文件

a)       设置环境变量,编辑vars,

# easy-rsa parameter settings

export D=`pwd`  #设置主目录

export KEY_CONFIG=$D/openssl.cnf  #设置key的配置文件

export KEY_DIR=$D/keys            #设置生成的key存放目录

# Issue rm -rf warning

#使用./clean-all会删除key存放目录里的所有文件

echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR

export KEY_SIZE=1024   #设置key的大小

export KEY_COUNTRY=CN  #设置国家代码,不能为空

export KEY_PROVINCE=CE #设置提供商,不能为空

export KEY_CITY=BEEJING #设置城市,不能为空

export KEY_ORG="CE-TEST"      #设置组织,不能为空

export KEY_EMAIL="[email protected]"上   #设置email,不能为空

b)       运行 vars,设置环境变量。

#. ./vars

c)       清除keys目录里的所有文件,

#./clean-all

d)       建立CA文件,生成的文件是ca.crt, ca.key, 在 keys目录里

#./build-ca

输出中Common Name (eg, your name or your server's hostname) []:OpenVPN-CA

其它按回车默认

e)       建立服务器的密匙文件,生成的server.crt, server.key,在keys目录里

#./build-key-server server

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

输入server,后面有两个提问按y确认。 Sign the certificate? [y/n]:y

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

f)       建立客户端的密匙文件。生成的client1.crt, client1.key 在keys目录里。

#./build-key client1

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

输入server,后面有两个提问按y确认。 Sign the certificate? [y/n]:y

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

 

同样可以多个客户机的密匙文件

#./build-key client2

#./build-key client3

g)       生成Diffie Hellman 参数,必须为openvpn生成

#./build-dh

h)       生成的文件说明

在keys目录下(/etc/openvpn/easy-rsa/keys)会发现刚才生成的文件,下面是生成的文件的说明:

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

client3.crt

client3 only

Client3 Certificate

NO

client3.key

client3 only

Client3 Key

YES

 

然后就可以将这些文件cp到需要的机器上了。

服务器的文件拷贝到服务器的 /etc/openvpn/下

客户机的文件拷贝到客户机的 /etc/openvpn/下

 

二、配置服务器

#/etc/openvpn/server.conf

# OpenVPN 服务侦听地址(可选)

#local a.b.c.d

# OpenVPN 服务侦听端口

port 1194

 

# 使用的协议

;proto tcp

proto udp

 

# "dev tun" will create a routed IP tunnel,

# "dev tap" will create an ethernet tunnel.

;dev tap

dev tun

 

# SSL/TLS root certificate (ca), certificate

# (cert), and private key (key).  Each client

# and the server must have their own cert and

# key file.  The server and all clients will

# use the same ca file.

ca ca.crt

cert server.crt

key server.key  # This file should be kept secret

 

# Diffie hellman parameters.

# Generate your own with:

#   openssl dhparam -out dh1024.pem 1024

# Substitute 2048 for 1024 if you are using

# 2048 bit keys.

dh dh1024.pem

 

# 配置服务器VPN子网地址,服务器使用10.8.0.1,每个客户都能到达这个地址

##服务器分配10.8.0.1,客户机分配本网段其它的地址

server 10.8.0.0 255.255.255.0

 

#维护客户机IP地址,重连的客户端会被分配曾用的IP地址

ifconfig-pool-persist ipp.txt

 

#把其它的私网地址路由推给客户,允许客户机访问这些私网地址。

#这些私网也需要知道到达vpn客户机的路由。

push "route 192.168.72.0 255.255.255.0"

push "route 192.168.73.0 255.255.255.0"

 

#为给特定的客户分配指定的IP地址,指定客户机配置目录ccd

#比如要给Common name为client1的客户分配IP地址192.168.73.1/255.255.255.248

#在ccd目录里建立一个client1的文件,

#其内容输入ifconfig-push 192.168.73.1 192.168.73.2

client-config-dir ccd

 

#根据客户端的IP地址分配目录 ccd ,下面的路由根据VPN客户地址来添加。

route 192.168.73.0 255.255.255.0

 

#允许客户机之间相互通讯,如果注释,客户机只能与openvpn服务器通讯,不能与其它客

#户机通讯

#client-to-client 

 

#可以允许客户机用相同的认证密匙。默认禁止

#duplicate-cn 

 

# The keepalive directive causes ping-like

# messages to be sent back and forth over

# the link so that each side knows when

# the other side has gone down.

# Ping every 10 seconds, assume that remote

# peer is down if no ping received during

# a 120 second time period.

keepalive 10 120

 

# For extra security beyond that provided

# by SSL/TLS, create an "HMAC firewall"

# to help block DoS attacks and UDP port flooding.

#

# Generate with:

#   openvpn --genkey --secret ta.key

#

# The server and each client must have

# a copy of this key.

# The second parameter should be '0'

# on the server and '1' on the clients.

tls-auth ta.key 0 # This file is secret

 

# 数据压缩,默认是开启,但开启后openVPN不能启动。服务器和客户机此项设置要一致。

;comp-lzo

 

# 允许的最大客户数

#max-clients 100

 

#在linux系统可以降低openvpn守护进程的权限,在windows上不能取掉注释

user nobody

group nobody

 

# The persist options will try to avoid

# accessing certain resources on restart

# that may no longer be accessible because

# of the privilege downgrade.

persist-key

persist-tun

 

# 输出一个精简的状态文件,显示当前的连接,每分钟重写一次

status openvpn-status.log

 

# 默认log信息是存在syslog里,使用log,log-append会覆盖这个默认值

#当openvpn启动的时候,log文件会被重写。

log         openvpn.log

log-append  openvpn.log

 

# log记录级别,0-9

# 0 只记录致命的错误

# 4 通常语法的原因

# 5 and 6 帮助调试连接问题

# 9 详细

verb 3

 

# 重复消息次数,只记录一条

;mute 20

服务器端文件目录结构,/etc/openvpn/

     ca.crt #来源easy-rsa/keys/ca.crt

     ca.key #来源easy-rsa/keys/ca.key

     dh1024.pem #来源easy-rsa/keys/dh1024.pem

     ipp.txt #openvpn自动生成

     openvpn.log # openvpn自动生成

     openvpn-status.log # openvpn自动生成

     server.conf #从/usr/share/doc/openvpn-2.0.7/sample-config-files/复制,并按上述配置编辑。

     server.crt #来源easy-rsa/keys/server.crt

     server.key #来源easy-rsa/keys/server.key

     ccd        #VPN客户配置目录mkdir ccd

ccd 目录中的文件名取客户的Common name。 内容如下格式:

ifconfig-push 192.168.73.1 192.168.73.2

192.168.73.1为VPN客户的ip地址,192.168.73.2为VPN服务端的虚拟IP地址

 

客户机的ip地址分配规则,ifconfig-push每对地址是虚拟服务器和客户端的端点地址,为和windows系统兼容必须以30位掩码划分子网,每对地址如下:

[1,2][5,6][9,10][13,14][17,18][21,22][25,26][29,30][33,34][37,38][41,42][45,46][49,50][53,54][57,58][61,62][65,66][69,70][73,74][77,78][81,82][85,86][89,90][93,94][97,98][101,102][105,106][109,110][113,114][117,118][121,122][125,126][129,130][133,134][137,138][141,142][145,146][149,150][153,154][157,158][161,162][165,166][169,170][173,174][177,178][181,182][185,186][189,190][193,194][197,198][201,202][205,206][209,210][213,214][217,218][221,222][225,226][229,230][233,234][237,238][241,242][245,246][249,250][253,254]

 

 

 

 

客户端配置文件client.conf

 

#客户端

client

 

;dev tap

dev tun

 

# 使用的协议

;proto tcp

proto udp

 

#服务器地址或域名,可以多个做负载平衡。

remote 200.1.1.2 1194

;remote 192.168.211.3 1194

;remote my-server-2 1194

 

# 做负载平衡时启用

;remote-random

 

# 保持尝试解析OpenVPN服务器的主机名,对不能永久连接机器非常有用

resolv-retry infinite

 

#大多数客户端不需要绑定本地端口

nobind

 

# 初始化完后,非windows用户降级权限

user nobody

group nobody

 

# Try to preserve some state across restarts.

persist-key

persist-tun

 

# SSL/TLS parms.

# See the server config file for more

# description.  It's best to use

# a separate .crt/.key file pair

# for each client.  A single ca

# file can be used for all clients.

ca ca.crt

cert client2.crt

key  client2.key

 

# Verify server certificate by checking

# that the certicate has the nsCertType

# field set to "server".  This is an

# important precaution to protect against

# a potential attack discussed here:

#  http://openvpn.net/howto.html#mitm

#

# To use this feature, you will need to generate

# your server certificates with the nsCertType

# field set to "server".  The build-key-server

# script in the easy-rsa folder will do this.

;ns-cert-type server

 

# If a tls-auth key is used on the server

# then every client must also have the key.

tls-auth ta.key 1

 

# Select a cryptographic cipher.

# If the cipher option is used on the server

# then you must also specify it here.

;cipher x

 

# Enable compression on the VPN link.

# Don't enable this unless it is also

# enabled in the server config file.

;comp-lzo

 

# Set log file verbosity.

verb 3

 

# Silence repeating messages

;mute 20

 

 

 

相关阅读 更多 +
排行榜 更多 +
超级冒险王安卓版

超级冒险王安卓版

休闲益智 下载
玩具小镇手机版

玩具小镇手机版

休闲益智 下载
这一关特上头手机版

这一关特上头手机版

休闲益智 下载