Tho*_*mas 3 debian openvpn systemd
我对此非常困惑,这似乎完全错误,但我不知道如何所以我将从头开始。
我使用本指南在我的 Debian 服务器上配置了 openvpn 。在我将必要的文件复制到我的 archlinux 桌面并尝试运行脚本后,我注意到连接超时:
$ openvpn server.ovpn
Thu Aug 2 18:50:29 2018 OpenVPN 2.4.6 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 24 2018
Thu Aug 2 18:50:29 2018 library versions: OpenSSL 1.1.0h 27 Mar 2018, LZO 2.10
Thu Aug 2 18:50:29 2018 TCP/UDP: Preserving recently used remote address: [AF_INET]<server-ip>:1194
Thu Aug 2 18:50:29 2018 Socket Buffers: R=[212992->212992] S=[212992->212992]
Thu Aug 2 18:50:29 2018 UDP link local: (not bound)
Thu Aug 2 18:50:29 2018 UDP link remote: [AF_INET]<server-ip>:1194
Thu Aug 2 18:50:29 2018 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
Thu Aug 2 18:51:29 2018 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Thu Aug 2 18:51:29 2018 TLS Error: TLS handshake failed
Thu Aug 2 18:51:29 2018 SIGUSR1[soft,tls-error] received, process restarting
Thu Aug 2 18:51:29 2018 Restart pause, 5 second(s)
^CThu Aug 2 18:51:32 2018 SIGINT[hard,init_instance] received, process exiting
Run Code Online (Sandbox Code Playgroud)
我认为这可能是防火墙问题,所以我决定在测试时暂时放弃我的防火墙,但没有运气(我在我的客户端和我的服务器上都这样做了):
$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 15 packets, 1056 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 8 packets, 768 bytes)
pkts bytes target prot opt in out source destination
Run Code Online (Sandbox Code Playgroud)
我决定确保我实际上是在尝试建立连接,所以我打开了wireshark并看到了这个:
1 <my-ip> <server-ip> OpenVPN 56 MessageType: P_CONTROL_HARD_RESET_CLIENT_V2
2 <server-ip> <my-ip> ICMP 84 Destination unreachable (Port unreachable)
3 <my-ip> <server-ip> OpenVPN 56 MessageType: P_CONTROL_HARD_RESET_CLIENT_V2
4 <server-ip> <my-ip> ICMP 84 Destination unreachable (Port unreachable)
15 <my-ip> <server-ip> OpenVPN 56 MessageType: P_CONTROL_HARD_RESET_CLIENT_V2
16 <server-ip> <my-ip> ICMP 84 Destination unreachable (Port unreachable)
29 <my-ip> <server-ip> OpenVPN 56 MessageType: P_CONTROL_HARD_RESET_CLIENT_V2
32 <server-ip> <my-ip> ICMP 84 Destination unreachable (Port unreachable)
51 <my-ip> <server-ip> OpenVPN 56 MessageType: P_CONTROL_HARD_RESET_CLIENT_V2
52 <server-ip> <my-ip> ICMP 84 Destination unreachable (Port unreachable)
Run Code Online (Sandbox Code Playgroud)
因为我知道没有防火墙规则阻止它,所以我去看看 open vpn 是否运行:
$ sudo lsof -i | grep -i vpn
$ sudo ps ax | grep -i vpn
19969 pts/0 S+ 0:00 grep -i vpn
Run Code Online (Sandbox Code Playgroud)
什么都不会回来。我检查了 systemd 以确保它没有崩溃:
$ systemctl status openvpn
? openvpn.service - OpenVPN service
Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2018-08-02 09:37:24 CDT; 11h ago
Process: 12769 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 12769 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/openvpn.service
Run Code Online (Sandbox Code Playgroud)
它说它退出成功,但后来我注意到,“ ExecStart=/bin/true ”。有没有搞错?我打开服务文件,看到这个:
$ cat /lib/systemd/system/openvpn.service
# This service is actually a systemd target,
# but we are using a service since targets cannot be reloaded.
[Unit]
Description=OpenVPN service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我承认,openvpn 是一个复杂的软件,我不完全理解,但如何ExecStart=/bin/true正确?我很难相信这只是一个以某种方式将其投入生产的占位符,因为有人比我现在发现的更聪明,但我只是不明白。这有什么意义,我如何让 openvpn 等待执行握手?
我承认,openvpn 是一个我不完全理解的复杂软件,但是 ExecStart=/bin/true 是如何正确的?
这实际上不是 OpenVPN 的功能,而是 systemd 的功能。在大多数带有 systemd 的系统上,OpenVPN 会附带一个模板单元和一个生成器。这允许您的系统支持多个 OpenVPN 实例,并允许 systemd 分别监视和控制每个 VPN
在 Debian 系统上,您想查看的模板单元在这里。/lib/systemd/system/openvpn@.service,生成器就在这里/lib/systemd/system-generators/openvpn-generator。
那个模板单元有一个像这样的 ExecStart 。
ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid
Run Code Online (Sandbox Code Playgroud)
例如在我的系统上,我有几个 VPN 配置正在运行
# systemctl list-units | grep openvpn
openvpn.service loaded active exited OpenVPN service
openvpn@zoredachesrv.service loaded active running OpenVPN connection to zoredachesrv
openvpn@p2p-to-valiant.service loaded active running OpenVPN connection to p2p-to-valiant
Run Code Online (Sandbox Code Playgroud)
您可以使用类似的命令查询单个 openvpn 实例systemctl status openvpn@zoredachesrv.service。
如果你刚刚添加了这个配置,你可能需要使用systemctl daemon-reloadsystemd 来识别新的单位。
如果您的配置字面上命名为“server.conf”并且没有被混淆,那么您将使用 systemctl status openvpn@server.service
至于解决您的问题,我建议您检查一下 openvpn 是否正在运行并且是否有一个套接字 open lsof -ni | grep openvpn。然后还要检查 OpenVPN 向您的系统日志报告了哪些错误或任何内容grep openvpn /var/log/syslog | tail -50。这两件事之一应该会给你一个关于正在发生的事情的提示。
| 归档时间: |
|
| 查看次数: |
1190 次 |
| 最近记录: |