在VPS创建open vpn指南

Linux VPS 支持
头像
oneleaf
论坛管理员
帖子: 10454
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

在VPS创建open vpn指南

#1

帖子 oneleaf » 2010-03-22 17:59

首先在面板激活tup或找客服开启tup

以下命令均在root账户下执行:
一、安装openvpn,iptables

代码: 全选

apt-get install openvpn iptables
二、生成openvpn密钥

代码: 全选

cd ~
cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 .
cd 2.0
source ./vars
./clean-all
./build-ca
./build-key-server server
./build-key client
./build-dh
cp keys/ca.crt /etc/openvpn/
cp keys/server.* /etc/openvpn/
cp keys/dh1024.pem /etc/openvpn/
三、获取服务端配置文件

代码: 全选

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz  /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz
四、配置 /etc/openvpn/server.conf 让客户端使用这个服务器的地址作为默认网关

代码: 全选

echo "push \"redirect-gateway def1\"" >> /etc/openvpn/server.conf
五、启动服务

代码: 全选

/etc/init.d/openvpn start
六、配置服务器网络,允许数据转发

代码: 全选

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE
=====以上服务端配置完毕,以下配置客户端=====

一、客户端安装openvpn

代码: 全选

sudo apt-get install openvpn
二、复制配置文件,将VPSIP替换为你的VPS服务器的IP地址

代码: 全选

sudo scp root@VPSIP:/root/2.0/keys/client.crt /etc/openvpn/
sudo scp root@VPSIP:/root/2.0/keys/client.key /etc/openvpn/
sudo scp root@VPSIP:/root/2.0/keys/ca.crt /etc/openvpn/
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn/
三、修改 /etc/openvpn/client.conf 配置文件,将服务器的IP地址写入到配置文件。将VPSIP替换为你的VPS服务器的IP地址

代码: 全选

sudo vim /etc/openvpn/client.conf

代码: 全选

remote my-server-1 1194
修改为

代码: 全选

remote VPSIP 1194
四、运行openvpn

代码: 全选

sudo /etc/init.d/openvpn start
头像
oneleaf
论坛管理员
帖子: 10454
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

Re: 在VPS创建open vpn指南

#2

帖子 oneleaf » 2010-03-22 18:29

如果碰到无法使用,可以尝试将 服务器上的 server.conf 和 客户端的 client.conf 的 udp 协议改为 tcp 协议

即如下,然后重启服务端和客户端试试。

代码: 全选

proto tcp
;proto udp
delectate
帖子: 18311
注册时间: 2008-01-09 22:41

Re: 在VPS创建open vpn指南

#3

帖子 delectate » 2010-03-22 18:43

顶着先

我ssh看youtube,最快也就30k,郁闷呢
头像
percy
帖子: 508
注册时间: 2006-09-10 8:19
系统: Gentoo/Mac OS X
来自: Shanghai,China
联系:

Re: 在VPS创建open vpn指南

#4

帖子 percy » 2010-03-22 22:32

在自己电脑上安装openvpn,提示nat表无法初始化,这是什么原因呢?

代码: 全选


 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables v1.4.7: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

头像
percy
帖子: 508
注册时间: 2006-09-10 8:19
系统: Gentoo/Mac OS X
来自: Shanghai,China
联系:

Re: 在VPS创建open vpn指南

#5

帖子 percy » 2010-03-22 23:20

解决了,在内核中打开nat选项,重新编译就好了。
percy 写了:在自己电脑上安装openvpn,提示nat表无法初始化,这是什么原因呢?

代码: 全选


 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables v1.4.7: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

头像
oneleaf
论坛管理员
帖子: 10454
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

Re: 在VPS创建open vpn指南

#6

帖子 oneleaf » 2010-03-22 23:38

应该是iptables出了问题,换个内核试试
头像
newnetexr
帖子: 163
注册时间: 2010-01-23 23:38
联系:

Re: 在VPS创建open vpn指南

#7

帖子 newnetexr » 2010-03-24 13:36

:em20 感觉很慢,而且有一些网站无法打开,不知道是什么原因
头像
meteormatt
帖子: 693
注册时间: 2008-02-24 14:15
系统: Ubuntu
来自: 江苏
联系:

Re: 在VPS创建open vpn指南

#8

帖子 meteormatt » 2010-04-05 21:35

newnetexr 写了::em20 感觉很慢,而且有一些网站无法打开,不知道是什么原因

是不是你那里的网络问题?

怀念以前的老台式机。可惜现在租的地方没条件用了。目前只能用笔记本和手机了。
totu
帖子: 4
注册时间: 2008-05-09 17:41

Re: 在VPS创建open vpn指南

#9

帖子 totu » 2010-04-07 0:50

谢谢一叶

配置顺利(除了要安装iptables),试着看了一段Youtube上TBBT 1分半的视频,480P模式缓冲很快。facebook也很快,twitter稍慢但也可以接受。看到几个久违的Google 服务,哈哈 :em11
试了几个国内网站,速度也都不错
之前用Google DNS 后访问极慢的 espn.com 和 livespace 现在也变得正常了
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: 在VPS创建open vpn指南

#10

帖子 速腾1994 » 2010-04-07 12:51

o
qmake
帖子: 62
注册时间: 2007-07-11 9:35
来自: Jilin University

Re: 在VPS创建open vpn指南

#11

帖子 qmake » 2010-04-07 22:25

我的openvpn连接上了,但是不能上网。
daemon.log显示为:

代码: 全选

Apr  7 14:21:47 cqjiaheng ovpn-server[12133]: cqjiaheng-client/220.243.137.28:60933 PUSH: Received control message: 'PUSH_REQUEST'
Apr  7 14:21:47 cqjiaheng ovpn-server[12133]: cqjiaheng-client/220.243.137.28:60933 SENT CONTROL [cqjiaheng-client]: 'PUSH_REPLY,redirect-gateway def1,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)
客户端log显示为:

代码: 全选

Options error: Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]:3: topology (2.0.9)
麻烦各位大大帮忙看看怎么回事,谢谢!
wangyanlb
帖子: 6
注册时间: 2010-03-12 18:58

Re: 在VPS创建open vpn指南

#12

帖子 wangyanlb » 2010-04-07 23:18

终于调试好了,不过碰到了一个问题,有些网站如youtube直接被封了DNS,默认的配置文件是没有把DNS解析推给客户端的,修改了服务器的配置

push "dhcp-option DNS 208.67.222.222"


解决上述问题
busywinter
帖子: 7
注册时间: 2010-04-10 2:17

Re: 在VPS创建open vpn指南

#13

帖子 busywinter » 2010-04-14 3:16

我的客户端连接openvpn后用ifconfig查看时,有:inet addr:10.8.0.10 P-t-P:10.8.0.9
其中的”inet addr“和”P-t-P"分别是什么意思啊?我看路由表里的网关都是用的P-t-P那个地址,但是ping的话只有inet addr能ping通,这是怎么一回事呢?求解答
sd3188818
帖子: 2
注册时间: 2010-03-28 14:45

Re: 在VPS创建open vpn指南

#14

帖子 sd3188818 » 2010-04-25 12:50

写iptables规则的时候提示

代码: 全选

iptables: No chain/target/match by that name.
这个怎么解决啊?
wangyanlb
帖子: 6
注册时间: 2010-03-12 18:58

Re: 在VPS创建open vpn指南

#15

帖子 wangyanlb » 2010-04-30 0:55

老大给的iptable命令好像失效了,估计是服务器内核变了。有效的命令如下:

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j SNAT --to-source 服务器IP
回复