VPS下安装配置OpenVPN服务器

Standard

上周弄了个vps,3.5美元一个月最便宜的那种.
号称24X7在线服务即时响应,但实际效率很低.
光是开通就用了三天,后让其重装下系统又等了两天,汗呢…
但这价格比起20RMB一月买玩网游用的商业VPN来说还是满划算 ^_^

本来vps上准备装个pptpd,既简单方便又不需专门客户端.可装了才发现vps上面没有相应的内核模块.
发tickets过去询问对方回复只支持openvps和vtun,vtun没用过,所以就装openvpn了.

安装步骤如下:

升级并安装openssl

yum update #全部升一下级
yum install openssl openssl-devel #openssl也许系统已经装了

第三方yum库

cd /etc/yum.repos.d/
vi CentOS-Third.repo
	[dag]
	name=Dag RPM Repository for Red Hat Enterprise Linux
	baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
	gpgcheck=1
	enabled=1
	[kbs-CentOS-Extras]
	name=CentOS.Karan.Org-EL$releasever - Stable
	gpgcheck=1
	gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
	enabled=1
	baseurl=http://centos.karan.org/el$releasever/extras/stable/$basearch/RPMS/
	[kbs-CentOS-Misc]
	name=CentOS.Karan.Org-EL$releasever - Stable
	gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
	gpgcheck=1
	enabled=1
	baseurl=http://centos.karan.org/el$releasever/misc/stable/$basearch/RPMS/
	[kbs-CentOS-Misc-Testing]
	name=CentOS.Karan.Org-EL$releasever - Testing
	gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
	gpgcheck=1
	enabled=1
	baseurl=http://centos.karan.org/el$releasever/misc/testing/i386/RPMS/
 
rpm --import http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

openvpn安装配置

yum install openvpn -y #安装openvpn
 
#找下easy-rsa在哪,将其cp到/etc/openvpn目录下
updatedb
locate easy-rsa
cp -R /../easy-rsa /etc/openvpn/
 
cd /etc/openvpn/easy-rsa
chmod 777 *
mkdir /etc/openvpn/keys
 
vi ./vars
#将export KEY_DIR=/etc/openvpn/keys改为export KEY_DIR=/etc/openvpn/keys
 
source ./vars
 
./clean-all
./build-ca
./build-key-server server
./build-key client1
./build-dh
 
cd /etc/openvpn
vi server.conf
	mode server
	duplicate-cn #多个用户使用同一帐号
	port 1194
	proto udp
	dev tun
	ca keys/ca.crt
	cert keys/server.crt
	key keys/server.key
	dh keys/dh1024.pem
	server 192.168.2.0 255.255.255.0
	client-config-dir ccd
	# Put your Public DNS Servers here
	push "dhcp-option DNS 208.67.222.222"
	push "route 192.168.2.0 255.255.255.0"
	ifconfig-pool-persist ipp.txt
	push "redirect-gateway"
	keepalive 10 120
	comp-lzo
	persist-key
	persist-tun
	status server-tcp.log
	verb 3
 
touch server-tcp.log
touch ipp.txt
vi /etc/init.d/openvpn 去掉119echo 1 > /proc/sys/net/ipv4/ip_forward 前的注释符
 
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to 123.123.123.123
 
/etc/init.d/openvpn start

Windows客户端安装配置
下载地址: http://openvpn.se/files/install_packages/openvpn-2.0.9-gui-1.0.3-install.exe

#my vps
cd /etc/openvpn/keys
tar zcvf clent1key.tar.gz c*
sz clientkey.tar.gz #将其sz下载下来并解压放到C:\Program Files\OpenVPN\config\
 
#windows client
C:\Program Files\OpenVPN\config\client1.ovpn
	client
	dev tun
	proto udp
	remote 174.36.56.242 1194
	resolv-retry infinite
	nobind
	persist-key
	persist-tun
	ca ca.crt
	cert client1.crt
	key client1.key
	ns-cert-type server
	#DNS Options here, CHANGE THESE !!
	push "dhcp-option DNS 208.67.222.222"
	comp-lzo
	verb 3
	status openvpn-status.log

转载请注明出处: http://yemaosheng.com

2 thoughts on “VPS下安装配置OpenVPN服务器

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.