Freebsd+openvpn
本文是在freebsd6.2操作系统下
安装openvpn
用root登陆服务器后
因为需要数据压缩,所以需要装LZO
[root@dns-master openvpn]# cd /usr/ports/archivers/lzo
[root@dns-master lzo]# pwd
/usr/ports/archivers/lzo
Make install clean
安装openvpn
[root@dns-master ~]# cd /usr/ports/security/openvpn
[root@dns-master openvpn]# pwd
/usr/ports/security/openvpn
然后输入make install with-lzo-headers=/usr/local/include with-lzo-lib=/usr/local/lib
二、配置openvpn.conf
可以去拷贝一个
cd /usr/ports/security/openvpn/work/openvpn-
[root@dns-master sample-config-files]# pwd
/usr/ports/security/openvpn/work/openvpn-
[root@dns-master sample-config-files]# cp server.conf /usr/local/etc/openvpn/openvpn
然后用vi编辑openvpn.conf
我的配置文件如下
# 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 udp
# “dev tun” will create a routed IP tunnel,
# “dev tap” will create an ethernet tunnel.
# Use “dev tap0″ if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use “dev-node” for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
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.
#
# See the “easy-rsa” directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see “pkcs12″ directive in man page).
ca ca.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
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take
# the rest will be made available to clients.
# Each client will be able to reach the server
# on
# ethernet bridging. See the man page for more info.
server
# 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
# Push routes to the client to allow it
# to reach other private subnets behind
# the server. Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (
# back to the OpenVPN server.
push “route 172.16.10.0 255.255.255.0″
# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory “ccd” for client-specific
# configuration files (see man page for more info).
# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of
# First uncomment out these lines:
client-config-dir ccd
# Uncomment this directive to allow different
# clients to be able to “see” each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server’s TUN/TAP interface.
client-to-client
# 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.
#
# 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.
#
# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo
# It’s a good idea to reduce the OpenVPN
# daemon’s privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user 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
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status openvpn-status.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3
三、生成服务器端和客户端证书和密钥
首先切换到一下目录
[root@dns-mastereasy-rsa]#cd/usr/ports/security/openvpn/work/openvpn-
[root@dns-master easy-rsa]# pwd
/usr/ports/security/openvpn/work/openvpn-
然后编辑vars文件内容如下,根据自己实际情况修改
[root@dns-master easy-rsa]# more vars
# easy-rsa parameter settings
# NOTE: If you installed from an RPM,
# don’t edit this file in place in
# /usr/share/openvpn/easy-rsa –
# instead, you should copy the whole
# easy-rsa directory to another location
# (such as /etc/openvpn) so that your
# edits will not be wiped out by a future
# OpenVPN package upgrade.
# This variable should point to
# the top level of the easy-rsa
# tree.
export D=`pwd`
# This variable should point to
# the openssl.cnf file included
# with easy-rsa.
export KEY_CONFIG=$D/openssl.cnf
# Edit this variable to point to
# your soon-to-be-created key
# directory.
#
# WARNING: clean-all will do
# a rm -rf on this directory
# so make sure you define
# it correctly!
export KEY_DIR=$D/keys
# Issue rm -rf warning
echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
# Increase this to 2048 if you
# are paranoid. This will slow
# down TLS negotiation performance
# as well as the one-time DH parms
# generation process.
export KEY_SIZE=1024
# These are the default values for fields
# which will be placed in the certificate.
# Don’t leave any of these fields blank.
export KEY_COUNTRY=CN
然后保存退出
. ./vars //注意两个点中间有空格
./clean-all
./build-ca
build-ca 命令使用openssl 命令生成certificate authority (CA) certificate 和密钥:
./build-ca
Generating a 1024 bit RSA private key
….++++++
…….++++++
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) [Beijing]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [redpoo.com]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:redpoo.com //这里随便输入即可
Email Address [
Common Name 处填server,其他默认,为上面编辑vars 文件时设置的值。“Sign the certificate?
[y/n]” 和“1 out of 1 certificate requests certified, commit? [y/n]“两处选y
四、修改客户端配置
以下是以windows为客户端为例
五、配置openvpn自动启动
Vi编辑/etc/rc.conf
六、启动openvpn
/usr/local/etc/rc.d/openvpn start

It is beautifully turned out .. I liked ..) would be continuously zahazhivat to you.