<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[观夏Note]]></title> 
<link>//gm.angeldm.com/index.php</link> 
<description><![CDATA[新技术番]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[观夏Note]]></copyright>
<item>
<link>//gm.angeldm.com/post//</link>
<title><![CDATA[OpenVZ下安装OpenVPN]]></title> 
<author>果面 &lt;admin@yourname.com&gt;</author>
<category><![CDATA[系统&amp;软件]]></category>
<pubDate>Wed, 14 Jul 2010 05:16:08 +0000</pubDate> 
<guid>//gm.angeldm.com/post//</guid> 
<description>
<![CDATA[ 
	不过OpenVPN有一个致命缺点，就是绝大多数移动设备不支持，电脑上使用需要安装复杂的客户端。<br/><br/>网上有很多的教程，但大都不适合VPS或者不完善，我根据我自己安装的经验，记录下来以便查阅。<br/><br/>OpenVPN需要TUN支持，大多数VPS默认都没有开启，你可以用这个命令检测：<br/><div class="code">cat /dev/net/tun</div><br/>如果返回信息为：cat: /dev/net/tun: File descriptor in bad state 说明正常。<br/>如果你需要连上OpenVPN后能访问互联网，还需要iptables_nat模块支持，用这个命令检测：<br/><div class="code">iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE</div><br/>如果返回信息为：iptables: Unknown error 4294967295 说明正常，否则需要发个ticket让VPS公司帮忙开通。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>你可以直接给客服发个Ticket告诉他你要用OpenVPN，让他开启tun/tap就行了。<br/>Can you help me enable tun/tap?<br/>I want to run openvpn, need tun/tap support.<br/>不一会客服就回复说：<br/>This has been added to your container. Have a good day.<br/></div></div><br/><br/><br/>环境准备好之后，我们正式开始安装OpenVPN了。网上的教程绝大多数都是用源代码编译方式安装的，但我觉得这种方式不便于以后升级维护，这里我们使用yum来安装。<br/><br/>默认情况下centos的yum源没有OpenVPN的，先安装EPEL这个东西，使用命令：<br/><div class="code">rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm</div><br/><br/>成功后yum源里面就有OpenVPN了，直接使用命令：<br/><div class="code">yum -y install openvpn</div><br/><br/>这里就体现了yum安装的好处，比如OpenVPN需要lzo支持，安装的时候会检测系统，没有的组件会自动安装进去。<br/><br/>我们来找一下安装到哪去了，使用命令：locate easy-rsa<br/><br/>找出来了原来在这里：/usr/share/openvpn/easy-rsa 大家应该都是一样的。<br/><br/>我们把easy-rsa这个文件夹移出来，用命令：<br/><div class="code">cp -R /usr/share/openvpn/easy-rsa /etc/openvpn/</div><br/>然后<br/><div class="code">cd /etc/openvpn/easy-rsa/2.0</div><br/><br/>进入，生成OpenVPN需要的证书。用<br/><div class="code">vi vars</div><br/>来编辑环境变量，这里涉及到编辑器vi的用法，不会用就自己google一下。<br/><br/>把最后几行根据实际情况修改：<br/><div class="code"><br/>export KEY_COUNTRY=&quot;CN&quot;<br/>export KEY_PROVINCE=&quot;GD&quot;<br/>export KEY_CITY=&quot;GZ&quot;<br/>export KEY_ORG=&quot;TELENAMEORG&quot;<br/>export KEY_EMAIL=&quot;webmaster@domains.com&quot;<br/></div><br/><br/>保存后运行：<br/><div class="code"><br/>. vars<br/>./clean-all<br/></div><br/><br/>接下来运行<br/><div class="code">./build-ca server</div><br/>创建证书颁发机构。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>Generating a 1024 bit RSA private key<br/>........................++++++<br/>....++++++<br/>writing new private key to 'ca.key'<br/>-----<br/>You are about to be asked to enter information that will be incorporated<br/>into your certificate request.<br/>What you are about to enter is what is called a Distinguished Name or a DN.<br/>There are quite a few fields but you can leave some blank<br/>For some fields there will be a default value,<br/>If you enter '.', the field will be left blank.<br/>-----<br/>Country Name (2 letter code) [CN]:回车<br/>State or Province Name (full name) [GD]:回车<br/>Locality Name (eg, city) [GZ]:回车<br/>Organization Name (eg, company) [Black-Xstar Net Empire]:回车<br/>Organizational Unit Name (eg, section) []:回车<br/>Common Name (eg, your name or your server's hostname) [Black-Xstar Net Empire CA]:回车<br/>Name []:回车<br/>Email Address [webmaster@black-xstar.com]:回车<br/></div></div><br/><br/>创建CA之后来生成服务器证书，输入<br/><div class="code">./build-key-server server</div><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>&nbsp;&nbsp;&nbsp;&nbsp;Generating a 1024 bit RSA private key<br/>&nbsp;&nbsp;&nbsp;&nbsp;...++++++<br/>&nbsp;&nbsp;&nbsp;&nbsp;...............++++++<br/>&nbsp;&nbsp;&nbsp;&nbsp;writing new private key to 'server.key'<br/>&nbsp;&nbsp;&nbsp;&nbsp;-----<br/>&nbsp;&nbsp;&nbsp;&nbsp;You are about to be asked to enter information that will be incorporated<br/>&nbsp;&nbsp;&nbsp;&nbsp;into your certificate request.<br/>&nbsp;&nbsp;&nbsp;&nbsp;What you are about to enter is what is called a Distinguished Name or a DN.<br/>&nbsp;&nbsp;&nbsp;&nbsp;There are quite a few fields but you can leave some blank<br/>&nbsp;&nbsp;&nbsp;&nbsp;For some fields there will be a default value,<br/>&nbsp;&nbsp;&nbsp;&nbsp;If you enter '.', the field will be left blank.<br/>&nbsp;&nbsp;&nbsp;&nbsp;-----<br/>&nbsp;&nbsp;&nbsp;&nbsp;Country Name (2 letter code) [CN]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;State or Province Name (full name) [GD]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Locality Name (eg, city) [GZ]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Organization Name (eg, company) [Black-Xstar Net Empire]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Organizational Unit Name (eg, section) []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Common Name (eg, your name or your server's hostname) [server]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Name []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Email Address [webmaster@black-xstar.com]:回车<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter the following 'extra' attributes<br/>&nbsp;&nbsp;&nbsp;&nbsp;to be sent with your certificate request<br/>&nbsp;&nbsp;&nbsp;&nbsp;A challenge password []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;An optional company name []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf<br/>&nbsp;&nbsp;&nbsp;&nbsp;Check that the request matches the signature<br/>&nbsp;&nbsp;&nbsp;&nbsp;Signature ok<br/>&nbsp;&nbsp;&nbsp;&nbsp;The Subject's Distinguished Name is as follows<br/>&nbsp;&nbsp;&nbsp;&nbsp;countryName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :P RINTABLE:'CN'<br/>&nbsp;&nbsp;&nbsp;&nbsp;stateOrProvinceName&nbsp;&nbsp; :P RINTABLE:'GD'<br/>&nbsp;&nbsp;&nbsp;&nbsp;localityName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'GZ'<br/>&nbsp;&nbsp;&nbsp;&nbsp;organizationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'Black-Xstar Net Empire'<br/>&nbsp;&nbsp;&nbsp;&nbsp;commonName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'server'<br/>&nbsp;&nbsp;&nbsp;&nbsp;emailAddress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:IA5STRING:'webmaster@black-xstar.com'<br/>&nbsp;&nbsp;&nbsp;&nbsp;Certificate is to be certified until Nov 18 17:25:15 2019 GMT (3650 days)<br/>&nbsp;&nbsp;&nbsp;&nbsp;Sign the certificate? [y/n]:y<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;1 out of 1 certificate requests certified, commit? [y/n]y<br/>&nbsp;&nbsp;&nbsp;&nbsp;Write out database with 1 new entries<br/>&nbsp;&nbsp;&nbsp;&nbsp;Data Base Updated<br/></div></div><br/>服务器证书生成完了，我们来生成客户端证书，理论上每个OpenVPN用户都有独立的证书，我们先来生成一个试试。<br/><br/>输入命令：<br/><div class="code">./build-key client1</div><br/>这里的client1是客户端名称，如果第二个就是client2了。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>&nbsp;&nbsp;&nbsp;&nbsp;Generating a 1024 bit RSA private key<br/>&nbsp;&nbsp;&nbsp;&nbsp;.......++++++<br/>&nbsp;&nbsp;&nbsp;&nbsp;.........++++++<br/>&nbsp;&nbsp;&nbsp;&nbsp;writing new private key to 'client1.key'<br/>&nbsp;&nbsp;&nbsp;&nbsp;-----<br/>&nbsp;&nbsp;&nbsp;&nbsp;You are about to be asked to enter information that will be incorporated<br/>&nbsp;&nbsp;&nbsp;&nbsp;into your certificate request.<br/>&nbsp;&nbsp;&nbsp;&nbsp;What you are about to enter is what is called a Distinguished Name or a DN.<br/>&nbsp;&nbsp;&nbsp;&nbsp;There are quite a few fields but you can leave some blank<br/>&nbsp;&nbsp;&nbsp;&nbsp;For some fields there will be a default value,<br/>&nbsp;&nbsp;&nbsp;&nbsp;If you enter '.', the field will be left blank.<br/>&nbsp;&nbsp;&nbsp;&nbsp;-----<br/>&nbsp;&nbsp;&nbsp;&nbsp;Country Name (2 letter code) [CN]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;State or Province Name (full name) [GD]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Locality Name (eg, city) [GZ]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Organization Name (eg, company) [Black-Xstar Net Empire]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Organizational Unit Name (eg, section) []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Common Name (eg, your name or your server's hostname) [client1]:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Name []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Email Address [webmaster@black-xstar.com]:回车<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter the following 'extra' attributes<br/>&nbsp;&nbsp;&nbsp;&nbsp;to be sent with your certificate request<br/>&nbsp;&nbsp;&nbsp;&nbsp;A challenge password []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;An optional company name []:回车<br/>&nbsp;&nbsp;&nbsp;&nbsp;Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf<br/>&nbsp;&nbsp;&nbsp;&nbsp;Check that the request matches the signature<br/>&nbsp;&nbsp;&nbsp;&nbsp;Signature ok<br/>&nbsp;&nbsp;&nbsp;&nbsp;The Subject's Distinguished Name is as follows<br/>&nbsp;&nbsp;&nbsp;&nbsp;countryName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :P RINTABLE:'CN'<br/>&nbsp;&nbsp;&nbsp;&nbsp;stateOrProvinceName&nbsp;&nbsp; :P RINTABLE:'GD'<br/>&nbsp;&nbsp;&nbsp;&nbsp;localityName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'GZ'<br/>&nbsp;&nbsp;&nbsp;&nbsp;organizationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'Black-Xstar Net Empire'<br/>&nbsp;&nbsp;&nbsp;&nbsp;commonName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:P RINTABLE:'client1'<br/>&nbsp;&nbsp;&nbsp;&nbsp;emailAddress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:IA5STRING:'webmaster@black-xstar.com'<br/>&nbsp;&nbsp;&nbsp;&nbsp;Certificate is to be certified until Nov 18 17:31:21 2019 GMT (3650 days)<br/>&nbsp;&nbsp;&nbsp;&nbsp;Sign the certificate? [y/n]:y<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;1 out of 1 certificate requests certified, commit? [y/n]y<br/>&nbsp;&nbsp;&nbsp;&nbsp;Write out database with 1 new entries<br/>&nbsp;&nbsp;&nbsp;&nbsp;Data Base Updated<br/></div></div><br/><br/>最后生成Diffie Hellman参数：<br/><div class="code">./build-dh</div><br/>这个需要一点时间的。<br/><br/>接下来我们开始配置OpenVPN了，我的配置文件只是一个参考，可以根据实际情况修改。<br/><br/>首先<br/><div class="code">cd ../..</div><br/>回到上一级目录，然后vi server.conf新建一个配置文件，输入下面内容：<br/><div class="code"><br/>port 1194<br/>proto tcp <br/>dev tun <br/>ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt <br/>cert /etc/openvpn/easy-rsa/2.0/keys/server.crt <br/>key /etc/openvpn/easy-rsa/2.0/keys/server.key <br/>dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem <br/>server 10.8.0.0 255.255.255.0 <br/>push &quot;redirect-gateway def1&quot; <br/>push &quot;dhcp-option DNS 208.67.222.222&quot; <br/>push &quot;dhcp-option DNS 208.67.220.220&quot; <br/>client-to-client <br/>keepalive 10 120 <br/>comp-lzo <br/>persist-key <br/>persist-tun <br/>verb 3<br/></div><br/>其中DNS服务器地址可以换成主机商的，也可以和我一样用opendns。<br/>到这里为止OpenVPN就配置好了，接下来我们设置外网访问。<br/><br/>输入<br/><div class="code">vi /etc/sysctl.conf</div><br/>开始编辑，找到<br/><div class="code">net.ipv4.ip_forward = 0</div><br/>改成<br/><div class="code">net.ipv4.ip_forward = 1</div><br/>保存。然后执行<br/><div class="code">sysctl -p</div><br/>输入<br/><div class="code">iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 1.2.3.4</div><br/>添加规则，注意最后1.2.3.4改成你的VPS的IP地址。<br/><br/>完成后用<br/><div class="code">/etc/init.d/iptables save</div><br/>保存iptables设置，然后<br/><div class="code">/etc/init.d/iptables restart</div><br/>重新启动下。<br/>把OpenVPN添加到开机启动，用<br/><div class="code">vi /etc/rc.local</div><br/>进入编辑，在后面加入<br/><div class="code">/usr/sbin/openvpn --config /etc/openvpn/server.conf &amp;</div><br/><br/>需要在服务器上完成的操作到这里就结束了，输入<br/><div class="code">openvpn --config /etc/openvpn/server.conf &amp;</div><br/>启动。<br/><br/>和PPTP不一样，OpenVPN需要安装客户端才行，在http://www.openvpn.net/index.php/open-source/downloads.html下载最新版本的Windows Installer安装。<br/><br/>然后在下载回来keys文件夹里面找到ca.crt、client1.crt和client1.key这三个文件，放到C:&#92;Program Files&#92;OpenVPN&#92;config里面。<br/><br/>同时在这里面新建一个名字为“client1.ovpn”的文本文件，输入下面内容：<br/><div class="code"><br/>client<br/>dev tun<br/>proto tcp<br/><br/># The hostname/IP and port of the server.<br/># CHANGE THIS TO YOUR VPS IP ADDRESS<br/>remote 208.110.73.134 1194<br/><br/>resolv-retry infinite<br/>nobind<br/><br/>persist-key<br/>persist-tun<br/><br/>ca ca.crt<br/>cert client1.crt<br/>key client1.key<br/><br/>comp-lzo<br/>verb 3<br/></div><br/>把208.110.73.134改成VPS的IP地址<br/><br/>在开始菜单里面找到OpenVPN GUI并运行，Vista和Win7下需要管理员身份运行。点Connect后等一下，是不是成功连上去了？！<br/><br/>成功连接后，右下角的OpenVPN GUI图标会由红色变为绿色。
]]>
</description>
</item><item>
<link>//gm.angeldm.com/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] OpenVZ下安装OpenVPN]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>//gm.angeldm.com/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>