特殊:Badtitle/NS100:OpenVPN/zh:修订间差异
小 以内容'{{From|https://help.ubuntu.com/community/OpenVPN}} {{Languages|UbuntuHelp:OpenVPN}} === 介绍/概况 === 更新说明可以查询 [https://help.ubuntu.com/9.10/serverguide…'创建新页面 |
无编辑摘要 |
||
(未显示同一用户的2个中间版本) | |||
第7行: | 第7行: | ||
==== 什么是 VPN 桥接 ? ==== | ==== 什么是 VPN 桥接 ? ==== | ||
VPN 桥接技术允许在客户看起来好像他们是在同一局域网(LAN)的服务器系统. VPN 使用结合虚拟设备来完成这项任务 -- 一些人称之为"桥接",另一些则称之为"tap device". Tap device就像一个虚拟以太网适配器和桥接设备一样工作,还有就是虚拟集线器. 当你桥接到一个物理以太网设备和tap device时, 必不可少的是创造一个物理网络和远程客户之间的集线器. 因此,所有网络服务(LAN services)对远程客户都是可见的. | |||
=== 系统的安装与配置 === | === 系统的安装与配置 === | ||
对于 Linux 网络协议栈的理解是必不可少的. 下面这个例子是使用安装了Ubuntu Jeos 8.04的开源虚拟机(KVM)的环境下完成的 (可以很容易的在一个独立的安装了 ubuntu 服务器的电脑中完成). 在我的配置中,eth0 连接到互联网,eth1连接到局域网,将在它们之间建立桥接. . | |||
==== 服务器的安装 ==== | ==== 服务器的安装 ==== | ||
安装 OpenVPN: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get install openvpn bridge-utils | sudo apt-get install openvpn bridge-utils | ||
</nowiki></pre> | </nowiki></pre> | ||
===== 配置桥接器 ===== | ===== 配置桥接器 ===== | ||
* | * 编辑 /etc/network/interfaces | ||
当一个 Linux 服务器开启了防火墙, 文件 /etc/network/interfaces 可能是: | |||
<pre><nowiki> | <pre><nowiki> | ||
# This file describes the network interfaces available on your system | # This file describes the network interfaces available on your system | ||
第35行: | 第34行: | ||
</nowiki></pre> | </nowiki></pre> | ||
编辑它并添加一个桥接端口: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo nano /etc/network/interfaces | sudo nano /etc/network/interfaces | ||
</nowiki></pre> | </nowiki></pre> | ||
然后它看起来可能是: | |||
<pre><nowiki> | <pre><nowiki> | ||
第58行: | 第57行: | ||
down ifconfig $IFACE down | down ifconfig $IFACE down | ||
</nowiki></pre> | </nowiki></pre> | ||
* | * 如果你在一个虚拟机中运行 Linux, 你需要对桥接连接补充以下参数: | ||
<pre><nowiki> | <pre><nowiki> | ||
bridge_fd 9 ## from the libvirt docs (forward delay time) | bridge_fd 9 ## from the libvirt docs (forward delay time) | ||
第65行: | 第64行: | ||
bridge_stp off ## from the libvirt docs (spanning tree protocol) | bridge_stp off ## from the libvirt docs (spanning tree protocol) | ||
</nowiki></pre> | </nowiki></pre> | ||
* | * 重启网络: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/networking restart | sudo /etc/init.d/networking restart | ||
</nowiki></pre> | </nowiki></pre> | ||
桥接从 libvirt 文件开始减速. (我真的只认识 bridge_ports 指令和 bridge_stp 指令.请添加更多的说明.) | |||
===== 证书的认证 ===== | ===== 证书的认证 ===== | ||
* | * 服务器证书的认证. 为此我将使用我自己的证书颁发机构提供的 easy-rsa 脚本目录 /usr/share/doc/openvpn/examples/easy-rsa/ . 另一个选择是使用图形界面的 tinyca 去建立你自己的证书(CA). | ||
第 1 步: | |||
复制文件到 /etc/openvpn/easy-rsa/ | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo mkdir /etc/openvpn/easy-rsa/ | sudo mkdir /etc/openvpn/easy-rsa/ | ||
sudo cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/ | sudo cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/ | ||
</nowiki></pre> | </nowiki></pre> | ||
第 2 步: | |||
编辑 /etc/openvpn/easy-rsa/vars | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/openvpn/easy-rsa/vars | sudo vi /etc/openvpn/easy-rsa/vars | ||
</nowiki></pre> | </nowiki></pre> | ||
在选项位置使用你的新CA更改下列项: | |||
<pre><nowiki> | <pre><nowiki> | ||
export KEY_COUNTRY="US" | export KEY_COUNTRY="US" | ||
第91行: | 第90行: | ||
export KEY_EMAIL="[email protected]" | export KEY_EMAIL="[email protected]" | ||
</nowiki></pre> | </nowiki></pre> | ||
第 3 步: | |||
安装你的CA和创建第一个服务器证书 | |||
<pre><nowiki> | <pre><nowiki> | ||
第108行: | 第107行: | ||
</nowiki></pre> | </nowiki></pre> | ||
证书机构已经建立,其所需的密钥在 /etc/openvpn/ 目录中 | |||
===== 服务器的配置 ===== | ===== 服务器的配置 ===== | ||
默认为所有服务器从指定的 /etc/openvpn/ 中的 *.conf 文件开始启动. 因此, 我们只需要在 /etc/openvpn/ 中创建一个新的 server.conf 文件. | |||
首先,我们将创建一个针对openvpn服务器使用的新脚本. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/openvpn/up.sh | sudo vi /etc/openvpn/up.sh | ||
</nowiki></pre> | </nowiki></pre> | ||
新脚本需像下面这样: | |||
<pre><nowiki> | <pre><nowiki> | ||
#!this bogus line has been added so the following line will display properly! | #!this bogus line has been added so the following line will display properly! | ||
第126行: | 第125行: | ||
/usr/sbin/brctl addif $BR $DEV | /usr/sbin/brctl addif $BR $DEV | ||
</nowiki></pre> | </nowiki></pre> | ||
现在,我们要建立一个 "down" 脚本. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/openvpn/down.sh | sudo vi /etc/openvpn/down.sh | ||
</nowiki></pre> | </nowiki></pre> | ||
像下面这样: | |||
<pre><nowiki> | <pre><nowiki> | ||
#!this bogus line has been added so the following line will display properly! | #!this bogus line has been added so the following line will display properly! | ||
第141行: | 第140行: | ||
/sbin/ifconfig $DEV down | /sbin/ifconfig $DEV down | ||
</nowiki></pre> | </nowiki></pre> | ||
然后,给两个脚本加上执行权限. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo chmod +x /etc/openvpn/up.sh /etc/openvpn/down.sh | sudo chmod +x /etc/openvpn/up.sh /etc/openvpn/down.sh | ||
</nowiki></pre> | </nowiki></pre> | ||
现在配置 openvpn. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/openvpn/server.conf | sudo vi /etc/openvpn/server.conf | ||
第191行: | 第190行: | ||
verb 3 | verb 3 | ||
</nowiki></pre> | </nowiki></pre> | ||
别忘了重新启动或运行下面的命令. 这将重新启动openvpn和加载新的配置. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/openvpn restart | sudo /etc/init.d/openvpn restart | ||
</nowiki></pre> | </nowiki></pre> | ||
==== 客户端的连接 ==== | ==== 客户端的连接 ==== | ||
这部分涉及到创建客户端证书和密钥文件并设置一个客户端配置文件. 文件将被用在客户端平台的 OpenVPN 中. 所描述的配置文件将被用在 OpenVPN 安装包 [http://openvpn.se/ OpenVPN GUI] for Windows 用户和 [http://code.google.com/p/tunnelblick/ Tunnelblick] for Mac OS X 用户. 详细的说明参考它们各自的网页.它也兼容 OpenVPN 用户. | |||
===== 生成密钥和证书 ===== | ===== 生成密钥和证书 ===== | ||
客户端的证书和服务器端的生成过程是类似的.这里假定你已建立 <code><nowiki>/etc/openvpn/easy-rsa/</nowiki></code> 目录和更新 <code><nowiki>/etc/openvpn/easy-rsa/vars</nowiki></code> 文件,像上面描述的一样. 你应该已经设置好了您的证书颁发机构,创建了一个服务器的证书和密钥. | |||
<pre><nowiki> | <pre><nowiki> | ||
cd /etc/openvpn/easy-rsa/ ## move to the easy-rsa directory | cd /etc/openvpn/easy-rsa/ ## move to the easy-rsa directory | ||
第205行: | 第204行: | ||
</nowiki></pre> | </nowiki></pre> | ||
===== 客户端的配置 ===== | ===== 客户端的配置 ===== | ||
客户端的配置是改编自 OpenVPN 2.0 样本配置文件. 对于 Windows 用户, 文件必须命名为 client.ovpn 对于其他的操作系统, 文件需命名为 client.conf. 可以用 vi 创建或者其他文本编辑器创建. | |||
假定客户端配置文件只有一个 TUN/TAP 设备被配置. | |||
<pre><nowiki> | <pre><nowiki> | ||
第249行: | 第248行: | ||
</nowiki></pre> | </nowiki></pre> | ||
把客户端的 client.ovpn (或者 client.conf) 配置文件和证书与密钥文件一起放在 openvpn 配置目录. 上面的建立后,下面的这些文件也需要放在配置目录中. | |||
<pre><nowiki> | <pre><nowiki> | ||
client.ovpn | client.ovpn | ||
第257行: | 第256行: | ||
ta.key | ta.key | ||
</nowiki></pre> | </nowiki></pre> | ||
( | (对于 [http://openvpn.se/ OpenVPN GUI] for Windows用户, 文件默认位置是 <code><nowiki>C:\Program Files\OpenVPN\config</nowiki></code>.) | ||
( | (对于 [http://code.google.com/p/tunnelblick/ Tunnelblick] for Mac OS X用户, 文件默认位置是 ''<code><nowiki>~username</nowiki></code>''<code><nowiki>/Library/openvpn</nowiki></code>. | ||
'' | '' | ||
==== 为 OpenVPN 配置 Firestarter ==== | ==== 为 OpenVPN 配置 Firestarter ==== | ||
Firestarter | Firestarter 需要在客户端和服务器端进行一些配置,来允许服务像 SAMBA 通过 VPN 信道.此外建立GUI界面时,还需要编辑 /etc/firestarter/user-pre 文件. 我用的这些说明摘自: | ||
http://www.howtoadvice.com/FirestarterVPN/ | http://www.howtoadvice.com/FirestarterVPN/ | ||
此外,虽然教程不讨论它,我认为有必要保存原始user-pre文件副本,然后由于权限的问题重命名原始文件和重命名复制文件到user-pre. | |||
=== 其他资源 === | === 其他资源 === | ||
* | * 查阅官方文件 [http://openvpn.net/howto.html OpenVPN Howto]. | ||
* | * 查阅 [http://www.juanpablo.netne.net/index.php/en/manuales-linux/red-privada-virtual-openvpn/item/58 this tutorial]. | ||
* | * 查阅 [http://ubuntuguide.org/wiki/OpenVPN_server Ubuntuguide -- OpenVPN server installation] | ||
* 英文不佳,有错误请更改,另外关于防火墙方面请参考原文. | |||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2011年9月5日 (一) 19:36的最新版本
![]() |
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/OpenVPN }} |
![]() |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/af | • {{#if: UbuntuHelp:OpenVPN|Afrikaans| [[::OpenVPN/zh/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ar | • {{#if: UbuntuHelp:OpenVPN|العربية| [[::OpenVPN/zh/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/az | • {{#if: UbuntuHelp:OpenVPN|azərbaycanca| [[::OpenVPN/zh/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/bcc | • {{#if: UbuntuHelp:OpenVPN|جهلسری بلوچی| [[::OpenVPN/zh/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/bg | • {{#if: UbuntuHelp:OpenVPN|български| [[::OpenVPN/zh/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/br | • {{#if: UbuntuHelp:OpenVPN|brezhoneg| [[::OpenVPN/zh/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ca | • {{#if: UbuntuHelp:OpenVPN|català| [[::OpenVPN/zh/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/cs | • {{#if: UbuntuHelp:OpenVPN|čeština| [[::OpenVPN/zh/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/de | • {{#if: UbuntuHelp:OpenVPN|Deutsch| [[::OpenVPN/zh/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/el | • {{#if: UbuntuHelp:OpenVPN|Ελληνικά| [[::OpenVPN/zh/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/es | • {{#if: UbuntuHelp:OpenVPN|español| [[::OpenVPN/zh/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/fa | • {{#if: UbuntuHelp:OpenVPN|فارسی| [[::OpenVPN/zh/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/fi | • {{#if: UbuntuHelp:OpenVPN|suomi| [[::OpenVPN/zh/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/fr | • {{#if: UbuntuHelp:OpenVPN|français| [[::OpenVPN/zh/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/gu | • {{#if: UbuntuHelp:OpenVPN|ગુજરાતી| [[::OpenVPN/zh/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/he | • {{#if: UbuntuHelp:OpenVPN|עברית| [[::OpenVPN/zh/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/hu | • {{#if: UbuntuHelp:OpenVPN|magyar| [[::OpenVPN/zh/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/id | • {{#if: UbuntuHelp:OpenVPN|Bahasa Indonesia| [[::OpenVPN/zh/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/it | • {{#if: UbuntuHelp:OpenVPN|italiano| [[::OpenVPN/zh/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ja | • {{#if: UbuntuHelp:OpenVPN|日本語| [[::OpenVPN/zh/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ko | • {{#if: UbuntuHelp:OpenVPN|한국어| [[::OpenVPN/zh/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ksh | • {{#if: UbuntuHelp:OpenVPN|Ripoarisch| [[::OpenVPN/zh/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/mr | • {{#if: UbuntuHelp:OpenVPN|मराठी| [[::OpenVPN/zh/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ms | • {{#if: UbuntuHelp:OpenVPN|Bahasa Melayu| [[::OpenVPN/zh/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/nl | • {{#if: UbuntuHelp:OpenVPN|Nederlands| [[::OpenVPN/zh/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/no | • {{#if: UbuntuHelp:OpenVPN|norsk| [[::OpenVPN/zh/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/oc | • {{#if: UbuntuHelp:OpenVPN|occitan| [[::OpenVPN/zh/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/pl | • {{#if: UbuntuHelp:OpenVPN|polski| [[::OpenVPN/zh/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/pt | • {{#if: UbuntuHelp:OpenVPN|português| [[::OpenVPN/zh/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ro | • {{#if: UbuntuHelp:OpenVPN|română| [[::OpenVPN/zh/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/ru | • {{#if: UbuntuHelp:OpenVPN|русский| [[::OpenVPN/zh/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/si | • {{#if: UbuntuHelp:OpenVPN|සිංහල| [[::OpenVPN/zh/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/sq | • {{#if: UbuntuHelp:OpenVPN|shqip| [[::OpenVPN/zh/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/sr | • {{#if: UbuntuHelp:OpenVPN|српски / srpski| [[::OpenVPN/zh/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/sv | • {{#if: UbuntuHelp:OpenVPN|svenska| [[::OpenVPN/zh/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/th | • {{#if: UbuntuHelp:OpenVPN|ไทย| [[::OpenVPN/zh/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/tr | • {{#if: UbuntuHelp:OpenVPN|Türkçe| [[::OpenVPN/zh/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/vi | • {{#if: UbuntuHelp:OpenVPN|Tiếng Việt| [[::OpenVPN/zh/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/yue | • {{#if: UbuntuHelp:OpenVPN|粵語| [[::OpenVPN/zh/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/zh | • {{#if: UbuntuHelp:OpenVPN|中文| [[::OpenVPN/zh/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/zh-hans | • {{#if: UbuntuHelp:OpenVPN|中文(简体)| [[::OpenVPN/zh/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:OpenVPN | UbuntuHelp:OpenVPN | {{#if: | :}}OpenVPN/zh}}/zh-hant | • {{#if: UbuntuHelp:OpenVPN|中文(繁體)| [[::OpenVPN/zh/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:OpenVPN|:OpenVPN/zh|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :OpenVPN/zh/zh | | {{#ifexist: OpenVPN/zh/zh | | {{#ifeq: {{#titleparts:OpenVPN/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:OpenVPN/zh|1|-1|}} | zh | | }}
介绍/概况
更新说明可以查询 the Ubuntu 9.10 Server guide (Karmic Koala) -- OpenVPN.
概况
OpenVPN 是由ubuntu库提供的私人虚拟网络(VPN)解决方案. 具有灵活,易用,可靠,安全的特点. 这些说明是使用x509证书建立一个VPN桥接和一般管理任务.
什么是 VPN 桥接 ?
VPN 桥接技术允许在客户看起来好像他们是在同一局域网(LAN)的服务器系统. VPN 使用结合虚拟设备来完成这项任务 -- 一些人称之为"桥接",另一些则称之为"tap device". Tap device就像一个虚拟以太网适配器和桥接设备一样工作,还有就是虚拟集线器. 当你桥接到一个物理以太网设备和tap device时, 必不可少的是创造一个物理网络和远程客户之间的集线器. 因此,所有网络服务(LAN services)对远程客户都是可见的.
系统的安装与配置
对于 Linux 网络协议栈的理解是必不可少的. 下面这个例子是使用安装了Ubuntu Jeos 8.04的开源虚拟机(KVM)的环境下完成的 (可以很容易的在一个独立的安装了 ubuntu 服务器的电脑中完成). 在我的配置中,eth0 连接到互联网,eth1连接到局域网,将在它们之间建立桥接. .
服务器的安装
安装 OpenVPN:
sudo apt-get install openvpn bridge-utils
配置桥接器
- 编辑 /etc/network/interfaces
当一个 Linux 服务器开启了防火墙, 文件 /etc/network/interfaces 可能是:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo eth0 iface lo inet loopback # The primary network interface iface eth0 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1
编辑它并添加一个桥接端口:
sudo nano /etc/network/interfaces
然后它看起来可能是:
auto lo br0 iface lo inet loopback iface br0 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1 bridge_ports eth0 iface eth0 inet manual up ifconfig $IFACE 0.0.0.0 up up ip link set $IFACE promisc on down ip link set $IFACE promisc off down ifconfig $IFACE down
- 如果你在一个虚拟机中运行 Linux, 你需要对桥接连接补充以下参数:
bridge_fd 9 ## from the libvirt docs (forward delay time) bridge_hello 2 ## from the libvirt docs (hello time) bridge_maxage 12 ## from the libvirt docs (maximum message age) bridge_stp off ## from the libvirt docs (spanning tree protocol)
- 重启网络:
sudo /etc/init.d/networking restart
桥接从 libvirt 文件开始减速. (我真的只认识 bridge_ports 指令和 bridge_stp 指令.请添加更多的说明.)
证书的认证
- 服务器证书的认证. 为此我将使用我自己的证书颁发机构提供的 easy-rsa 脚本目录 /usr/share/doc/openvpn/examples/easy-rsa/ . 另一个选择是使用图形界面的 tinyca 去建立你自己的证书(CA).
第 1 步: 复制文件到 /etc/openvpn/easy-rsa/
sudo mkdir /etc/openvpn/easy-rsa/ sudo cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
第 2 步: 编辑 /etc/openvpn/easy-rsa/vars
sudo vi /etc/openvpn/easy-rsa/vars
在选项位置使用你的新CA更改下列项:
export KEY_COUNTRY="US" export KEY_PROVINCE="CA" export KEY_CITY="SanFrancisco" export KEY_ORG="Fort-Funston" export KEY_EMAIL="[email protected]"
第 3 步: 安装你的CA和创建第一个服务器证书
cd /etc/openvpn/easy-rsa/ ## move to the easy-rsa directory sudo chown -R root:admin . ## make this directory writable by the system administrators sudo chmod g+w . ## make this directory writable by the system administrators source ./vars ## execute your new vars file ./clean-all ## Setup the easy-rsa directory (Deletes all keys) ./build-dh ## takes a while consider backgrounding ./pkitool --initca ## creates ca cert and key ./pkitool --server server ## creates a server cert and key cd keys openvpn --genkey --secret ta.key ## Build a TLS key sudo cp server.crt server.key ca.crt dh1024.pem ta.key ../../
证书机构已经建立,其所需的密钥在 /etc/openvpn/ 目录中
服务器的配置
默认为所有服务器从指定的 /etc/openvpn/ 中的 *.conf 文件开始启动. 因此, 我们只需要在 /etc/openvpn/ 中创建一个新的 server.conf 文件. 首先,我们将创建一个针对openvpn服务器使用的新脚本.
sudo vi /etc/openvpn/up.sh
新脚本需像下面这样:
#!this bogus line has been added so the following line will display properly! #!/bin/sh BR=$1 DEV=$2 MTU=$3 /sbin/ifconfig $DEV mtu $MTU promisc up /usr/sbin/brctl addif $BR $DEV
现在,我们要建立一个 "down" 脚本.
sudo vi /etc/openvpn/down.sh
像下面这样:
#!this bogus line has been added so the following line will display properly! #!/bin/sh BR=$1 DEV=$2 /usr/sbin/brctl delif $BR $DEV /sbin/ifconfig $DEV down
然后,给两个脚本加上执行权限.
sudo chmod +x /etc/openvpn/up.sh /etc/openvpn/down.sh
现在配置 openvpn.
sudo vi /etc/openvpn/server.conf
mode server tls-server local <your ip address> ## ip/hostname of server port 1194 ## default openvpn port proto udp #bridging directive dev tap0 ## If you need multiple tap devices, add them here up "/etc/openvpn/up.sh br0" down "/etc/openvpn/down.sh br0" persist-key persist-tun #certificates and encryption ca ca.crt cert server.crt key server.key # This file should be kept secret dh dh1024.pem tls-auth ta.key 0 # This file is secret cipher BF-CBC # Blowfish (default) comp-lzo #DHCP Information ifconfig-pool-persist ipp.txt server-bridge 192.168.1.10 255.255.255.0 192.168.1.100 192.168.1.110 push "dhcp-option DNS your.dns.ip.here" push "dhcp-option DOMAIN yourdomain.com" max-clients 10 ## set this to the max number of clients that should be connected at a time #log and security user nobody group nogroup keepalive 10 120 status openvpn-status.log verb 3
别忘了重新启动或运行下面的命令. 这将重新启动openvpn和加载新的配置.
sudo /etc/init.d/openvpn restart
客户端的连接
这部分涉及到创建客户端证书和密钥文件并设置一个客户端配置文件. 文件将被用在客户端平台的 OpenVPN 中. 所描述的配置文件将被用在 OpenVPN 安装包 OpenVPN GUI for Windows 用户和 Tunnelblick for Mac OS X 用户. 详细的说明参考它们各自的网页.它也兼容 OpenVPN 用户.
生成密钥和证书
客户端的证书和服务器端的生成过程是类似的.这里假定你已建立 /etc/openvpn/easy-rsa/
目录和更新 /etc/openvpn/easy-rsa/vars
文件,像上面描述的一样. 你应该已经设置好了您的证书颁发机构,创建了一个服务器的证书和密钥.
cd /etc/openvpn/easy-rsa/ ## move to the easy-rsa directory source ./vars ## execute the vars file ./pkitool client ## create a cert and key named "client"
客户端的配置
客户端的配置是改编自 OpenVPN 2.0 样本配置文件. 对于 Windows 用户, 文件必须命名为 client.ovpn 对于其他的操作系统, 文件需命名为 client.conf. 可以用 vi 创建或者其他文本编辑器创建. 假定客户端配置文件只有一个 TUN/TAP 设备被配置.
# Specify that this is a client client # Bridge device setting dev tap # Host name and port for the server (default port is 1194) # note: replace with the correct values your server set up remote your.server.example.com 1194 # Client does not need to bind to a specific local port nobind # Keep trying to resolve the host name of OpenVPN server. resolv-retry infinite # Preserve state across restarts persist-key persist-tun # SSL/TLS parameters - files created previously ca ca.crt cert client.crt key client.key # Since we specified the tls-auth for server, we need it for the client # note: 0 = server, 1 = client tls-auth ta.key 1 # Specify same cipher as server cipher BF-CBC # Use compression comp-lzo # Log verbosity (to help if there are problems) verb 3
把客户端的 client.ovpn (或者 client.conf) 配置文件和证书与密钥文件一起放在 openvpn 配置目录. 上面的建立后,下面的这些文件也需要放在配置目录中.
client.ovpn ca.crt client.crt client.key ta.key
(对于 OpenVPN GUI for Windows用户, 文件默认位置是 C:\Program Files\OpenVPN\config
.)
(对于 Tunnelblick for Mac OS X用户, 文件默认位置是 ~username
/Library/openvpn
.
为 OpenVPN 配置 Firestarter
Firestarter 需要在客户端和服务器端进行一些配置,来允许服务像 SAMBA 通过 VPN 信道.此外建立GUI界面时,还需要编辑 /etc/firestarter/user-pre 文件. 我用的这些说明摘自: http://www.howtoadvice.com/FirestarterVPN/ 此外,虽然教程不讨论它,我认为有必要保存原始user-pre文件副本,然后由于权限的问题重命名原始文件和重命名复制文件到user-pre.
其他资源
- 查阅官方文件 OpenVPN Howto.
- 查阅 this tutorial.
- 查阅 Ubuntuguide -- OpenVPN server installation
- 英文不佳,有错误请更改,另外关于防火墙方面请参考原文.