本篇文章介绍了 ROS 路由器搭建 OpenVPN 服务的操作步骤,以及客户端配置文件的构造方法。
首先需要用户利用 WinBox 客户端,完成基础配置,包含配置 IP 地址,放通防火墙端口等。

目录
签发证书
1、配置 OpenVPN 需要创建三张证书,分别是 CA 证书、服务端证书和客户端证书。
2、首先创建一张「CA 证书」,选择 System > Certificates > Certificates,创建一张新的证书,在「Name」和「Common Name」两处位置填写证书名称,并在「Key Usage」页面勾选「key cert. sign」和「crl sign」两个选项。


3、点击「Apply」保存修改,并点击「Sign」进行证书签发,在「CA CRL Host」一栏填写路由器的出口 IP 地址,完成后点击「Start」签发证书。

4、证书签发完成后,进入证书详情页面,确保「Trusted」处于勾选状态。

5、继续创建「服务端证书」,和刚才一样,在「Name」和「Common Name」两处位置填写证书名称,并在「Key Usage」页面勾选「digital signature」、「key encipherment」和「tls server」三个选项。


6、点击「Apply」保存修改,并点击「Sign」进行证书签发,在「CA」一栏选择刚才创建的 CA 证书对证书进行签名。

7、证书签发完成后,进入证书详情页面,确保「Trusted」处于勾选状态。

8、最后创建「客户端证书」,在「Name」和「Common Name」两处位置填写证书名称,并在「Key Usage」页面勾选「tls client」一个选项。


9、点击「Apply」保存修改,并点击「Sign」进行证书签发,在「CA」一栏选择刚才创建的 CA 证书对证书进行签名。

10、创建完成后,证书列表中将会有三张证书。

导出证书
1、接下来需要将 CA 证书和客户端证书导出,用于 OpenVPN 客户端的配置。
2、进入客户端证书页面,点击「Export」进行导出,导出客户端时可以设置证书密钥,用于加强安全性。

3、导出 CA 证书。

4、导出的证书可以在 Files 当中看到,通过鼠标拖拽可以将证书复制到 Windows 桌面。

配置 OpenVPN 服务
1、配置 OpenVPN 用户地址池,进入 IP > Pool,创建一个地址池。


2、进入 PPP > Profiles,创建一个 OpenVPN Profiles 来指定刚刚创建的地址池,其中「Remote Address」选择刚刚创建的地址池。

3、进入 PPP > Interface,选择顶部的「OVPN Server」,勾选「Enabled」开启服务,「Default Profile」选择刚刚创建的 Profiles 文件,「Certificate」选择服务端证书,并选择对应的认证和加密方式。


4、进入 PPP > Secrets,创建一个登陆账户。

5、完成以上配置,Router OS 端的配置已经全部完成。
配置 OpenVPN 客户端配置文件
1、电脑安装 OpenVPN 客户端,并准备一个 ovpn 配置文件,以及刚才导出的证书。

2、对扩展名为 ovpn 的配置文件进行编辑。
client
dev tun
proto tcp
remote 192.168.100.1 1194 /* 将 IP 地址替换为路由器的公网地址 */
route 192.168.10.0 255.255.255.0 /* 添加一条静态路由 */
nobind
persist-key
persist-tun
tls-client
remote-cert-tls server
verb 4
mute 10
cipher AES-256-CBC
auth SHA1
auth-user-pass
auth-nocache
redirect-gateway /* 重定向客户端的网关,不需要可删除 */
route-nopull /* 默认从本地进行流量转发 */
<ca>
/* 此处粘贴 CA 证书文件内容 */
</ca>
<cert>
/* 此处粘贴客户端证书文件内容 */
</cert>
<key>
/* 此处粘贴客户端密钥文件内容 */
</key>
3、完成后将配置文件导入到 OpenVPN 客户端,进行连接测试。
ROS 路由器搭建 OpenVPN 服务
https://blog.kobin.cn/blog/network/n1/1087.html
评论列表(5条)
你好,有个异常请兄弟看看。我有个hex s作为客户端配置为:
name=”ovpn-out1″ mac-address=x max-mtu=1500
connect-to=x port=11196 mode=ip user=”x”
password=”x” profile=default
certificate=Client.crt_0 verify-server-certificate=no
auth=sha1 cipher=aes256 use-peer-dns=no
add-default-route=no
可以正常连接服务端配置为:
enabled: yes
port: 11196
mode: ip
protocol: tcp
netmask: 24
mac-address: FE:A5:0B:A6:25:4F
max-mtu: 1500
keepalive-timeout: 60
default-profile: ovpnProfile
certificate: ovpnServer
require-client-certificate: yes
tls-version: any
auth: sha1
cipher: aes256
可是win11端2.6版本客户端导入配置的ovpn文件就是连接不上,提示TLS失败错误:
Sun Sep 3 16:26:36 2023 VERIFY EKU OK
Sun Sep 3 16:26:36 2023 VERIFY OK: depth=0, CN=ovpnServer
Sun Sep 3 16:27:35 2023 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Sun Sep 3 16:27:35 2023 TLS Error: TLS handshake failed
Sun Sep 3 16:27:35 2023 Fatal TLS error (check_tls_errors_co), restarting
Sun Sep 3 16:27:35 2023 Closing DCO interface
Sun Sep 3 16:27:35 2023 SIGUSR1[soft,tls-error] received, process restarting
。ovpn文件配置为:
client
dev tun
proto tcp-client
tls-client
remote x 11196
nobind
persist-key
persist-tun
remote-cert-tls server
verb 4
;mute 10
cipher AES-256-CBC
auth SHA1
auth-user-pass auth.cfg
auth-nocache
ca CA.crt
cert chao.crt
key chao.key
@leiyushan:可以参考下这篇文章 https://openvpn.net/faq/tls-error-tls-key-negotiation-failed-to-occur-within-60-seconds-check-your-network-connectivity/ ,首先看下 win11 能不能正常访问到服务端的 11196 端口,其次关闭下防火墙,排除下是不是防火墙规则拦截了
谢谢您,您的文章帮助到了我,按照你的教程,我成功登录并可以访问了内网,不过有个问题,访问内网后无法访问外网,转发不出去?意思是登录openvpn服务端后访问外网的ip不是openvpn服务端的外网ip,外网根本不能访部,求解!希望得到您的回复和指导。
@三好学生:外网根本不能访部=外网根本不通访问
@三好学生:可以先在 ROS 上带源 ping 外网,源地址填 VPN 的网关 IP,先确保服务端是可以正常通信的。如果服务端正常,再检查下客户端配置文件的问题,以及客户端的 DNS 解析是否正常。