好文档 - 专业文书写作范文服务资料分享网站

openvpnhowto中文版

天下 分享 时间: 加入收藏 我要投稿 点赞

-----END OpenVPN Static key V1-----

一个 OpenVPN 静态密钥包含有足够的熵值,其中512位作为加密键,512位作为身份验证的 HMAC。(An OpenVPN static key file contains enough entropy to key both a 512 bit cipher key and a 512 bit HMAC key for authentication.)

通过安全的媒介将 拷贝到另一端(peer),比如使用scp 或 ssh 中的拷贝、粘贴。

使用预共享静态密钥(Pre-Shared Static Key)的配置文件

在我们的例子中,我们使用 OpenVPN 配置文件。OpenVPN 允许由命令行或一个或多个配置文件指定参数。在命令行中由\引导的参数在配置文件中是可以忽略\的,命令行中则不行。

Set up the following configuration files:

-------------------------------------------------------------------------------- sample-config-files/

#

# Sample OpenVPN configuration file for # office using a pre-shared static key. #

# '#' or ';' may be used to delimit comments. # Use a dynamic tun device. # For Linux or non-Linux OSes, # you may want to use an explicit # unit number such as \# OpenVPN also supports virtual # ethernet \dev tun

# is our local VPN endpoint (office). # is our remote VPN endpoint (home).

ifconfig Our up script will establish routes # once the VPN is alive. up ./

# Our pre-shared static key secret

# OpenVPN uses UDP port 5000 by default. # Each OpenVPN tunnel must use # a different port number. # lport or rport can be used # to denote different ports # for local and remote.

; port 5000

# Downgrade UID and GID to

# \# for extra security. ; user nobody ; group nobody

# If you built OpenVPN with # LZO compression, uncomment # out the following line. ; comp-lzo

# Send a UDP ping to remote once # every 15 seconds to keep # stateful firewall connection # alive. Uncomment this

# out if you are using a stateful # firewall. ; ping 15

# Uncomment this section for a more reliable detection when a system # loses its connection. For example, dial-ups or laptops that # travel to other locations. ; ping 15

; ping-restart 45 ; ping-timer-rem ; persist-tun ; persist-key

# 信息细节等级

# 0 -- 除非发生致命错误,否则保持安静。

# 1 -- 非常安静,但会显示一些非致命网络错误。 # 3 -- 中等输出,通常情况下的很好选择。 # 9 -- 非常详细,用于诊断错误。 verb 3

-------------------------------------------------------------------------------- sample-config-files/

#!/bin/bash

route add -net netmask gw $5

-------------------------------------------------------------------------------- sample-config-files/

#

# Sample OpenVPN configuration file for

# home using a pre-shared static key. #

# '#' or ';' may be used to delimit comments. # Use a dynamic tun device. # For Linux or non-Linux OSes, # you may want to use an explicit # unit number such as \# OpenVPN also supports virtual # ethernet \dev tun

# Our OpenVPN peer is the office gateway. remote is our local VPN endpoint (home). # is our remote VPN endpoint (office).

ifconfig Our up script will establish routes # once the VPN is alive. up ./

# Our pre-shared static key secret

# OpenVPN uses UDP port 5000 by default. # Each OpenVPN tunnel must use # a different port number. # lport or rport can be used # to denote different ports # for local and remote. ; port 5000

# Downgrade UID and GID to

# \# for extra security. ; user nobody ; group nobody

# If you built OpenVPN with # LZO compression, uncomment # out the following line. ; comp-lzo

# Send a UDP ping to remote once # every 15 seconds to keep # stateful firewall connection # alive. Uncomment this

# out if you are using a stateful # firewall. ; ping 15

# Uncomment this section for a more reliable detection when a system

# loses its connection. For example, dial-ups or laptops that # travel to other locations. ; ping 15

; ping-restart 45 ; ping-timer-rem ; persist-tun ; persist-key

# 信息细节等级

# 0 -- 除非发生致命错误,否则保持安静。

# 1 -- 非常安静,但会显示一些非致命网络错误。 # 3 -- 中等输出,通常情况下的很好选择。 # 9 -- 非常详细,用于诊断错误。 verb 3

-------------------------------------------------------------------------------- sample-config-files/

#!/bin/bash

route add -net netmask gw $5 在 SSL/TLS mode 下启动 VPN

Home 机器端,用如下命令启动 VPN : openvpn --config

Office 端,用如下命令启动 VPN : openvpn --config

在静态密钥模式(Static Key mode)下启动 VPN Home 机器端,用如下命令启动 VPN : openvpn --config

Office 端,用如下命令启动 VPN : openvpn --config

测试 VPN

在 Home 机器上,可以通过 ping Office 主机(经过隧道)来测试 VPN: ping

在 Office 机器上,可以通过 ping Home 主机(经过隧道)来测试 VPN:

ping

如果测试失败但无输出信息,可以编辑配置文件将 信息细节等级 调为8(将产生大量细节信息用于调试)。参考FAQ 获取更多错误处理信息。 如果测试通过,可以尝试经过隧道 ping 另一端子网中的机器(网关机器除外)来测试路由。基本上 子网中的任一机器可以访问 子网中的任意机器,反之亦然。

如果工作正常,恭喜你!如果不正常,你可以查看邮件列表 OpenVPN Mailing List 有没有相似问题。如果问题依旧,可以考虑贴到 openvpn-users 列表。

Make the VPN DHCP-aware

回想一下,在我们的网络配置中,Home是使用动态 IP,地址可以任意的变化。如果你的客户端(client daemon)使用 dhcpcd ,那写一个适应IP地址任意变化的脚本也是很容易的。这个脚本或许被命名为 /etc/dhcpc/.

基本上你要作的就是将下面这一行加入脚本,其作用是向 OpenVPn daemon 发送一个SIGUSR1 或 SIGHUP 信号:

killall -HUP openvpn

当 OpenVPN 收到这个信号后会关闭连接随后再使用DHCP获取的新的IP重新与对端连接。 如果你连接的对端由于 DHCP 重置而改变IP地址,你也许会考虑使用 --float 选项。 DHCP 重置时也有可能是 SIGUSR1 起作用,相比SIGHUP 它会在OpenVPN子系统重置时提供更多的进程回收控制。--ping 和 --ping-restart 也会内在的产生SIGUSR1信号。 --persist-tun 选项实现重置时不需关闭重新打开 TUN 设备(这就为在DHCP上的隧道提供了一种无缝连接)。 --persist-remote-ip 选项实现在DHCP重置时会保留远端 IP 地址。这样就允许 OpenVPN 隧道的两端都可以为DHCP client。

--persist-key 选项实现在重启时不用重新读取密钥文件(这样就允许 OpenVPN daemon 在权限降为 --user 或 --group 时也能实现重启)。 在 动态IP 环境下使用 OpenVPN的 更多信息,可参考FAQ 。 OpenVPN 也能在如下环境使用:连接两端都为动态地址。

系统重启时自动启动 VPN

首先建立一个目录存放OpenVPN密钥和配置文件,如: /etc/openvpn.

选择使用TLS模式或静态密钥模式 ,将适当的 .conf, .up, .key, .pem, 和 .crt 文件拷入 目录/etc/openvpn. 保护你的 .key 文件:

chmod go-rwx /etc/openvpn/*.key

如果使用 Linux iptables,编辑防火墙配置文件 ,将相应的变动拷入目录 /etc/openvpn.

创建类似如下的 startup 脚本:

-------------------------------------------------------------------------------- sample-config-files/ #!/bin/bash

# A sample OpenVPN startup script # for Linux.

openvpnhowto中文版

-----ENDOpenVPNStatickeyV1-----一个OpenVPN静态密钥包含有足够的熵值,其中512位作为加密键,512位作为身份验证的HMAC。(AnOpenVPNstatickeyfilecontainsenoughentropytokeybotha512bitcipherkeyanda512bitHM
推荐度:
点击下载文档文档为doc格式
3enmq2zg7l55mbv23rb17u3cm9b9nu004pi
领取福利

微信扫码领取福利

微信扫码分享