在openwrt下面配置openvpn是非常简单的事情,当然我假定你有linux下面配置openvpn的经验。

首先,将配置文件,证书等等复制到/etc/openvpn下面。我的配置大概是这样。

client
dev tun
proto udp
remote ipaddr port
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/openwrt.crt
key /etc/openvpn/openwrt.key
ns-cert-type server
tls-auth /etc/openvpn/ta.key 1
cipher DES-EDE3-CBC
comp-lzo
verb 3
script-security 3
up /etc/openvpn/dftup
down /etc/openvpn/dftdown

注意,其中的路径必须写完整,貌似测试下来不支持相对目录。其中的up和down是指在启动和关闭时会自动执行的两个脚本。根据贝壳的测试,redirect-gateway是无效的,不知道为什么。具体的路由配置方法,会在下一章中具体介绍。

然后,你需要将这个配置启用,方法是修改/etc/config/openvpn,在其中加入以下内容。

config openvpn name
option enable 1
option config /etc/openvpn/name.conf

name是你的配置名,下面的路径和配置文件路径吻合。

然后,你可以这样启动vpn。

/etc/init.d/openvpn restart