Skip to content

Instantly share code, notes, and snippets.

@willwhui
Last active April 26, 2018 15:06
Show Gist options
  • Save willwhui/b13cf86ff05456bec76a15d2b82fc77f to your computer and use it in GitHub Desktop.
Save willwhui/b13cf86ff05456bec76a15d2b82fc77f to your computer and use it in GitHub Desktop.
在vps上配置openvpn
在vps上配置openvpn
@willwhui
Copy link
Author

willwhui commented Oct 10, 2017

@willwhui
Copy link
Author

willwhui commented Oct 11, 2017

在sentris.net的一个低端vps上配置

选择操作系统时要注意,必须选择允许安装"openvpn"的那种,否则会导致安装dnsmasq失败,应该是服务商不准搭建
我选择了"debian-8-turnkey-openvpn_xxx"那个,按照上面链接教程的步骤逐步完成了。
注意,教程中这一段是要因机器而异的:

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

这句命令是设置nat,完成dhcp的设置。
然而并不是所有的机器都使用了"eth0"这个interface
否则会显示这个错误:

bad source address from client xxx.xxx.xxx.xxx , packet dropped

根据这里的提示(https://www.void.gr/kargig/blog/2008/05/17/openvpn-multi-bad-source-address-from-client-solution/)
运行

cat /etc/network/interfaces

显示

auto venet0
iface venet0 inet manual
	up ifconfig venet0 up
	up ifconfig venet0 127.0.0.2
	up route add default dev venet0
	down route del default dev venet0
	down ifconfig venet0 down

可知我这里的机器的interface是"venet0"
因此,相应的要改成:

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

然后就好了。

@willwhui
Copy link
Author

willwhui commented Oct 11, 2017

在google的服务器上配置。

按照指引顺利完成配置

@willwhui
Copy link
Author

willwhui commented Oct 28, 2017

貌似隔一段时间(比较长)就会断线

重启客户端就可以。
不知道是不是和服务端的/etc/openvpn/server.conf 中的keepalive参数有关?
在服务端和客户端的配置都增加下面这个配置试试:

keepalive 360000 720000 (后一个数字必须大于等于前一个数字的2倍)

意思就是360000秒=100小时内,客户端和服务端之间不联系都视为正常,不要中断连接。

@willwhui
Copy link
Author

willwhui commented Nov 4, 2017

如何配置网站分流

指定特定目标ip流量走vpn,参见https://gist.github.com/willwhui/1febd37a3dd79a503cc8544c3bb18ece#gistcomment-2232565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment