热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在Ubuntu12.04下安装配置OpenVPN

一开始,我的vps装的是Ubuntu10.10,在这个版本上我折腾了好几天,都没有成功,后来在线升级了系统之后再安装配置openvpn,终于,能用了。如果有新的系统版本,用户刚刚登陆进去的时候就会有提示,如下图:也就是说,直接在shell中输入“do-release-upgrade”就可以升级到下一版本。由于我是linux菜鸟,故在此做个记录。下面就开始

 一开始,我的vps装的是Ubuntu 10.10,在这个版本上我折腾了好几天,都没有成功,后来在线升级了系统之后再安装配置openvpn,终于,能用了。如果有新的系统版本,用户刚刚登陆进去的时候就会有提示,如下图:

也就是说,直接在shell中输入“do-release-upgrade”就可以升级到下一版本。由于我是linux菜鸟,故在此做个记录。下面就开始我们的openvpn之旅吧。

1.  安装openvpn

这个很容易,在线安装就可以了:apt-get  install openvpn,不作赘述了。

 2  复制配置文件到/etc下: cp -R /usr/share/doc/openvpn/examples/easy-rsa  /etc/openvpn/

3  修改var文件 :vim /etc/openvpn/easy-rsa/2.0/vars。其实也可以不修改,但是为了后续步骤能够一路enter,所以就先在这里修改下吧。主要是要修改末尾的几行。

 export KEY_COUNTRY=" "
export KEY_PROVINCE=" "
export KEY_CITY=" "
export KEY_ORG=" "
export KEY_EMAIL=""
export KEY_EMAIL=
export KEY_CN=
export KEY_NAME=
export KEY_OU=
export PKCS11_MODULE_PATH=
export PKCS11_PIN=

=号后边就自己填入吧,我不知道大小写有没有影响,为了以防万一,还是按照它默认的格式来写吧。编辑完之后要记得保存。
4  产生证书

  #cd /etc/openvpn/easy-rsa/2.0/
  #chown -R root:admin .   
  #chmod g+w .

  #source ./vars    //这一步如果提示没有openssl.cnf,所以把openssl-1.0.0.cnf 重命名为openssl.cnf即可.

  #./build-ca  选项默认即可。

  # ./build-key-server server

  # ./build-key  client

    #./build-dh

  新产生的证书可以在/etc/openvpn/easy-rsa/2.0/keys/目录下找到。

5  进行服务器端文件配置

    首先需要复制一份配置样本,然后再在这个基础上进行修改:

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

      #cd  /etc/openvpn/

      #gunzip server.conf.gz

    这样就会解压出一个server.conf文件,打开编辑吧,如果你是从头按我的步骤来的,那么可以直接复制我的配置,其中l有些地方要根据自己的实际情况改一下。需要注意的是标红色字体的地方。

# Which local IP address should OpenVPN
# listen on? (optional)
local xx.xx.xx.xx  #这里的ip用你自己机器上网卡ip


# 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 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 tap
dev 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


# 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 easy-rsa/2.0/keys/ca.crt
cert easy-rsa/2.0/keys/server.crt
key easy-rsa/2.0/keys/server.key


# 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 easy-rsa/2.0/keys/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.9.0.0 255.255.255.0  #虚拟网卡上的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


# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet


# in order for this to work properly).
push "redirect-gateway def1 bypass-dhcp"


# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"


# 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


# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
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

# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo


# The maximum number of concurrently connected


# clients we want to allow.
;max-clients 100


# 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
group nogroup


# 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


# 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


# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.


;mute 20

 

 

6. 配置防火墙数据包转发

  #sysctl -wnet.ipv4.ip_forward=1

  # iptables -t nat -A POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE

7.  运行openvpn服务端 # openvpn /etc/openvpn/server.conf

8.  配置客户端

    a.  复制生成的ca.crt,client.key,client.crt到本地

    b. 编辑client.ovpn文件

 # 定义是一个客户端
client
# 定义使用路由IP模式,与服务端一致
;dev tap
dev tun
# 定义Windows下使用的网卡名称,linux不需要
;dev-node
# 定义使用的协议,与服务端一致
;proto tcp
proto udp


# 指定服务端地址和端口,可以用多行指定多台服务器
# 实现负载均衡(从上往下尝试)
remote xx.xx.xx.xx 1194  #输入服务器的ip以及端口
# 若上面配置了多台服务器,让客户端随机连接
;remote-random


# 解析服务器域名
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# 客户端不需要绑定端口
# Most clients do not need to bind to
# a specific local port number.
nobind
# 也是为了让Openvpn也nobody运行(安全)
# 注意:Windows不能设置
;user nobody
;group nobody


# Try to preserve some state across restarts.
persist-key
persist-tun
# 若客户端通过HTTP Proxy,在这里设置
# 要使用Proxy,不能使用UDP为VPN的通讯协议
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]


# 无线网络有很多多余的头文件,设置忽略它
;mute-replay-warnings
# 重点,就是指定ca和客户端的证书
# 注意,下面的两个号是连在一起的,之间没有空格
ca ca.crt
cert client01.crt
key client01.key
# 如果服务端打开了PAM认证模块,客户端需要另其有效
;auth-user-pass
;tls-auth ta.key 1


# 一些安全措施
# 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.
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x
# 使用lzo压缩,与服务端一致
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
mute 20

  c. 把ca.crt、client.crt、client.key和client.ovpn文件复制到openvpn-gui安装目录下的config文件夹中。

9. 启动openvpn客户端

OpenVPN 的详细介绍:请点这里
OpenVPN 的下载地址:请点这里

相关阅读:

Ubuntu下OpenVPN客户端配置教程 http://www.linuxidc.com/Linux/2013-06/86562.htm

Ubuntu 10.04搭建OpenVPN http://www.linuxidc.com/Linux/2012-11/74790.htm

Ubuntu 13.04 VPN (OpenVPN) 配置和连接不能同时访问内外网的问题 http://www.linuxidc.com/Linux/2013-07/86899.htm

如何在Linux上用OpenVPN搭建安全的远程网络架构 http://www.linuxidc.com/Linux/2013-11/92646.htm


推荐阅读
  • 31.项目部署
    目录1一些概念1.1项目部署1.2WSGI1.3uWSGI1.4Nginx2安装环境与迁移项目2.1项目内容2.2项目配置2.2.1DEBUG2.2.2STAT ... [详细]
  • 1、概述首先和大家一起回顾一下Java消息服务,在我之前的博客《Java消息队列-JMS概述》中,我为大家分析了:然后在另一篇博客《Java消息队列-ActiveMq实战》中 ... [详细]
  • 域名解析系统DNS
    文章目录前言一、域名系统概述二、因特网的域名结构三、域名服务器1.根域名服务器2.顶级域名服务器(TLD,top-leveldomain)3.权威(Authoritative)域名 ... [详细]
  • PHP编程能开发哪些应用?
    导读:很多朋友问到关于PHP编程能开发哪些应用的相关问题,本文编程笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!本文目录一览: ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • 本文介绍了在Web应用系统中,数据库性能是导致系统性能瓶颈最主要的原因之一,尤其是在大规模系统中,数据库集群已经成为必备的配置之一。文章详细介绍了主从数据库架构的好处和实验环境的搭建方法,包括主数据库的配置文件修改和设置需要同步的数据库等内容。MySQL的主从复制功能在国内外大型网站架构体系中被广泛采用,本文总结了作者在实际的Web项目中的实践经验。 ... [详细]
  • PHP组合工具以及开发所需的工具
    本文介绍了PHP开发中常用的组合工具和开发所需的工具。对于数据分析软件,包括Excel、hihidata、SPSS、SAS、MARLAB、Eview以及各种BI与报表工具等。同时还介绍了PHP开发所需的PHP MySQL Apache集成环境,包括推荐的AppServ等版本。 ... [详细]
  • 在单位的一台4cpu的服务器上部署了esxserver,挂载了6个虚拟机,目前运行正常。在安装部署过程中,得到了cnvz.net论坛精华区 ... [详细]
  • php课程Json格式规范需要注意的小细节
    JSON(JavaScriptObjectNotation)是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScriptProgramming ... [详细]
  • SQL Server 2008 到底需要使用哪些端口?
    SQLServer2008到底需要使用哪些端口?-下面就来介绍下SQLServer2008中使用的端口有哪些:  首先,最常用最常见的就是1433端口。这个是数据库引擎的端口,如果 ... [详细]
  • NFS文件共享系统
    1、概述:NFS(NetworkFileSystem)意为网络文件系统,它最大的功能就是可以通过网络,让不同的机器不同的操作系统可以共享 ... [详细]
  • c# java socketn 字节流_C#Socket编程详解(一)TCP与UDP简介
    一、TCP与UDP(转载)1、TCP1.1定义TCP(TransmissionControlProtocol)传输控制协议。是一种可靠的、面向连接的协议(eg:打电话)、传输效率低 ... [详细]
  • IP双栈环境下网络应用迁移
    IPv4向IPv6迁移有多种途径,在选择具体的迁移方式时,当前环境中运行的应用是否支持IPv6是重要的考量因素之一,同时在编写新的应用时,需要考虑新编写的应用不仅可以适应当前主流的IPv4环境, ... [详细]
  • 概述H.323是由ITU制定的通信控制协议,用于在分组交换网中提供多媒体业务。呼叫控制是其中的重要组成部分,它可用来建立点到点的媒体会话和多点间媒体会议 ... [详细]
  • POCOCLibraies属于功能广泛、轻量级别的开源框架库,它拥有媲美Boost库的功能以及较小的体积广泛应用在物联网平台、工业自动化等领域。POCOCLibrai ... [详细]
author-avatar
零夏一夜_335
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有