CentOS6下搭建OpenVPN服务器
OpenVPN是一个用于创建虚拟专用网络(Virtual Private Network)加密通道的免费开源软件。使用OpenVPN可以方便地在家庭、办公场所、住宿酒店等不同网络访问场所之间搭建类似于局域网的专用网络通道。OpenVPN使用方便,运行性能优秀,支持Solaris、Linux 2.2+(Linux 2.2+表示Linux 2.2及以上版本,下同)、OpenBSD 3.0+、FreeBSD、NetBSD、Mac OS X、Android和Windows 2000+的操作系统,并且采用了高强度的数据加密,再加上其开源免费的特性,使得OpenVPN成为中小型企业及个人的VPN首选产品。使用OpenVPN配合特定的代理服务器,可用于访问Youtube、FaceBook、Twitter等受限网站,也可用于突破公司的网络限制。
服务器端:CentOS6.5
客 户 端:Windows7
服务器端软件:epel-release-6-8.noarch.rpm,openvpn,easy-rsa
客户端软件: openvpn-install-2.3.4
1. 关闭SELINUX
setenforce 0 //暂时关闭 sed -i '^SELINUX=/c\SELINUX=disabled' /etc/selinux/config //重启有效
2. 安装"EPEL"源
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm //下载centos6 32位的EPEL源 rpm -ivh epel-release-6-8.noarch.rpm //安装EPEL源 yum makecache //更新本地缓存
3. 安装openvpn
yum -y install openvpn easy-rsa
4. easy-rsa配置
mkdir -p /etc/openvpn/easy-rsa/keys cp -rf/usr/share/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
5. 创建CA证书和密钥
vi /etc/openvpn/easy-rsa/vars //更改你自己的国家,省份,城市,邮箱等... source ./vars //初始化证书的授权中心 ./clean-all //清除keys目录下面的文件 ./build-ca //创建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) [CA]: Locality Name (eg, city) [HZ]: Organization Name (eg, company) [HZ]: Organizational Unit Name (eg, section) [changeme]: Common Name (eg, your name or your server's hostname) [changeme]: Name [changeme]: Email Address [mail@host.domain]:
6. 创建服务端的证书和密钥
./build-key-server server Generating a 1024 bit RSA private key .....++++++ .................++++++ writing new private key to '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) [CA]: Locality Name (eg, city) [HZ]: Organization Name (eg, company) [HZ]: Organizational Unit Name (eg, section) [changeme]: Common Name (eg, your name or your server's hostname) [server]: Name [changeme]: Email Address [mail@host.domain]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/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:'CA' localityName :PRINTABLE:'HZ' organizationName :PRINTABLE:'HZ' organizationalUnitName:PRINTABLE:'changeme' commonName :PRINTABLE:'server' name :PRINTABLE:'changeme' emailAddress :IA5STRING:'mail@host.domain' Certificate is to be certified until Mar 28 03:05:21 2022 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 Update
7. 创建客户端的证书和密钥
./build-key client1 Generating a 1024 bit RSA private key ...++++++ ...............++++++ writing new private key to 'client1.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) [CA]: Locality Name (eg, city) [HZ]: Organization Name (eg, company) [HZ]: Organizational Unit Name (eg, section) [changeme]: Common Name (eg, your name or your server's hostname) [client1]: Name [changeme]: Email Address [mail@host.domain]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/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:'CA' localityName :PRINTABLE:'HZ' organizationName :PRINTABLE:'HZ' organizationalUnitName:PRINTABLE:'changeme' commonName :PRINTABLE:'client1' name :PRINTABLE:'changeme' emailAddress :IA5STRING:'mail@host.domain' Certificate is to be certified until Mar 28 03:21:06 2022 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
8. 创建迪菲霍尔曼密钥交换参数
./build-dh
9. 拷贝服务端证书、秘钥等
cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key,dh2048.pem,ca.crt} /etc/openvpn
10. 配置VPN服务端
cp /usr/share/doc/openvpn-2.3.*/sample/sample-config-files/server.conf/etc/openvpn/ //复制配置文件到/etc/openvpn
修改服务端配置文件:
cat server.conf | grep "^[^#|^;]" //列出未注释的内容
local 10.17.1.20 #监听地址 port 1194 #监听端口 proto tcp #监听协议 dev tun #采用路由隧道模式 ca ca.crt #ca证书路径 cert server.crt #服务器证书 key server.key # This file should be kept secret 服务器密钥 dh dh2048.pem #密钥交换协议文件 server 10.8.0.0 255.255.255.0 #给客户端分配地址池,注意:不能和VPN服务器内网网段有相同 ifconfig-pool-persist ipp.txt push "route 192.168.20.0 255.255.255.0" #允许客户端访问内网 20.0 的网段。 push"dhcp-option DNS 8.8.8.8" #dhcp分配dns client-to-client #客户端之间互相通信 keepalive 10 120 #存活时间,10秒ping一次,120 如未收到响应则视为断线 comp-lzo #传输数据压缩 max-clients 100 #最多允许 100 客户端连接 user nobody #用户 group nobody #用户组 persist-key persist-tun status /var/log/openvpn/openvpn-status.log log /var/log/openvpn/openvpn.log verb 3
11. iptables配置
清空iptables配置: iptables -F iptables -X 配置openvpn的nat功能,将所有网段的包转发到eth0口: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 添加FORWARD白名单: iptables -A FORWARD -i tun+ -j ACCEPT 开启系统的路由功能: echo "1" > /proc/sys/net/ipv4/ip_forward service iptables save //保存iptables配置 service iptables restart //重启iptables
12. 启动openvpn
service openvpn start
13. 配置客户端
复制客户端配置文件client.ovpn:
cp /usr/share/doc/openvpn-2.3.*/sample/sample-config-files/client.conf /etc/openvpn/client.ovpn
修改客户端配置文件:
cat server.conf | grep "^[^#|^;]"
client dev tun proto tcp //改为tcp remote 203.195.xxx.xxx 1194 //OpenVPN服务器的外网IP和端口 resolv-retry infinite nobind persist-key persist-tun ca ca.crt //client1的证书 cert client.crt key client.key //client1的密钥 ns-cert-type server comp-lzo verb 3
1. 拷贝服务器端/etc/openvpn/easy-rsa/keys/{ca.crt,client.crt,client,key}和/etc/openvpn/client.ovpn到Windows7客户端
2. 下载openvpn客户端安装
下载地址: http://pan.baidu.com/s/1ZsgpS
3. 把刚才复制过来的几个文件拷贝到openvpn客户端安装目录下面的config目录里面(C:\Program Files\OpenVPN\config)
4. 启动OpenVPN GUI
在电脑右下角的openvpn图标上右击,选择“Connect”。正常情况下应该能够连接成功,分配正常的IP。
原文来自:http://***/centos6-setup-openvpn.html
更多Linux干货请访问:http://***/
CentOS6下搭建OpenVPN服务器的更多相关文章
- CentOS 6.9/Ubuntu 16.04搭建OpenVPN服务器以及客户端的使用
说明: 1.发现一个很奇怪的现象,CentOS和Ubuntu有着对用户不同的管理理念,比如CentOS中安装一切软件都是以root优先(su -),而Ubuntu则以当前用户优先,安装软件以sudo开 ...
- centos6环境下搭建irc服务器
问题描述 有时候逛技术社区,经常会发现有个叫IRC的东西存在,想搭建下看看到底是个什么东西 说明: 操作系统环境为CentOS6.5_64 安装irc服务器 通过yum进行安装,命令如下: yum i ...
- VPS CentOS-6 下 LNMP HTTP服务器的搭建
VPS CentOS-6 下 LNMP HTTP服务器的搭建 前言 恢复更新后的第一篇博文, 前段时间由于各种理由, 把博客更新给宕掉了, 个人独立博客的开发也搁浅了, 现在随着工作的逐步稳定, 决心 ...
- Centos6.8下搭建SVN服务器
1.Centos6.8下搭建SVN服务器 Subversion是一个自由,开源的版本控制系统.Subversion将文件存放在中心版本库里.这个版本库很像一个普通的文件服务器,不同的是,它可以记录每一 ...
- CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)
CentOS 6.5下搭建ftp服务器 vsftpd(very secure ftp daemon,非常安全的FTP守护进程)是一款运行在Linux操作系统上的FTP服务程序,不仅完全开源而且免费,此 ...
- CentOS 6.2下搭建Web服务器
1Centos 6.2下搭建web服务器 如今,Linux在Web应用越来越广,许多企业都采用Linux来搭建Web服务器,这样即节省了购买正版软件的费用,而且还能够提高服务器的安全性. 之前我们介绍 ...
- CentOS 6.3下搭建Web服务器
准备前的工作: 1.修改selinux配置文件(/etc/sysconfig/selinux) 关闭防火墙 (1)把SELINUX=enforcing注释掉 (2)并添加SELINUX=disable ...
- 【转】在Linux下搭建Git服务器
在 Linux 下搭建 Git 服务器 环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.windows. ...
- ubuntu 14.04LTS 环境下搭建tftp服务器
花费我一整天的时间在 ubuntu 14.04LTS 环境下搭建tftp服务器,网上好多资料参差不齐,简单来说,TFTP(Trivial File Transfer Protocol),是一个基于UD ...
随机推荐
- nginx 配置优化的几个参数
nginx 配置优化的几个参数 2011-04-22 本文地址: http://blog.phpbean.com/a.cn/7/ --水平有限欢迎指正-- -- 最近在服务器上搞了一些nginx 研究 ...
- 常用的正则表达式(例如:匹配中文、匹配html)(转载)
匹配中文字符的正则表达式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^x00-xff] 评注:可以用来计算字符串 ...
- node开发 npm install -g express-generator@4
Node forever : 1,forever start --uid test start app.js 2,forever start --uid test start -a app.js 3, ...
- 【Noip2012】解题报告【字符】【贪心】【高精度】【倍增】【set】
目录:1:vigenere密码[字符]2:国王游戏[贪心][高精度]3:开车旅行[倍增][set] 题目: VJ P1778 vigenere密码 Accepted 标签:NOIP提高组2012 ...
- dhtmlxScheduler日历日程控件包括天视图,周视图,月视图,年视图和日程表视图
dhtmlxScheduler 是一个基于Web的类似于Outlook的日历日程控件. 它完全由javascript/js/css编写, 提供类似于MS Outlook Calendar, Apple ...
- iphone获取当前磁盘信息
获取iphone磁盘总大小.已使用空间.空闲空间 [代码]悦德财富:https://www.yuedecaifu.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- 端口占用问题——netstat命令
1.查看所有的端口占用情况 C:\>netstat -ano 协议 本地地址 外部地址 状态 PID(进程号) TCP 127.0.0.1:1434 ...
- 虚拟机无法上网的问题:无法启动VMnet0等问题
虚拟机无法上网,由于之前安装过虚拟机,后来将它卸载了,然后重新安装,最后出现了虚拟机无法上网.刚开始以为是系统的原因,于是就通过linux命令查看系统里面的网卡时是否启动,如:/etc/init.d/ ...
- FZU1683 矩阵
//Accepted 220 KB 359 ms #include <cstdio> #include <cstring> ; int pp; struct matrix { ...
- 统计文件夹下java代码行数的小程序--主要是学习任务队列的思想
首先感谢czbk的老师,录制的视频,让我们有这么好的学习资料.……—— 统计文件夹java文件的行数,首先想到的肯定是用递归的方法,因为文件夹下面可能包含文件夹,用递归的方法,代码容易写.(这和写简单 ...