DO上CentOS7配置OpenVPN

来源:互联网 发布:淘宝单怎么刷在哪里刷 编辑:程序博客网 时间:2024/06/08 11:45

一、安装准备

安装openssl-devel、openssl、gcc gcc-c++

yum -y install openssl-devel openssl gcc gcc-c++

二、下载安装lzo、OpenVPN

解压及安装
# tar xvf lzo-2.04.tar.gz
# cd lzo-2.04
# ./configure  --prefix=/usr/local/lzo
# make && make install
# cd ../
# tar xvf openvpn-2.1.4.tar.gz
# cd openvpn-2.1.4
# ./configure  --prefix=/usr/local/openvpn  --with-lzo-headers=/usr/local/lzo/include/  --with-lzo-lib=/usr/local/lzo/lib/ --with-ssl-headers=/usr/include/openssl/ --with-ssl-lib=/usr/lib
# make && make install
# cd ../

三、OpenVPN设置

用easy-rsa生成服务器证书客户端证书

# mkdir  /etc/openvpn

# cp /root/openvpn-2.1.4/easy-rsa/  /etc/openvpn/ -r

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

# cat vars |grep -v '^$'|grep -v '^#'

   下面这个命令在第一次安装时可以运行,以后在添加客户端时千万别运行,这个命令 会清除所有已经生成的证书密钥

# ./clean-all

 初始化参数

# ./vars

  # source vars

 建立根证书

# ./build-ca

生成服务端密钥,后面参数为服务端名称,红色部分为服务端密码

# ./build-key-server hubert.com

生成DH参数

# ./build-dh

  生成客户端密钥(可生成多个客户端密钥,只需要后面参数名不要相同即可)

# ./build-keyhubert1

复制ca证书,服务端证书到OPENVPN配置目录

# cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/

创建服务端配置文件

[root@hhhubert 2.0]# mkdir /etc/openvpn/easy-rsa/2.0/conf
[root@hhhubert 2.0]# pwd
/etc/openvpn/easy-rsa/2.0
[root@hhhubert 2.0]# cp /apps/openvpn-2.1.4/sample-config-files/server.conf /etc/openvpn/easy-rsa/2.0/conf/
[root@hhhubert 2.0]# cat /etc/openvpn/easy-rsa/2.0/conf/server.conf |grep -v '^$'|grep -v '^;'|grep -v '^#'
port 1194
proto udp
dev tun
ca ca.crt
cert
hubert.com.crt
key hubert.com.key  # This file should be kept secret
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb 3

设置服务器路由功能

# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1


启动服务端OPENVPN

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


四、Windows客户端配置

安装openvpn-2.1_rc22-install.exe

            将服务器上的/etc/openvpn/easy-rsa/2.0/keys下的所有文件拷贝到安装目录下的config文件夹里

   将安装目录下\sample-config\client.ovpn拷贝到\config下

   编辑client.ovpn

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote
服务端IP地址 1194

   运行程序

==============================================================================

服务端端运行成功:



客户端连接日志:


a?
0 0