Quantcast
Channel: 似水年华 »域名主机
Viewing all articles
Browse latest Browse all 10

Linode VPS安装OpenVPN

$
0
0

Ubuntu 是所有Linode VPS 用户中使用最多的操作系统,也是我曾经安装使用过的唯一一个Linux系统,因此在这里记录一下Ubuntu中安装OpenVPN的过程。步骤完全按照Linode Labrary中的教程来操作。

获取安装系统更新:
apt-get update
apt-get upgrade --show-upgraded

安装OpenVPN:
apt-get install openvpn udev
OpenVPN的配置文件在easy-rsa文件夹里,这些文件的默认目录是 /usr/share/doc/openvpn/examples/easy-rsa/,需要将这些文件放在/etc/openvpn文件里并配置好才能使用。所以要拷贝文件:
cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn

配置公用密匙变量,修改 /etc/openvpn/easy-rsa/2.0/vars

vi /etc/openvpn/easy-rsa/2.0/vars

修改文件里的变量,下面是一个例子,可以直接用,覆盖文件中默认的。要改就改后面两个变量 ORG/组织、EMAIL/邮件。用国内城市不能识别。
export KEY_COUNTRY="US"
export KEY_PROVINCE="OH"
export KEY_CITY="Oxford"
export KEY_ORG="Ducklington"
export KEY_EMAIL=squire@ducklington.org

初始化公用密匙:
cd /etc/openvpn/easy-rsa/2.0/
. /etc/openvpn/easy-rsa/2.0/vars
. /etc/openvpn/easy-rsa/2.0/clean-all
. /etc/openvpn/easy-rsa/2.0/build-ca

生成证书和私人密匙。一路按”回车键”,密码和公司名忽略。
. /etc/openvpn/easy-rsa/2.0/build-key-server server
然后执行
. /etc/openvpn/easy-rsa/2.0/build-key client1
生成Diffie Hellman Parameters:
. /etc/openvpn/easy-rsa/2.0/build-dh
密匙已生成,将/etc/openvpn/easy-rsa/2.0/keys/ 文件夹下的 ca.crt、client1.crt、client1.key 三个文件用FTP下载到电脑上。

将ca.crt、ca.key、dh1024.pem、server.crt、server.key 拷贝到/etc/openvpn 目录下:
cd /etc/openvpn/easy-rsa/2.0/keys
cp ca.crt ca.key dh1024.pem server.crt server.key /etc/openvpn

配置虚拟私人网络,将服务器配置文件server.conf复制到/etc/openvpn/目录下,将客户端配置文件复制到/root/目录里。
cd /usr/share/doc/openvpn/examples/sample-config-files
gunzip -d server.conf.gz
cp server.conf /etc/openvpn/
cp client.conf ~/
cd ~/

修改~/client.conf,配置如下:
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote ducklington.org 1194
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client1.crt
key client1.key

其中将ducklington.org改为服务器IP。将client.conf用FTP下载到电脑上。

启动OpenVPN:
/etc/init.d/openvpn start

配置网络。修改/etc/openvpn/server.conf ,加上一行
push "redirect-gateway def1"

修改/etc/sysctl.conf,去掉下面一行代码前的分号(;),使之生效
net.ipv4.ip_forward=1

执行命令
echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

修改/etc/rc.local,确认包含如下代码:
#!/bin/sh -e
#
# [...]
#
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
exit 0

修改/etc/apt/sources.list,确认包含如下代码:
## universe repositories - uncomment to enable
deb http://us.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid universe
deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe

获取更新,安装dnsmasq:
apt-get update

apt-get install dnsmasq
修改/etc/openvpn/server.conf,加上一行:
push "dhcp-option DNS 10.8.0.1"

重启OpenVPN:
/etc/init.d/openvpn restart

下面是在电脑上安装OpenVPN软件。在openvpn.net上下载,然后安装。如果电脑是WIN7系统,安装时右键点击使用管理员身份来运行程序。安装完成后,将前面下载的ca.crt、client1.crt、client1.key、client.conf拷贝到OenVPN安装目录里的config文件下。

至此,安装配置全部完成。打开OpenVPN GUI程序,选择client来连接即可。连接成功后,右下角的openvpn图标变成绿色。

现在我的问题是打开youtube速度太慢,还不如一些翻墙软件。是不是OpenVPN配置可以优化?知道的童鞋可留言告知。


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images