openvpn

回复 收藏
第一部分:OpenVPN概述
VPN(Virtual Private Network)译为“虚拟专用网络”,被定义为通过一个公用网络(通常是Internet)建立一个临时的、安全的连接,是一条安全、稳定的隧道。使用这条隧道可以对数据进行加密,达到安全使用互联网的目的。虚拟专用网络是企业内部网络的拓展,可以帮助远程用户、公司分支机构、商业伙伴及供应商与公司的内部网络建立可信任的安全连接,VPN的实现主要采用隧道、加解密、密钥管理和使用者与设备身份认证等技术。

VPN首先是虚拟的,它使用一个已经存在的基础设施;其次,它是专用的,通过一个安全的协议来封装数据;最后,它是一个网络,将两个或多个设备(或网络)连接起来。VPN可以提供的功能主要有:防火墙功能、认证、加密、隧道化。

OpenVPN是一个具备完全特征的SSL VPN解决方案,可以进行大范围的配置操作,包括远程访问、点对点的VPN以及企业级远程访问解决方案,支持负载均衡、错误恢复以及细粒度的访问控制。OpenVPN通过使用工业标准--SSL/TLS协议来实现数据加密与安全传输,支持Linux、FreeBSD、Windows等操作系统,它并不是一个基于Web的VPN软件,也不与其它VPN软件相兼容。

OpenVPN的技术核心是虚拟网卡,其次是SSL协议的实现,虚拟网卡是使用网络底层编程技术实现的一个驱动软件,安装OpenVPN以后,在主机上会出现一个网卡,此网卡可以像其他网卡一样进行配置。虚拟网卡在很多操作系统下都有相应的实现,这也是OpenVPN能够跨平台实现的一个很重要的原因。

OpenVPN提供了多种身份验证方式,用于确认参与连接的双方的身份,包括预享私钥、第三方证书及用户名/密码组合。预享秘钥最为简单,但它只能用于建立点对点的VPN;基于PKI的第三方证书提供了最完善的功能,但是需要额外的精力去维护一个PKI证书体系;OpenVPN 2.0版本引入了用户名/密码组合的身份验证方式,它可以省略客户端证书,但是仍有一份服务器证书需要被用作加密。

OpenVPN所有的通信都是基于一个单一的IP端口(默认为1194端口),推荐使用UDP协议通信,同时也支持TCP协议。OpenVPN连接能通过大多数的代理服务器,并且能够在NAT环境中很好的工作。服务器端具有向客户端“推送”某些网络配置信息的功能,这些信息包括:IP地址、路由设置等。OpenVPN提供了TUN/TAP两种虚拟网络接口,通过它们,可以分别建立三层IP隧道和虚拟二层以太网,它可以传输任何类型的二层以太网络数据,传输的数据可以通过LZO算法压缩。2.0以后的版本每个进程可以同时管理数个并发的隧道。

OpenVPN在选择协议的时候,需要注意两个加密隧道之间的网络状况,如果有高延迟或丢包较多的情况,最好选择TCP协议作为底层协议,UDP协议由于存在无连接和重传机制,导致隧道上层协议的数据重传,其效率非常低下。

总体来说,OpenVPN具有如下特性:
1、使用单个或者多个服务器配置为可拓展的、负载均衡的VPN服务器,能够处理上千个动态的VPN客户端连接。
2、使用OpenSSL库的加密、验证和证书等保护在互联网上建立的通信。
3、既可以使用基于静态密钥的常规加密(不推荐),也可以使用基于证书的公钥加密。
4、不需要配置复杂的防火墙规则。
5、可以在NAT之上建立隧道网络。
6、可以使用虚拟TAP设备建立安全的以太网桥(桥接模式),使用虚拟TUN设备支持路由模式。
7、可以实现局对局的应用环境。
8、可以穿透一些顽固型的防火墙,直接访问其后端的局域网资源。

第二部分:部署OpenVPN服务器
一、环境概述
为加固广东珠海Linux应用服务器的安全性,公司决定在IDC机房内部搭建一台OpenVPN服务器,同时对广东珠海机房的应用服务器SSH端口做限制,只允许公司出口IP(218.247.217.98)、应用服务器内网IP地址段(192.168.200.0/24)和OpenVPN专有网络(10.8.0.0/24)访问,具体如下:
公司出口IP:218.247.217.98/32
公司局域网办公地址网络段:192.168.4.0/24
OpenVPN服务器内(eth1)/外(eth0)网地址:192.168.200.131 255.255.255.0 / 183.61.9.131 255.255.255.192
应用服务器内网(eth1)IP地址段:192.168.200.0/24

说明:
1、OpenVPN服务器与应用服务器内网之间都已经互通(在同一个网段)。
2、公司局域网员工无需VPN,可以在办公区直接连接IDC机房的应用服务器(外网IP)。
3、外出员工可以通过登录VPN连接机房应用服务器。

二、安装OpenVPN服务器
操作系统:Debian GNU/Linux 7 x86_64
注意事项:为方便调试VPN服务器,建议初期关闭防火墙和Selinux,并同步系统时间(略)

1、安装相关依赖包及开发环境
# apt-get update
# apt-get install gcc make openssl libssl-dev

2、安装lzo,提供压缩功能
# cd /data/soft
# tar zxvf lzo-2.03.tar.gz
# cd lzo-2.03
# ./configure
# make && make install  //默认安装路径为/usr/local
# cd ../
# echo "/usr/local/lib" >> /etc/ld.so.conf  //调整lzo共享库文件路径
# ldconfig

3、安装OpenVPN
# tar zxvf openvpn-2.1.1.tar.gz
# cd openvpn-2.1.1
# ./configure --with-lzo-lib=/usr/local/lib
# make && make install  //默认可执行程序路径为/usr/local/sbin/openvpn

# mkdir -p /etc/openvpn
# cp -r /data/soft/openvpn-2.1.1/easy-rsa /etc/openvpn/
# chmod -R 755 /etc/openvpn/*

三、配置OpenVPN服务器
1、建立ROOT CA的详细信息
# vi /etc/openvpn/easy-rsa/2.0/vars
修改内容如下:
export KEY_COUNTRY="CN"        //所在国家,2个字符
export KEY_PROVINCE="BeiJing"  //所在省份
export KEY_CITY="BeiJing"      //所在城市
export KEY_ORG="yywin"         //所在组织名称
export KEY_EMAIL="13436437221@163.com"  //邮箱地址

使以上修改的变量生效,如下:
# cd /etc/openvpn/easy-rsa/2.0
# source vars

2、初始化keys目录,用于存放必备的文件(如果生成了第一个客户端的证书文件,以后生成第二个客户端证书文件时,此步就无需执行了,因为它会清空所有的证书文件)
# ./clean-all
# ls -l keys/  //执行完毕后,keys目录下会生成两个文件,这两个文件是CA签发数字证书时需要的

3、OpenVPN有两种安全模式,一种是基于使用RSA证书和密钥的SSL/TLS,另一种则使用预先分享的静态密钥,这里采用第一种方式,以使VPN的连接更安全。为了简单起见,这里直接将VPN服务器作为证书颁发机构,直接在VPN服务器端生成CA证书,由它签发的证书是可信的,如下:
# ./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) [yywin]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [yywin CA]:
Name []:
Email Address [13436437221@163.com]:

查看是否生成ca.crt和ca.key文件(ca.key文件是私钥,专门进行数字签名,应对其进行保护,ca.crt包含了公钥,专门用来解密经CA签发过的证书,需分发出去),如下:
# ls -l keys/ | grep ca

4、为服务器生成Diffie-Hellman文件,后面配置VPN时需要用到此文件,如下:
# ./build-dh
# ls -l keys | grep dh

5、为VPN服务器生成证书和密钥,如下:
# ./build-key-server openvpn-server
Generating a 1024 bit RSA private key
.............++++++
..........................................++++++
writing new private key to 'openvpn-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) [BeiJing]:
Locality Name (eg, city) [BeiJing]:
Organization Name (eg, company) [yywin]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [openvpn-server]:
Name []:
Email Address [13436437221@163.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
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:'BeiJing'
localityName          :PRINTABLE:'BeiJing'
organizationName      :PRINTABLE:'yywin'
commonName            :PRINTABLE:'openvpn-server'
emailAddress          :IA5STRING:'13436437221@163.com'
Certificate is to be certified until Oct 25 07:01:39 2024 GMT (3650 days)
Sign the certificate? [y/n]:y  //输入y确认


1 out of 1 certificate requests certified, commit? [y/n]y  //输入y确认
Write out database with 1 new entries
Data Base Updated

查看是否生成成功,如下:
# ls -l keys | grep openvpn-server

6、生成VPN客户端证书文件,如下:
# ./build-key liuchao
Generating a 1024 bit RSA private key
............++++++
.........++++++
writing new private key to 'liuchao.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) [yywin]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [liuchao]:
Name []:
Email Address [13436437221@163.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
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:'BeiJing'
localityName          :PRINTABLE:'BeiJing'
organizationName      :PRINTABLE:'yywin'
commonName            :PRINTABLE:'liuchao'
emailAddress          :IA5STRING:'13436437221@163.com'
Certificate is to be certified until Oct 25 07:14:49 2024 GMT (3650 days)
Sign the certificate? [y/n]:y  //输入y确认


1 out of 1 certificate requests certified, commit? [y/n]y  //输入y确认
Write out database with 1 new entries
Data Base Updated

查看是否生成成功,如下:
# ls -l keys | grep liuchao

7、生成ta.key,防止恶意攻击
# openvpn --genkey --secret keys/ta.key
# ls -l keys/ | grep ta.key

8、配置OpenVPN
# vi /etc/openvpn/server.conf
内容如下:
port 1194
proto tcp
dev tun
ca    /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert  /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.crt
key   /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.key
dh    /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
;ifconfig-pool-persist /etc/openvpn/ipp.txt
push "route 192.168.200.0 255.255.255.0"
push "redirect-gateway def1"
push "dhcp-option DNS 114.114.114.114"
;client-to-client
keepalive 10 120
tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0
comp-lzo
max-clients 100
user root
group root
persist-key
persist-tun
log-append  /var/log/openvpn.log
verb 3

# /usr/local/sbin/openvpn --config /etc/openvpn/server.conf --daemon //启动OpenVPN,并设置开机自动启动

9、设置防火墙策略,开启内核转发功能
# cat /etc/iptables.up.rules     //OpenVPN服务器防火墙策略
内容如下:
*nat
:PREROUTING ACCEPT [13:800]
:INPUT ACCEPT [12:720]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.8.0.0/24 -d 192.168.200.0/24 -j SNAT --to-source 192.168.200.131
-A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 183.61.9.131
COMMIT

*filter
:INPUT DROP [1:80]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [21:2783]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -s 218.247.217.98/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 1194 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,873 -j ACCEPT
-A INPUT -p tcp --sport 53 -j ACCEPT
-A INPUT -p udp --sport 53 -j ACCEPT
-A INPUT -s 192.168.200.0/24 -p tcp -j ACCEPT
-A INPUT -s 10.8.0.0/24 -p tcp -j ACCEPT
COMMIT

# cat /etc/sysctl.conf
内容如下:
# Kernel sysctl configuration file for Debian Linux
# See /etc/sysctl.d/ for additonal system variables
# See sysctl.conf (5) for information.

net.ipv4.ip_forward = 1    //开启内核转发功能
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_max_syn_backlog = 8192
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 65535
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024  65535

10、客户端验证
1)在Windows安装对应版本的OpenVPN客户端程序。
2)将服务器端生成的ca.crt、liuchao.crt、liuchao.key、ta.key复制到OpenVPN客户端程序安装路径的config目录下,并创建client.ovpn配置文件,内容如下:
client
dev tun
proto tcp
remote 183.61.9.131 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert liuchao.crt
key liuchao.key
tls-auth ta.key 1
ns-cert-type server
redirect-gateway def1
route-method exe
route-delay 2
comp-lzo
verb 3
3)以管理员身份打开VPN客户端,右击任务栏右下角的VPN图标,选择连接,连接后,会分配到一个VPN地址,查看客户端路由表,会添加一条到192.168.200.0/24网段的路由,测试是否可以正常连接VPN服务器及应用服务器的内网地址。

附1:使用用户名/密码验证方式登录(无需创建客户端证书)
1、修改服务器端配置文件,如下:
# cat /etc/openvpn/server.conf
内容如下:
port 1194
proto tcp
dev tun
ca    /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert  /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.crt
key   /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.key
dh    /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
;ifconfig-pool-persist /etc/openvpn/ipp.txt
push "route 192.168.200.0 255.255.255.0"
push "redirect-gateway def1"
push "dhcp-option DNS 114.114.114.114"
;client-to-client
keepalive 10 120
tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0
comp-lzo
max-clients 100
user root
group root

;添加密码验证方式
script-security 3 system
auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
client-cert-not-required
username-as-common-name

persist-key
persist-tun
log-append  /var/log/openvpn.log
verb 3

# cat /etc/openvpn/checkpsw.sh  //用于检测用户密码(需要添加可执行权限)
内容如下:
#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se>
#
# This script will authenticate OpenVPN users against
# a plain text file. The passfile should simply contain
# one row per user with the username first followed by
# one or more space(s) or tab(s) and then the password.

PASSFILE="/etc/openvpn/psw-file"  //密码文件
LOG_FILE="/var/log/openvpn-passwd.log"  //日志文件
TIME_STAMP=`date "+%Y-%m-%d %T"`

###########################################################

if [ ! -r "${PASSFILE}" ]; then
  echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}
  exit 1
fi

CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`

if [ "${CORRECT_PASSWORD}" = "" ]; then
  echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
  exit 1
fi

if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
  echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}
  exit 0
fi

echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
exit 1

# chmod 400 /etc/openvpn/psw-file  //修改权限

2、设置用于登录的用户名和密码
# cat /etc/openvpn/psw-file
内容如下:
liuchao  W39)*fy7^P
zwenxun  d^9i0dqw8v
.......  .........
.......  .........   //依次添加即可...

3、重启VPN服务器,使配置生效(略)。

4、客户端配置文件(client.ovpn),内容如下:
client
dev tun
proto tcp
remote 183.61.9.131 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
;cert liuchao.crt   
;key liuchao.key
tls-auth ta.key 1
ns-cert-type server
redirect-gateway def1
route-method exe
route-delay 2
comp-lzo
verb 3
auth-user-pass   //添加验证方式登录
auth-user-pass pass.txt   //验证文件,用于自动登录

pass.txt文件格式为:
账号
密码

5、测试即可...

附2:在公司不通过VPN客户端,直接连接IDC机房只有内网的服务器,大体步骤如下:
1、在公司内网配置一台Linux服务器(192.168.2.99),并配置连接机房OpenVPN服务器,如下:
# cat /etc/openvpn/client.ovpn
内容如下:
client
dev tun
proto tcp
remote 210.73.213.238 1194
resolv-retry infinite
nobind
persist-key
persist-tun
user root
group root
ca /etc/openvpn/ca.crt
cert /etc/openvpn/office.crt
key /etc/openvpn/office.key
ns-cert-type server
redirect-gateway def1
tls-auth /etc/openvpn/ta.key 1
route-delay 2
comp-lzo
verb 3

# /usr/sbin/openvpn --config /etc/openvpn/client.ovpn > /dev/null 2>&1 &   //后台启动

2、开启路由转发功能
# cat /etc/sysctl.conf
内容如下:
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

net.ipv4.ip_forward = 1   //开启内核转发功能
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_max_syn_backlog = 8192
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024  65535
vm.swappiness=10

3、配置防火墙规则,如下:
# cat /etc/sysconfig/iptables
内容如下:
*nat
:PREROUTING ACCEPT [13:800]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 192.168.2.0/24 -d 10.10.1.0/24 -j SNAT --to-source 10.8.0.22   //192.168.2.0/24是公司内网,10.8.0.22是获取的VPN地址,10.10.1.0/24是机房内网
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT

4、公司内网Windows客户端添加路由
route -p add 10.10.1.0 mask 255.255.255.0 192.168.2.99

5、测试即可...

http://www.it165.net/admin/html/201405/2988.html
http://www.centoscn.com/image-text/install/2013/0924/1681.html
http://www.centoscn.com/image-text/config/2013/1010/1774.html


2016-06-17 14:27 举报
已邀请:
0

李昂

赞同来自:

配置说明:
# 监听端口
port 1194

# 协议类型(TCP/UDP)
# 如果网络有高延迟或丢包较多的情况,请选择TCP协议作为底层协议,UDP协议由于存在无连接和重传机制,导致隧道上层协议的数据重传,其效率非常低下
proto tcp

# VPN服务器使用的设备接口,tun为路由隧道模式,实现的功能较多,启动后,会出现tun虚拟接口,建议使用此模式
dev tun

# CA证书的位置,含有CA的公钥,用于验证客户端证书是否合法,专门用来解密经CA签发过的证书
ca    /etc/openvpn/easy-rsa/2.0/keys/ca.crt

# 经CA签发的服务器证书的位置
cert  /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.crt

# 服务器私钥位置,应该设置严格的权限,默认权限为600
key   /etc/openvpn/easy-rsa/2.0/keys/openvpn-server.key

# 生成的DH文件,用于对称加密
dh    /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem

# VPN服务器的地址池,用于为客户端分配VPN地址,VPN服务器自身的tun接口地址为10.8.0.1,只有在路由模式下才能这样设置
server 10.8.0.0 255.255.255.0

# ipp.txt维护着客户端的VPN地址,在客户端重新连接服务器时,服务器根据这个文件中的保存记录,给客户端分配以前同样的VPN地址,启动服务器后,该文件会自动生成
;ifconfig-pool-persist /etc/openvpn/ipp.txt

# 启用此项,则VPN客户端会把VPN服务器当成默认网关(本地默认网关失效),所有从VPN客户端发出的数据包都会重定向到VPN服务器(10.8.0.1),然后由VPN服务器将这些数据包转发出去
# 这使得VPN服务器成为客户端和Internet通信的一个中转站,客户端的所有流量都通过VPN转发出去
# 通常配合NAT转换一起使用
;push "redirect-gateway"
;push "redirect-gateway def1"

# 配置VPN服务器将自己的局域网地址通知给VPN客户端,让客户端有达到服务器后面的局域网的路由,这里省略了下一跳地址10.8.0.1(VPN服务器IP)
push "route 192.168.200.0 255.255.255.0"

# 关于DHCP的一些配置项
push "dhcp-option DNS 219.141.136.10"
push "dhcp-option DNS 219.141.146.10"

# 默认情况下,客户端只能访问VPN服务器,如果想让服务器和客户端所在局域网的用户能相互访问,或者有多个客户端局域网,而又要让这些局域网能相互访问的话,需要配置此项
;client-to-client

# keepalive功能,每隔10秒钟就通过控制通道ping对方,如果在120秒之内未收到应答,则认为对方已经失效
keepalive 10 120

# HMAC防火墙,用于防止Dos攻击,对于没有HMAC签名的控制信息不予处理,注意服务器端后面的数字肯定使用0,客户端使用1
tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0

# 对数据进行压缩,客户端和服务器端必须一致
comp-lzo

# 允许同时有100个用户连接VPN服务器
max-clients 100

# 运行用户和用户组
user nobody
group nobody

# VPN服务器在down掉后再重启时,不再重新访问某些资源,以加快启动速度
persist-key
persist-tun

# VPN日志文件,每次重启动VPN后,保留原有的log信息,新信息追加到文件最后
log-append  /var/log/openvpn.log

# 日志级别,通常设置为等级3
verb 3

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: