GVKun编程网logo

Centos6.3下利用openvpn部署远程VPN服务

12

想了解Centos6.3下利用openvpn部署远程VPN服务的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于centos6yum安装openvpn、Centos6.2搭建VPN服务、

想了解Centos6.3下利用openvpn部署远程VPN服务的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于centos 6 yum 安装 openvpn、Centos 6.2搭建VPN服务、CentOS 6.8 上OpenVPN部署和使用、CentOS 7安装OpenVPN的新知识。

本文目录一览:

Centos6.3下利用openvpn部署远程VPN服务

Centos6.3下利用openvpn部署远程VPN服务

今天看到群里有人提到openvpn,刚好放假在家,就顺带的研究了下。

2年前自己还是小白的时候就在老单位连总部OA时用过openvpn这个客户端,感觉还挺好用,而且觉得以后项目应该也能用得上,SO google了网上大量零碎资料,折腾了大半天,按照自己的理解就整理了如下文档,给有兴趣的朋友分享一下。

最近一直想把自己的短板,也就是LINUX编程这块好好研究下。。

不扯了,开始干活。。

openvpn是一款在LINUX网关服务器使用的开源的VPN软件,顾名思义,其实就是用来打通一条安全的虚拟专用通道,实现用户远程办公,获取内网资源。

该软件可跨平台在在Linux、xBSD、Mac OS X与Windows间使用,并利用openssl作为加密库,使用加密证书或用户名/密码来实现身份验证,是一款不可多得的开源VPN解决方案。

我们做这个实验的目的就是模拟线上常见的公司外出人员在外需要访问公司内网OA,实现远程办公自动化。

解决方案:


系统环境:centos6.3 x64

OPENVPN: openvpn-2.3.0(附件有下载)

附件打开.rar

vpn server: eth0:192.168.100.90,eth1:172.24.30.1

vpn client: 192.168.100.34

intranet server: 172.24.30.10



部署环境:


1.清空默认策略并重启iptables

# iptables -t NAT -F

# iptables -F

# service iptables save

# service iptables restart


2.关闭SELINUX

# setenforce 0

# vi /etc/sysconfig/selinux

---------------

SELINUX=disabled

---------------


server端(路由模式):


一.网络设置

1.开启服务器端路由转发功能

# vi /etc/sysctl.conf

---------------------

net.ipv4.ip_forward = 1

---------------------

# sysctl -p


2.设置nat转发:

注:保证VPN地址池可路由出外网

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


3.设置openvpn端口通过:

# iptables -A INPUT -p TCP --dport 1194 -j ACCEPT

# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

重启iptables:

注:这里提一下,INPUT策略是执行后即时生效的,POSTROUTING需要保存并重启服务才能生效

# service iptables save

# service iptables restart

注:若想让该服务器只提供openvpn等基本服务,可参照本文档附件iptables脚本


3.时间同步(重要):

# ntpdate asia.pool.ntp.org


二.安装依赖库

# yum install -y openssl openssl-devel lzo lzo-devel pam pam-devel automake pkgconfig


三.安装openvpn:

# wget -c http://swupdate.openvpn.org/community/releases/openvpn-2.3.0.tar.gz

# tar zxvf openvpn-2.3.0.tar.gz

# cd openvpn-2.3.0

# ./configure --prefix=/usr/local/openvpn

# make && make install

# mkdir -p /etc/openvpn

复制模板到openvpn配置目录:

# cp -rf sample /etc/openvpn/

复制openvpn配置文件到主目录:

# cp /etc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/

# cd ..


四.下载easy-rsa:

注:该包用来制作ca证书,服务端证书,客户端证书,openvpn2.3.0该版本源码不包含easy-rsa,所以需要单独下载安装用来配合openvpn实现证书生成。

# wget -c https://github.com/OpenVPN/easy-rsa/archive/master.zip

# unzip master

# mv easy-rsa-master easy-rsa

# cp -rf easy-rsa /etc/openvpn

# cd /etc/openvpn/easy-rsa/easy-rsa/2.0

修改证书变量

# vi vars

修改如下参数

注:在后面生成服务端ca证书时,这里的配置会作为缺省配置

---------------------

export KEY_COUNTRY="CN"

export KEY_PROVINCE="SX"

export KEY_CITY="Xian"

export KEY_ORG="example"

export KEY_EMAIL="user01@example.com"

---------------------

做SSL配置文件软链:

# ln -s openssl-1.0.0.cnf openssl.cnf

修改vars文件可执行并调用

# chmod +x vars

# source ./vars

-----------------

NOTE: If you run ./clean-all,I will be doing a rm -rf on /etc/openvpn/easy-rsa/easy-rsa/2.0/keys

-----------------

注:也就是如果执行./clean-all,就会清空/etc/openvpn/easy-rsa/easy-rsa/2.0/keys下所有文件


开始配置证书:

1.清空原有证书:

# ./clean-all

注:下面这个命令在第一次安装时可以运行,以后在添加完客户端后慎用,因为这个命令会清除所有已经生成的证书密钥,和上面的提示对应


2.生成服务器端ca证书

# ./build-ca

注:由于之前做过缺省配置,这里一路回车即可


3.生成服务器端密钥证书,后面这个openvpn.example.com就是服务器名,也可以自定义

# ./build-key-server openvpn.example.com

---------------------------

Generating a 2048 bit RSA private key

...................................................+++

..................................+++

writing new private key to 'openvpn.example.com.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) [SX]:

Locality Name (eg,city) [Xian]:

Organization Name (eg,company) [example]:

Organizational Unit Name (eg,section) []:

Common Name (eg,your name or your server's hostname)


[openvpn.example.com]:

Name [EasyRSA]:

Email Address [user01@example.com]:


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:example

Using configuration from /etc/openvpn/easy-rsa/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches the signature

Signature ok

The Subject's distinguished Name is as follows

countryName :PRINTABLE:'CN'

stateOrProvinceName :PRINTABLE:'SX'

localityName :PRINTABLE:'Xian'

organizationName :PRINTABLE:'example'

commonName :PRINTABLE:'openvpn.example.com'

name :PRINTABLE:'EasyRSA'

emailAddress :IA5STRING:'user01@example.com'

Certificate is to be certified until Jun 10 21:58:49 2023 GMT (3650 days)

Sign the certificate? [y/n]:y

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

Write out database with 1 new entries

Data Base Updated

---------------------------


4.生成所需客户端证书密钥文件(名字任意,建议写成你要发给的人的姓名,方便管理):

# ./build-key client1

# ./build-key client2

注:这里与生成服务端证书配置类似,中间一步提示输入服务端密码,其他按照缺省提示一路回车即可。


5.再生成diffie hellman参数,用于增强openvpn安全性(生成需要漫长等待)

# ./build-dh


6.打包keys

# tar zcvf keys.tar.gz keys/


7.终端发送到客户端备用

# yum install lrzsz -y

# sz keys.tar.gz


五.配置openvpn server:

# vi /etc/openvpn/server.conf

注:可按照默认模板配置,本例为自定义配置文件:

--------------------------

# 设置监听IP,默认是监听所有IP

;local a.b.c.d


# 设置监听端口,必须要对应的在防火墙里面打开

port 1194


# 设置用TCP还是UDP协议?

;proto tcp

proto tcp


# 设置创建tun的路由IP通道,还是创建tap的以太网通道

# 路由IP容易控制,所以推荐使用它;但如果如IPX等必须

# 使用第二层才能通过的通讯,则可以用tap方式,tap也

# 就是以太网桥接

;dev tap

dev tun


# Windows需要给网卡一个名称,这里设置,linux不需要

;dev-node MyTap


# 这里是重点,必须指定SSL/TLS root certificate (ca),

# certificate(cert),and private key (key)

# ca文件是服务端和客户端都必须使用的,但不需要ca.key

# 服务端和客户端指定各自的.crt和.key

# 请注意路径,可以使用以配置文件开始为根的相对路径,

# 也可以使用绝对路径

# 请小心存放.key密钥文件

ca /etc/openvpn/easy-rsa/easy-rsa/2.0/keys/ca.crt

cert /etc/openvpn/easy-rsa/easy-rsa/2.0/keys/openvpn.example.com.crt

key /etc/openvpn/easy-rsa/easy-rsa/2.0/keys/openvpn.example.com.key

# This file should be kept secret


# 指定Diffie hellman parameters.

dh /etc/openvpn/easy-rsa/easy-rsa/2.0/keys/dh2048.pem


# 配置VPN使用的网段,OpenVPN会自动提供基于该网段的DHCP

# 服务,但不能和任何一方的局域网段重复,保证唯一

server 10.8.0.0 255.255.255.0


# 维持一个客户端和virtual IP的对应表,以方便客户端重新

# 连接可以获得同样的IP

ifconfig-pool-persist ipp.txt


# 配置为以太网桥模式,但需要使用系统的桥接功能

# 这里不需要使用

;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100


# 为客户端创建对应的路由,以另其通达公司网内部服务器

# 但记住,公司网内部服务器也需要有可用路由返回到客户端

;push "route 192.168.20.0 255.255.255.0"

push "route 172.24.30.0 255.255.255.0"


# 为特定的客户端指定IP或指定路由,该路由通常是客户端后面的

# 内网网段,而不是服务端连接的网段

# ccd是/etc/openvpn下的目录,其中建有希望限制的客户端Common

# Name为文件名的文件,并通过下面的命令写入固定IP地址

# 例如Common Name为client1,则在/etc/openvpn/ccd/client1写有:

# ifconfig-push 10.9.0.1 10.9.0.2

;client-config-dir ccd

;route 192.168.40.128 255.255.255.248


# 为可以对不同的客户端设置防火墙等权限

# 可以让其自动运行对应脚本,可参考man

;learn-address ./script


# 若客户端希望所有的流量都通过VPN传输,则可以使用该语句

# 其会自动改变客户端的网关为VPN服务器,推荐关闭

# 一旦设置,请小心服务端的DHCP设置问题

;push "redirect-gateway"


# 用OpenVPN的DHCP功能为客户端提供指定的DNS、WINS等

;push "dhcp-option DNS 10.8.0.1"

;push "dhcp-option WINS 10.8.0.1"


# 默认客户端之间是不能直接通讯的,除非把下面的语句注释掉

client-to-client


# 如果您希望有相同Common Name的客户端都可以登陆

# 也可以注释下面的语句,推荐每个客户端都使用不用的Common Name

# 常用于测试

;duplicate-cn


# 设置服务端检测的间隔和超时时间

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


# Select a cryptographic cipher.

# This config item must be copied to

# the client config file as well.

;cipher BF-CBC # Blowfish (default)

;cipher AES-128-CBC # AES

;cipher DES-EDE3-CBC # Triple-DES


# 使用lzo压缩的通讯,服务端和客户端都必须配置

comp-lzo


# 设置最大用户数

;max-clients 100


# 让OpenVPN以nobody用户和组来运行(安全)

;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 /var/log/openvpn/openvpn-status.log


# 缺省日志会记录在系统日志中,但也可以导向到其他地方

# 建议调试的使用先不要设置,调试完成后再定义

log /var/log/openvpn/openvpn.log

log-append /var/log/openvpn/openvpn.log


# 设置日志的级别

#

# 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

--------------------------

创建日志目录:

# mkdir -p /var/log/openvpn/


启动openvpn server

# /usr/local/openvpn/sbin/openvpn --config /etc/openvpn/server.conf &


设置开机启动:

# echo "/usr/local/openvpn/sbin/openvpn --config /etc/openvpn/server.conf > /dev/null 2>&1 &" >> /etc/rc.local


client端:


六.安装WINDOWS客户端(WIN7 64bit)

1.下载客户端,并默认安装:

http://vpntech.googlecode.com/files/openvpn-2.1.1-gui-1.0.3-install-cn-64bit.zip


2.将服务端打包文件解压,并将包内ca.crt、client1.crt、client1.key复制到客户端C:\Program Files\OpenVPN\config下.


3.在C:\Program Files\OpenVPN\config下创建client.ovpn文件

内容如下:

-----------------------

# 定义是一个客户端

client


# 定义使用路由IP模式,与服务端一致

;dev tap

dev tun


# 定义Windows下使用的网卡名称,linux不需要

;dev-node MyTap


# 定义使用的协议,与服务端一致

;proto tcp

proto tcp


# 指定服务端地址和端口,可以用多行指定多台服务器

# 实现负载均衡(从上往下尝试)

remote 192.168.100.90 1194

;remote my-server-2 1194


# 若上面配置了多台服务器,让客户端随机连接

;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 client1.crt

key client1.key


# 如果服务端打开了PAM认证模块,客户端需要另其有效

;auth-user-pass


# 一些安全措施

# 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


# 使用lzo压缩,与服务端一致

comp-lzo


# Set log file verbosity.

verb 3


# Silence repeating messages

;mute 20

-----------------------


5.连接:

在右下角的openvpn图标上右击,选择“Connect”,若能正常分配IP,则连接成功。


6.最终测试:

C:\Users\Administrator>ipconfig/all

---------------------------------------

...............



以太网适配器 本地连接* 12:


连接特定的 DNS 后缀 . . . . . . . :

描述. . . . . . . . . . . . . . . : TAP-Win32 Adapter V9

物理地址. . . . . . . . . . . . . : 00-FF-45-FB-F5-E2

DHCP 已启用 . . . . . . . . . . . : 是

自动配置已启用. . . . . . . . . . : 是

本地链接 IPv6 地址. . . . . . . . : fe80::848d:bd1d:c1f4:fb51%27(首选)

IPv4 地址 . . . . . . . . . . . . : 10.8.0.6(首选)

子网掩码 . . . . . . . . . . . . : 255.255.255.252

获得租约的时间 . . . . . . . . . : 2013年6月15日 22:36:59

租约过期的时间 . . . . . . . . . : 2014年6月15日 22:36:59

默认网关. . . . . . . . . . . . . :

DHCP 服务器 . . . . . . . . . . . : 10.8.0.5

DHCPv6 IAID . . . . . . . . . . . : 453050181

.....................

----------------------------------


在vpn client上ping intranet server 主机IP:172.24.30.10

C:\Users\Administrator>ping 172.24.30.10

-------------------------

正在 Ping 172.24.30.10 具有 32 字节的数据:

来自 172.24.30.10 的回复: 字节=32 时间=2ms TTL=63

来自 172.24.30.10 的回复: 字节=32 时间<1ms TTL=63

来自 172.24.30.10 的回复: 字节=32 时间<1ms TTL=63

来自 172.24.30.10 的回复: 字节=32 时间<1ms TTL=63

--------------------------


大功告成。。。

七.注意事项:

(这里参考并感谢酒哥的“构建高可用LINUX服务器”一书)

1.公司如果有同事离职,如何注销该用户VPN证书:

注:这里需保持openvpn服务正常开启

# cd /etc/openvpn/easy-rsa/easy-rsa/2.0

# ./revoke-full client2

如果报错,则注释掉该目录下openssl.cnf文件若干行内容,如下:

(实际情况执行上面的操作,直接可注销该用户)

-------------------------

#[pkcs11_section]

#engine_id = pkcs11

#dynamic_path = /usr/lib/engines/engine_pkcs11.so

#MODULE_PATH = $EVN::PKCS11_MODULE_PATH

#PIN = $ EVN::PKCS!!_PIN

#init =0

-------------------------

重新注销:

# ./revoke-full client2

若末行返回error23则账号注销成功,但需完全注销掉还需做如下配置:

# vi /etc/openvpn/server.conf

末行添加如下内容保证每次在重启加载openvpn配置文件时都会重新加载crl.pem文件:

-----------------------

crl-verify /etc/openvpn/easy-rsa/easy-rsa/2.0/keys/crl.pem

-----------------------

注:crl.pem为注销的用户的黑名单,可以理解为每次启动openvpn时,加载一次黑名单操作,保证最新被吊销的证书无法使用。


重启openvpn:

# killall openvpn

# /usr/local/openvpn/sbin/openvpn --config /etc/openvpn/server.conf &

在客户端服务器使用client2证书验证该证书是否能够使用

最终确定该证书无法连接openvpn服务器


2.更改证书有效期,提高证书的安全性:

默认证书的有效期是3650天,也就是10年

# cd /etc/openvpn/easy-rsa/easy-rsa/2.0

# vi pkitool

搜索到两处默认有效期天数"3650",修改该为你需要设置的天数保存即可

下次执行该脚本制作客户端证书时,期限就会更改为新的天数。


进阶:

openvpn作为内网server提供远程VPN服务解决方案:

有充裕预算的公司可以搭建openvpn的负载均衡,这里可以把两台服务器挂到内网交换机上,利用一台防火墙隔离内外网,并做分别作到内网这两台openvpn服务器的两条端口映射,保证两台服务器与其他内网服务器同网段,且两台openvpn配置相同。


这个方案其实适用于在项目后期,如果已经架设好防火墙,在既保留现有防火墙的情况下又想远程客户端访问内网资源,其实就可以利用原有防火墙做一个到内网openvpn服务器1194端口的映射,只要能保证openvpn服务器与其他内网资源在同一网段,或者可路由网段,就能起到远程VPN访问功能。

(openvpn-server)

1.打开ip_forward(略)

2.做openvpn地址池网段数据可转发出eth0口的策略

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

3.保证openvpn配置文件做了到内网的路由

---------------------

push "route 192.168.100.0 255.255.255.0"

---------------------

其他配置与网关openvpn模式一致。


最后在客户端配置文件(C:\Program Files\OpenVPN\config\client.ovpn)里添加如下内容:

------------------

remote 172.24.30.40 1194

remote 172.24.30.40 1195

.....

remote-random

------------------

这行客户端会随机连接这2台服务器地址,从而利用其作为代理访问网内其他资源。


--------大功告成----------

本文出自 “一路向北” 博客,请务必保留此出处http://showerlee.blog.51cto.com/2047005/1222738


centos 6 yum 安装 openvpn

centos 6 yum 安装 openvpn

centos 6 yum 安装 openvpn
2012-04-10 21:31

centos 6 默认的yum 源没有openvpn,所以需要添加外部的源

获取

wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

 

rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

 

然后运行 

yum makecache
yum install openvpn

安装完成以后,开始配置

#cp -R /usr/share/openvpn/easy-rsa /etc/openvpn/

# 或者是这个德行,貌似不同的系统,这个位置不一样

我的是centos6.2 是在下面这个位置

cp -R /usr/share/doc/openvpn-2.2.2/easy-rsa /etc/openvpn
cd /etc/openvpn/easy-rsa/2.0
chmod +x ./*
source ./vars

下面开始生成key等文件,所有的都回车默认
./clean-all
创建CA
./build-ca server
创建CA之后来生成服务器证书,输入
./build-key-server server
生成客户端证书,同样,都是默认回车
./build-key client1
./build-key client2
最后生成Diffie Hellman参数:
./build-dh

证书等生成完毕,开始设置配置文件,如下的配置文件支持 单server --->> 多client,而且不会修改默认的网关,所以运行后,不会影响现有的
网络路由,这样可以支持多客户端之间的互相连接
以下文件保存在 /etc/openvpn/server.conf
vim /etc/openvpn/server.conf

引用port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
status /var/run/openvpn.status
server 10.10.10.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-config-dir /etc/openvpn/ccd 
user nobody
group nobody
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
script-security 2
verb 3

如果想支持openvpn 能踢掉连接的用户,可以打开openvpn 的 management 功能,方法就是在配置文件里面添加如下

引用
management 127.0.0.1 9999


使用的方法就是用 telnet 127.0.0.1 9999 
登陆进入后,help下就知道怎么操作了,非常的方便

如果要想修改客户端连接以后,自动修改网关为服务器的地址,并用来fan,用下面的配置文件
引用port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 10.10.10.0 255.255.255.0
push "redirect-gateway def1"
push "dhcp-option DNS 8.8.8.8"
ifconfig-pool-persist ipp.txt
client-config-dir /etc/openvpn/ccd 
user nobody
group nobody
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
script-security 2
verb 3

如果想让服务端支持同一个客户多次登录的化,服务器端配置文件添加如下

引用duplicate-cn

上面的 client-config-dir /etc/openvpn/ccd  表示固定客户的ip,即每个客户拨号上来以后,ip是固定的

创建 /etc/openvpn/ccd 目录, 在目录里面创建CN的名字的文件名,如上,应该为 client1 client2 等样子的文件,内容如下

ifconfig-push 10.10.10.5 10.10.10.6

批量创建这个文件的命令
for i in `seq 1 10`
do
((IPA=i+4))
((IPB=i+5))
echo "ifconfig-push 10.10.10.${IPA} 10.10.10.${IPB}" > /etc/openvpn/ccd/client${i}
done


注意, 每个ip之间,ip间隔4个, 5,9,13 等,依次类推

配置完成openvpn以后,开始配置iptables,设置开启ipv4的路由转发
vim /etc/sysctl.conf
修改为
引用net.ipv4.ip_forward = 1
运行如下命令,配置nat

iptables -t nat -A POSTROUTING -j MASQUERADE

保持开机运行
chkconfig openvpn on
echo ''iptables -t nat -A POSTROUTING -j MASQUERADE'' >> /etc/rc.local

重新启动openvpn服务
/etc/init.d/openvpn restart

打包 keys 目录下的文件,并下载到客户端,具体配置方法,不做说明了,配置文件如下
--------------------------------------------------
以下为客户端配置文件
引用client
dev tun
proto udp
remote  x.x.x.x 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
script-security 2
verb 3

ps: 经过我的测试,在网络不好的情况下,会发生掉包的情况,而且掉包比较厉害,重新连接又可以用.解决的方法如下:

在客户端的配置文件中,添加如下两行,经过测试,这个方法非常有效,服务端不用做修改

引用mssfix 1300
tun-mtu-extra 32

如果是用用户名和密码的方法来验证登陆,需要 openvpn 2.2 的版本,官方最新版本的已经支持
配置文件如下,这里仅仅需要 ca 就可以了,其他的都不需要

引用
client
dev tun
proto udp
remote  xxxx 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
comp-lzo
script-security 2
verb 3
auth-user-pass pass.txt
explicit-exit-notify 2
no-replay

Centos 6.2搭建VPN服务

Centos 6.2搭建VPN服务

系统环境:本次系统采用Centos 6.2 32位系统为基础。

所需工具:dkms-2.0.17.5-1.noarch.rpm

kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm

pptpd-1.3.4-2.el6.i686.rpm

ppp-2.4.5-17.0.rhel6.i686.rpm

首先先把以上工具下载到/home/download下:

#mkdir -p /home/download

#cd /home/download

#wget http://www.hi-vps.com/downloads/dkms-2.0.17.5-1.noarch.rpm

#wget http://wty.name/linux/sources/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm

#wgethttp://poptop.sourceforge.net/yum/stable/rhel6/i386/pptpd-1.3.4-2.el6.i686.rpm

#wgethttp://poptop.sourceforge.net/yum/stable/rhel6/i386/ppp-2.4.5-17.0.rhel6.i686.rpm

继续安装库:

#yum -y install make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers

安装刚才下的工具:

#rpm -ivh dkms-2.0.17.5-1.noarch.rpm

#rpm -ivh kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm

#rpm -Uvhppp-2.4.5-17.0.rhel6.i686.rpm

#rpm -ivhpptpd-1.3.4-2.el6.i686.rpm

把里面的IP跟DNS改成你所使用的DNS。。。

mknod /dev/ppp c 108 0
echo 1 > /proc/sys/net/ipv4/ip_forward
echo “mknod /dev/ppp c 108 0″ >> /etc/rc.local
echo “echo 1 > /proc/sys/net/ipv4/ip_forward” >> /etc/rc.local
echo “localip 172.16.36.1″ >> /etc/pptpd.conf
echo “remoteip 172.16.36.2-254″ >> /etc/pptpd.conf
echo “ms-dns 8.8.8.8″ >> /etc/ppp/options.pptpd
echo “ms-dns 8.8.4.4″ >> /etc/ppp/options.pptpd

防火墙配置:

iptables -t nat -A POSTROUTING -s 172.16.36.0/24 -j SNAT ?to-source `ifconfig | grep ‘inet addr:’| grep -v ’127.0.0.1′ | cut -d: -f2 | awk ‘NR==1 { print $1}’`
iptables -A FORWARD -p tcp ?syn -s 172.16.36.0/24 -j TCPMSS ?set-mss 1356

服务启动:

service iptables save

chkconfig iptables on
chkconfig pptpd on

service iptables start
service pptpd start

好的,到这里,VPN就已经搭建完成了。。。

下面开始建立用户:

#vi /etc/ppp/chap-secrets

编辑内容为(IP中*号代表所有):

# Secrets for authentication using CHAP
# client server secret IP addresses
用户名 pptpd 密码 *

配置好以后,重启pptp服务

#service pptpd start

教程到此结束。。客户端如何配置。这里就不写了。

CentOS 6.8 上OpenVPN部署和使用

CentOS 6.8 上OpenVPN部署和使用

OpenVPN生产环境中实战部署及客户端使用

OpenVPN环境部署

1、环境需求

设备

IP

个人PC,VPN客户端

eth0:192.168.119.0/24

OpenVPN Server

eth0:192.168.239.167;eth1:192.168.119.83

局域网服务器

eth0:192.168.239.165

实现需求

在远端通过VPN客户端对VPN Server后端多个servers直接访问,管理维护

2、查看系统环境

[root@Y-solin~]#cat/etc/redhat-release
CentOSrelease6.9(Final)
[root@Y-solin~]#uname-r
2.6.32-696.1.1.el6.x86_64
[root@Y-solin~]#uname-m
x86_64

4、配置VPN服务器时间同步

(1)安装ntp

[root@Y-solin~]#yuminstallntp

(2)手动同步时间

[root@Y-solin~]#/usr/sbin/ntpdatepool.ntp.org
27Apr10:03:51ntpdate[2387]:steptimeserver85.199.214.101offset7.719699sec

(3)加入定时任务

[root@Y-solin~]#echo'#timesync'>>/var/spool/cron/root
[root@Y-solin~]#echo'*/5****/usr/sbin/ntpdatetime.windows.com>/dev/null2>&1'>>/var/spool/cron/root
[root@Y-solin~]#crontab-l
#timesync
*/5****/usr/sbin/ntpdatetime.windows.com>/dev/null2>&1

安装OpenVPN相关依赖软件

1、建立OpenVPN软件目录

[root@Y-solin~]#mkdir-p/home/solin/opt/openvpm
[root@Y-solin~]#cd/home/solin/opt/openvpm

2、下载所需要的包

(1)下载依赖包

选择下载的版本:http://www.oberhumer.com/opensource/lzo/download/

我这里选择了lzo-2.06:http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz

[root@Y-solinopenvpm]#wget
http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz

(2)下载OpenVPN

选择下载版本:https://build.openvpn.net/downloads/releases/

openvpn-2.4.0:https://build.openvpn.net/downloads/releases/openvpn-2.4.0.tar.gz

这里选择了

[root@Y-solinopenvpm]#wgetftp://ftp-osl.osuosl.org/.1/vectorlinux/VL64-7.0/source/sourceVL/openvpn/2.2.2/src/openvpn-2.2.2.tar.gz

3、安装

(1)编译安装vpn依赖

[root@Y-solinopenvpm]#tarzxflzo-2.06.tar.gz
[root@Y-solinopenvpm]#cdlzo-2.06
[root@Y-solinlzo-2.06]#./configure
configure:ConfiguringLZO2.06
…
[root@Y-solinlzo-2.06]#make
makeall-am
make[1]:Enteringdirectory`/home/solin/opt/openvpm/lzo-2.06'
…
[root@Y-solinlzo-2.06]#makeinstall
make[1]:Enteringdirectory`/home/solin/opt/openvpm/lzo-2.06'
test-z"/usr/local/lib"||/bin/mkdir-p"/usr/local/lib"
…

(2)编译安装VPN

[root@Y-solinopenvpm]#tarzxvfopenvpn-2.2.2.tar.gz
[root@Y-solinopenvpm]#cdopenvpn-2.2.2
[root@Y-solinopenvpn-2.2.2]#./configure--with-lzo-headers=/usr/local/ssl/include--with-lzo-lib=/usr/local/ssl/lib
checkingbuildsystemtype...x86_64-unkNown-linux-gnu
checkinghostsystemtype...x86_64-unkNown-linux-gnu
…
[root@Y-solinopenvpn-2.2.2]#echo$?
0
[root@Y-solinopenvpn-2.2.2]#make
makeall-recursive
make[1]:Enteringdirectory`/home/solin/opt/openvpm/openvpn-2.2.2'
…
[root@Y-solinopenvpn-2.2.2]#echo$?
0
[root@Y-solinopenvpn-2.2.2]#makeinstall
Makinginstallinimages
make[1]:Enteringdirectory`/home/solin/opt/openvpm/openvpn-2.2.2/images'
make[2]:Enteringdirectory`/home/solin/opt/openvpm/openvpn-2.2.2/images'
…
[root@Y-solinopenvpn-2.2.2]#echo$?
0
[root@Y-solinopenvpm]#ll/usr/local/sbin/openvpn
-rwxr-xr-x.1rootroot45711864月2714:40/usr/local/sbin/openvpn

配置OpenVPN server建立CA(Certificate Authority)证书

1、初始化配置

[root@Y-solinopenvpn-2.2.2]#cdeasy-rsa/2.0/
[root@Y-solin2.0]#tail-6vars
exportKEY_EMAIL=mail@host.domain
exportKEY_CN=changeme
exportKEY_NAME=changeme
exportKEY_OU=changeme
exportPKCS11_MODULE_PATH=changeme
exportPKCS11_PIN=1234
[root@Y-solin2.0]#pwd
/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0
[root@Y-solin2.0]#cpvarsvars.solin.170427
[root@Y-solin2.0]#vivars
修改如下
#exportKEY_COUNTRY="US"
exportKEY_COUNTRY="CN"
#exportKEY_PROVINCE="CA"
exportKEY_PROVINCE="SH"
#exportKEY_CITY="SanFrancisco"
exportKEY_CITY="ShangHai"
#exportKEY_ORG="Fort-Funston"
exportKEY_ORG="Y-solin"
#exportKEY_EMAIL="me@myhost.mydomain"
exportKEY_EMAIL="yalsnlin@sina.com"
exportKEY_EMAIL=mail@host.domain
exportKEY_CN=changeme
#exportKEY_NAME=changeme
exportKEY_NAME=Y-solin
#exportKEY_OU=changeme
exportKEY_OU=BDCOM
exportPKCS11_MODULE_PATH=changeme
exportPKCS11_PIN=1234
[root@Y-solin2.0]#.vars
NOTE:Ifyourun./clean-all,Iwillbedoingarm-rfon/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0/keys
[root@Y-solin2.0]#./clean-all#清空所有CA

2、创建一个新的CA

[root@Y-solin2.0]#./build-ca
Generatinga1024bitRSAprivatekey
.++++++
.++++++
writingnewprivatekeyto'ca.key'
-----
Youareabouttobeaskedtoenterinformationthatwillbeincorporated
intoyourcertificaterequest.
WhatyouareabouttoenteriswhatiscalledadistinguishednameoraDN.
Therearequiteafewfieldsbutyoucanleavesomeblank
Forsomefieldstherewillbeadefaultvalue,Ifyouenter'.',thefieldwillbeleftblank.
-----
CountryName(2lettercode)[CN]:
StateorProvinceName(fullname)[SH]:
LocalityName(eg,city)[ShangHai]:
OrganizationName(eg,company)[Y-solin]:
OrganizationalUnitName(eg,section)[BDCOM]:
CommonName(eg,yournameoryourserver'shostname)[changeme]:Y-solin
Name[Y-solin]:
EmailAddress[mail@host.domain]:yalsnlin@sina.com
查看创建的CA证书
[root@Y-solin2.0]#ls-lkeys/
总用量12
-rw-r--r--.1rootroot13304月2715:58ca.crt
-rw-------.1rootroot9124月2715:58ca.key
-rw-r--r--.1rootroot04月2715:51index.txt
-rw-r--r--.1rootroot34月2715:51serial

生成服务器端证书和秘钥key文件


1、生成一个服务端的证书

[root@Y-solin2.0]#./build-key-serverserver
Generatinga1024bitRSAprivatekey
....................++++++
...........++++++
writingnewprivatekeyto'server.key'
-----
Youareabouttobeaskedtoenterinformationthatwillbeincorporated
intoyourcertificaterequest.
WhatyouareabouttoenteriswhatiscalledadistinguishednameoraDN.
Therearequiteafewfieldsbutyoucanleavesomeblank
Forsomefieldstherewillbeadefaultvalue,yournameoryourserver'shostname)[server]:
Name[Y-solin]:
EmailAddress[mail@host.domain]:yalsnlin@sina.com
Pleaseenterthefollowing'extra'attributes
tobesentwithyourcertificaterequest
Achallengepassword[]:bdyun
Anoptionalcompanyname[]:BDCOM
Usingconfigurationfrom/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Checkthattherequestmatchesthesignature
Signatureok
TheSubject'sdistinguishednameisasfollows
countryName:PRINTABLE:'CN'
stateOrProvinceName:PRINTABLE:'SH'
localityName:PRINTABLE:'ShangHai'
organizationName:PRINTABLE:'Y-solin'
organizationalUnitName:PRINTABLE:'BDCOM'
commonName:PRINTABLE:'server'
name:PRINTABLE:'Y-solin'
emailAddress:IA5STRING:'yalsnlin@sina.com'
CertificateistobecertifieduntilApr2508:13:482027GMT(3650days)
Signthecertificate?[y/n]:y
1outof1certificaterequestscertified,commit?[y/n]y
Writeoutdatabasewith1newentries
DataBaseUpdated

查看生成的CA证书

[root@Y-solin2.0]#ls-lrtkeys/
总用量40
-rw-r--r--.1rootroot34月2715:51serial.old
-rw-r--r--.1rootroot04月2715:51index.txt.old
-rw-------.1rootroot9124月2715:58ca.key
-rw-r--r--.1rootroot13304月2715:58ca.crt
-rw-------.1rootroot9164月2716:13server.key
-rw-r--r--.1rootroot7734月2716:13server.csr
-rw-r--r--.1rootroot40294月2716:14server.crt
-rw-r--r--.1rootroot34月2716:14serial
-rw-r--r--.1rootroot214月2716:14index.txt.attr
-rw-r--r--.1rootroot1244月2716:14index.txt
-rw-r--r--.1rootroot40294月2716:1401.pem

生成客户端证书和key文件

(1)生成客户端证书秘钥

[root@Y-solin2.0]#./build-keysolin
Generatinga1024bitRSAprivatekey
.++++++
........................................++++++
writingnewprivatekeyto'solin.key'
-----
Youareabouttobeaskedtoenterinformationthatwillbeincorporated
intoyourcertificaterequest.
WhatyouareabouttoenteriswhatiscalledadistinguishednameoraDN.
Therearequiteafewfieldsbutyoucanleavesomeblank
Forsomefieldstherewillbeadefaultvalue,yournameoryourserver'shostname)[solin]:
Name[Y-solin]:
EmailAddress[mail@host.domain]:yalsnlin@sina.com
Pleaseenterthefollowing'extra'attributes
tobesentwithyourcertificaterequest
Achallengepassword[]:bdyun
Anoptionalcompanyname[]:BDCOM
Usingconfigurationfrom/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Checkthattherequestmatchesthesignature
Signatureok
TheSubject'sdistinguishednameisasfollows
countryName:PRINTABLE:'CN'
stateOrProvinceName:PRINTABLE:'SH'
localityName:PRINTABLE:'ShangHai'
organizationName:PRINTABLE:'Y-solin'
organizationalUnitName:PRINTABLE:'BDCOM'
commonName:PRINTABLE:'solin'
name:PRINTABLE:'Y-solin'
emailAddress:IA5STRING:'yalsnlin@sina.com'
CertificateistobecertifieduntilApr2508:30:572027GMT(3650days)
Signthecertificate?[y/n]:y
1outof1certificaterequestscertified,commit?[y/n]y
Writeoutdatabasewith1newentries
DataBaseUpdated
[root@Y-solin2.0]#ls-lrtkeys/
总用量64
-rw-------.1rootroot9124月2715:58ca.key
-rw-r--r--.1rootroot13304月2715:58ca.crt
-rw-------.1rootroot9164月2716:13server.key
-rw-r--r--.1rootroot7734月2716:13server.csr
-rw-r--r--.1rootroot40294月2716:14server.crt
-rw-r--r--.1rootroot34月2716:14serial.old
-rw-r--r--.1rootroot1244月2716:14index.txt.old
-rw-r--r--.1rootroot214月2716:14index.txt.attr.old
-rw-r--r--.1rootroot40294月2716:1401.pem
-rw-------.1rootroot9204月2716:30solin.key
-rw-r--r--.1rootroot7694月2716:30solin.csr
-rw-r--r--.1rootroot39074月2716:31solin.crt
-rw-r--r--.1rootroot34月2716:31serial
-rw-r--r--.1rootroot214月2716:31index.txt.attr
-rw-r--r--.1rootroot2474月2716:31index.txt
-rw-r--r--.1rootroot39074月2716:3102.pem

(2)生成客户端拨号需要密码的证书秘钥

[root@Y-solin2.0]#./build-key-passxiaodangjia
Generatinga1024bitRSAprivatekey
...........++++++
.........++++++
writingnewprivatekeyto'xiaodangjia.key'
EnterPEMpassphrase:
Verifying-EnterPEMpassphrase:
-----
Youareabouttobeaskedtoenterinformationthatwillbeincorporated
intoyourcertificaterequest.
WhatyouareabouttoenteriswhatiscalledadistinguishednameoraDN.
Therearequiteafewfieldsbutyoucanleavesomeblank
Forsomefieldstherewillbeadefaultvalue,yournameoryourserver'shostname)[xiaodangjia]:
Name[Y-solin]:
EmailAddress[mail@host.domain]:yalsnlin@sina.com
Pleaseenterthefollowing'extra'attributes
tobesentwithyourcertificaterequest
Achallengepassword[]:bdyun
Anoptionalcompanyname[]:BDCOM
Usingconfigurationfrom/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Checkthattherequestmatchesthesignature
Signatureok
TheSubject'sdistinguishednameisasfollows
countryName:PRINTABLE:'CN'
stateOrProvinceName:PRINTABLE:'SH'
localityName:PRINTABLE:'ShangHai'
organizationName:PRINTABLE:'Y-solin'
organizationalUnitName:PRINTABLE:'BDCOM'
commonName:PRINTABLE:'xiaodangjia'
name:PRINTABLE:'Y-solin'
emailAddress:IA5STRING:'yalsnlin@sina.com'
CertificateistobecertifieduntilApr2608:26:542027GMT(3650days)
Signthecertificate?[y/n]:y
1outof1certificaterequestscertified,255);text-align:justify;">

生成generate diffie hellman parameter

生成传输进行秘钥交换时用到的交换秘钥协议文件

[root@Y-solin2.0]#./build-dh
GeneratingDHparameters,1024bitlongsafeprime,generator2
Thisisgoingtotakealongtime
......

sgiTPmw0970.jpg">

查看生成的证书

[root@Y-solin2.0]#pwd
/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0
[root@Y-solin2.0]#llkeys/
总用量84
-rw-r--r--.1rootroot40294月2716:1401.pem
-rw-r--r--.1rootroot39074月2716:3102.pem
-rw-r--r--.1rootroot39214月2716:3603.pem
-rw-r--r--.1rootroot13304月2715:58ca.crt
-rw-------.1rootroot9124月2715:58ca.key
-rw-r--r--.1rootroot2454月2716:44dh1024.pem
-rw-r--r--.1rootroot3764月2716:36index.txt
-rw-r--r--.1rootroot214月2716:36index.txt.attr
-rw-r--r--.1rootroot214月2716:31index.txt.attr.old
-rw-r--r--.1rootroot2474月2716:31index.txt.old
-rw-r--r--.1rootroot34月2716:36serial
-rw-r--r--.1rootroot34月2716:31serial.old
-rw-r--r--.1rootroot40294月2716:14server.crt
-rw-r--r--.1rootroot7734月2716:13server.csr
-rw-------.1rootroot9164月2716:13server.key
-rw-r--r--.1rootroot39074月2716:31solin.crt
-rw-r--r--.1rootroot7694月2716:30solin.csr
-rw-------.1rootroot9204月2716:30solin.key
-rw-r--r--.1rootroot39214月2716:36xiaodangjia.crt
-rw-r--r--.1rootroot7774月2716:36xiaodangjia.csr
-rw-------.1rootroot9164月2716:36xiaodangjia.key

配置服务端VPN配置文件server.conf(服务端模板配置文件)

1、把所有的keys和配置文件拷贝到/etc/openvpn目录下

[root@Y-solin2.0]#mkdir-p/etc/openvpn
[root@Y-solin2.0]#cp-a/home/solin/opt/openvpm/openvpn-2.2.2/easy-rsa/2.0/keys/etc/openvpn/
[root@Y-solin2.0]#cp-a/home/solin/opt/openvpm/openvpn-2.2.2/sample-config-files/*.conf/etc/openvpn/

2、进入/etc/openvpn目录

备份server.conf文件

[root@Y-solin2.0]#cd/etc/openvpn/
[root@Y-solinopenvpn]#ll
总用量36
-rw-rw-r--.1500500342610月212010client.conf
drwx------.2rootroot40964月2716:44keys
-rw-rw-r--.15005001028810月212010server.conf
-rw-rw-r--.1500500174210月212010static-home.conf
-rw-rw-r--.1500500168810月212010static-office.conf
-rw-rw-r--.1500500193710月212010tls-home.conf
-rw-rw-r--.1500500194810月212010tls-office.conf
[root@Y-solinopenvpn]#cpserver.confserver.conf.solin.170427

过滤出默认开启的配置

[root@Y-solinopenvpn]#pwd
/etc/openvpn
[root@Y-solinopenvpn]#egrep-v"^#|^$^|;"server.conf
port1194
protoudp
devtun
caca.crt
certserver.crt
keyserver.key#Thisfileshouldbekeptsecret
dhdh1024.pem
server10.8.0.0255.255.255.0
ifconfig-pool-persistipp.txt
keepalive10120
comp-lzo
persist-key
persist-tun
statusopenvpn-status.log
verb3

过滤内容追加到新文件

[root@Y-solinopenvpn]#egrep-v"^#|^$|^;"server.conf>solin-vpn.conf
[root@Y-solinopenvpn]#catsolin-vpn.conf
port1194
protoudp
devtun
caca.crt
certserver.crt
keyserver.key#Thisfileshouldbekeptsecret
dhdh1024.pem
server10.8.0.0255.255.255.0
ifconfig-pool-persistipp.txt
keepalive10120
comp-lzo
persist-key
persist-tun
statusopenvpn-status.log
verb3


修改生成的配置文件

[root@Y-solinopenvpn]#visolin-vpn.conf
修改如下
local192.168.119.96
port52115
prototcp
devtun
ca/etc/openvpn/keys/ca.crt
key/etc/openvpn/keys/server.key
cert/etc/openvpn/keys/server.crt
dh/etc/openvpn/keys/dh1024.pem
server10.8.0.0255.255.255.0
ifconfig-pool-persistipp.txt
keepalive10120
comp-lzo
persist-key
persist-tun
statusopenvpn-status.log
verb3
push"route192.168.239.0255.255.255.0"
client-to-client
log/var/log/openvpn.log

启动服务端的VPN服务

0、取消防火墙对VPN(1194,52115)的拦截

1、开启内核转发功能

(1)修改sysctl.conf

[root@Y-solinopenvpn]#vi/etc/sysctl.conf
修改
…
net.ipv4.ip_forward=1
…

(2)配置生效

[root@Y-solinopenvpn]#sysctl-p
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

2、启动OpenVPN服务

[root@Y-solinopenvpn]#/usr/local/sbin/openvpn--config/etc/openvpn/solin-vpn.conf&
[1]48435

3、检查VPN服务端口

[root@Y-solinopenvpn]#netstat-lntup|grep52115
tcp00192.168.119.96:521150.0.0.0:*LISTEN50918/openvpn
[root@Y-solinopenvpn]#ps-ef|grepvpn
root509182392009:22pts/100:00:00/usr/local/sbin/openvpn--config/etc/openvpn/solin-vpn.conf
root509322392009:23pts/100:00:00grepvpn

4、设置开机自启动(两种方式)

方式一:修改rc.local配置文件

[root@Y-solinopenvpn]#echo"#starupopenvpnbysolinat170427">>/etc/rc.local
[root@Y-solinopenvpn]#echo"/usr/local/sbin/openvpn--config/etc/openvpn/solin-vpn.conf&">>/etc/rc.local
[root@Y-solinopenvpn]#tail-2/etc/rc.local
#starupopenvpnbysolinat170427
/usr/local/sbin/openvpn--config/etc/openvpn/solin-vpn.conf&

方式二:加入init.d目录下

注:solin-vpn.conf必须修改为server.conf才可实现

[root@Y-solinopenvpn]#cp/home/solin/opt/openvpm/openvpn-2.2.2/sample-scripts/openvpn.init/etc/init.d/openvpn
[root@Y-solinopenvpn]#chmod755/etc/init.d/openvpn
[root@Y-solinopenvpn]#chkconfigopenvpnon
[root@Y-solinopenvpn]#chkconfig--listopenvpn
openvpn0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

到这里服务端完全配置完毕!

安装WindowsVPN客户端配置VPN连接

1、下载安装客户端

官网下载:https://openvpn.net/index.PHP/download/58-open-source/downloads.html

下载与OpenVPN服务端版本一致的Windows客户端,如果版本不一致可能会导致连接失败。

我这里下载好了

2、openvpn-2.2.2Windows客户端安装

(1)双加开始安装

(2)按默认配置安装就可以了

3、客户端配置

(1)备份client.conf配置文件

[root@Y-solinopenvpn]#pwd
/etc/openvpn
[root@Y-solinopenvpn]#ll
总用量56
-rw-rw-r--.1500500342610月212010client.conf
-rw-------.1rootroot04月2814:13ipp.txt
drwx------.2rootroot40964月2809:09keys
-rw-------.1rootroot2324月2814:13openvpn-status.log
-rw-rw-r--.15005001028810月212010server.conf
-rw-r--r--.1rootroot102884月2717:15server.conf.solin.170427
-rw-r--r--.1rootroot4034月2809:20solin-vpn.conf
-rw-rw-r--.1500500174210月212010static-home.conf
-rw-rw-r--.1500500168810月212010static-office.conf
-rw-rw-r--.1500500193710月212010tls-home.conf
-rw-rw-r--.1500500194810月212010tls-office.conf
[root@Y-solinopenvpn]#cpclient.confclient.conf.solin.17.04.28

(2)过滤配置文件

[root@Y-solinopenvpn]#egrep-v"^#|^;|^$"client.conf
client
devtun
protoudp
remotemy-server-11194
resolv-retryinfinite
nobind
persist-key
persist-tun
caca.crt
certclient.crt
keyclient.key
ns-cert-typeserver
comp-lzo
verb3

(3)过滤内容追加为新的文件

[root@Y-solinopenvpn]#egrep-v"^#|^;|^$"client.conf>client-solin.conf
[root@Y-solinopenvpn]#catclient-solin.conf
client
devtun
protoudp
remotemy-server-11194
resolv-retryinfinite
nobind
persist-key
persist-tun
caca.crt
certclient.crt
keyclient.key
ns-cert-typeserver
comp-lzo
verb3

(4)生产环境下配置

[root@Y-solinopenvpn]#viclient-solin.conf
[root@Y-solinopenvpn]#catclient-solin.conf
client
devtun
#protoudp
prototcp
#remotemy-server-11194
remote192.168.119.9652115
resolv-retryinfinite
nobind
persist-key
persist-tun
caca.crt
#certclient.crt
certsolin.crt
#keyclient.key
keysolin.key
ns-cert-typeserver
comp-lzo
verb3

4、从服务器导出修改好的配置文件和证书文件

在OpenVPN安装目录(我的OpenVPN安装目录:D:\Tools\OpenVPN\config)的config文件夹下,新建client-solin文件夹,把配置好的配置文件和证书文件放在该目录中

[root@Y-solinopenvpn]#szclient-solin.confkeys/ca.crtkeys/solin.*keys/xiaodangjia.*

5、修改配置文件client-solin.conf和证书文件client-solin.ovpn


6、同样的方式导出xiaodangjia配置文件和认证文件

(1)在我的安装目录D:\Tools\OpenVPN\config下,创建client-xiaodangjia文件夹,导入配置文件和认证文件

(2)连接拨号client-xiaodangjia,需要输入密码,连接成功

7、连接拨号

(1)双加打开VPN

(2)拨号连接

(3)连接成功显示绿色

CentOS 7安装OpenVPN

CentOS 7安装OpenVPN

命令很简单,但是网上似乎没资料,只有RHEL6以下的资料。

直接贴命令:

rpm -Uvh openvpn-as-2.0.10-CentOS7.x86_64.rpm ovpn-init

之后端口啥的可以自己改。

init之后需要修改openvpn的账户密码。

1

 
passwd openvpn

然后连上Admin UI就可以了

默认是:

https://xxx.xxx.xxx.xxx:943/admin

今天关于Centos6.3下利用openvpn部署远程VPN服务的分享就到这里,希望大家有所收获,若想了解更多关于centos 6 yum 安装 openvpn、Centos 6.2搭建VPN服务、CentOS 6.8 上OpenVPN部署和使用、CentOS 7安装OpenVPN等相关知识,可以在本站进行查询。

本文标签: