我已经遵循指示这里(略作修改,如下所列)在 OpnSense 路由器上设置 OpenVPN,但客户端无法连接。
差异:
- 我将本地端口设置为 1179
- 我将 IPv4 隧道网络设置为 10.79.0.0/24 - 我认为这是否是任意的?
- 我被迫禁用重定向网关,因为如果没有它,“IPv4 本地网络”选项将被隐藏,并且(AFAICT)该值必须设置为我的家庭网络的 IP 范围才能允许访问到该网络无法通过 VPN 连接设备访问 - 如果没有这种访问权限,VPN 的意义何在?
- DHCP 服务器(也在 OpnSense 路由器上运行)分配给网络上设备的 IP 地址是
192.168.1.0/24
。我承认,如果使用此 CIDR 与其他私有网络的配置发生冲突,可能会出现问题,但此时我在网络上设置了太多其他设备和服务,因此重新定义 HCP 并不简单——我想在采取这一步骤之前排除所有其他错误来源。
- DHCP 服务器(也在 OpnSense 路由器上运行)分配给网络上设备的 IP 地址是
- 我启用了“DNS 服务器”(原始指南中未提及),并将值设置为私有网络上的 DNS 服务器的 IP 地址(即我的 OpnSense 路由器)。我还设置了“强制 DNS 缓存更新”。
配置
服务器
dev ovpns1
verb 1
dev-type tun
dev-node /dev/tun1
writepid /var/run/openvpn_server1.pid
script-security 3
daemon
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
proto udp
cipher AES-128-CBC
auth SHA512
up /usr/local/etc/inc/plugins.inc.d/openvpn/ovpn-linkup
down /usr/local/etc/inc/plugins.inc.d/openvpn/ovpn-linkdown
multihome
client-disconnect "/usr/local/etc/inc/plugins.inc.d/openvpn/attributes.sh server1"
tls-server
server 10.79.0.0 255.255.255.0
client-config-dir /var/etc/openvpn-csc/1
username-as-common-name
auth-user-pass-verify "/usr/local/etc/inc/plugins.inc.d/openvpn/ovpn_auth_verify user 'Local Database' 'false' 'server1'" via-env
tls-verify "/usr/local/etc/inc/plugins.inc.d/openvpn/ovpn_auth_verify tls 'OpenVPN+Cert' 1"
lport 1179
management /var/etc/openvpn/server1.sock unix
push "route 192.168.1.0 255.255.255.0"
push "dhcp-option DNS 192.168.1.1"
push "register-dns"
ca /var/etc/openvpn/server1.ca
cert /var/etc/openvpn/server1.cert
key /var/etc/openvpn/server1.key
dh /usr/local/etc/dh-parameters.4096.sample
tls-auth /var/etc/openvpn/server1.tls-auth 0
persist-remote-ip
float
topology subnet
客户
使用“客户端导出”导出
dev tun
persist-tun
persist-key
cipher AES-128-CBC
auth SHA512
client
resolv-retry infinite
remote vpn.scubbo.org 1179 udp
lport 0
verify-x509-name "C=US, ST=CA, L=Berkeley, O=Avril, [email protected], CN=OpenVPN Cert" subject
remote-cert-tls server
auth-user-pass
<ca>
-----BEGIN CERTIFICATE-----
REDACTED
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
REDACTED
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
REDACTED
-----END PRIVATE KEY-----
</key>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
REDACTED
-----END OpenVPN Static key V1-----
</tls-auth>
key-direction 1
日志文件
服务器
<27>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 91882 - [meta sequenceId="1"] event_wait : Interrupted system call (code=4)
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 91882 - [meta sequenceId="2"] /usr/local/etc/inc/plugins.inc.d/openvpn/ovpn-linkdown ovpns1 1500 1621 10.79.0.1 255.255.255.0 init
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 91882 - [meta sequenceId="3"] SIGTERM[hard,] received, process exiting
<28>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27558 - [meta sequenceId="4"] DEPRECATED OPTION: --cipher set to 'AES-128-CBC' but missing in --data-ciphers (AES-256-GCM:AES-128-GCM). Future OpenVPN version will ignore --cipher for cipher negotiations. Add 'AES-128-CBC' to --data-ciphers or change --cipher 'AES-128-CBC' to --data-ciphers-fallback 'AES-128-CBC' to silence this warning.
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27558 - [meta sequenceId="5"] OpenVPN 2.5.7 amd64-portbld-freebsd13.0 [SSL (OpenSSL)] [LZO] [LZ4] [MH/RECVDA] [AEAD] built on Jul 6 2022
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27558 - [meta sequenceId="6"] library versions: OpenSSL 1.1.1q 5 Jul 2022, LZO 2.10
<28>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="7"] NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="8"] TUN/TAP device ovpns1 exists previously, keep at program end
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="9"] TUN/TAP device /dev/tun1 opened
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="10"] /sbin/ifconfig ovpns1 10.79.0.1 10.79.0.2 mtu 1500 netmask 255.255.255.0 up
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="11"] /usr/local/etc/inc/plugins.inc.d/openvpn/ovpn-linkup ovpns1 1500 1621 10.79.0.1 255.255.255.0 init
<28>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="12"] Could not determine IPv4/IPv6 protocol. Using AF_INET6
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="13"] setsockopt(IPV6_V6ONLY=0)
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="14"] UDPv6 link local (bound): [AF_INET6][undef]:1179
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="15"] UDPv6 link remote: [AF_UNSPEC]
<29>1 2023-10-24T19:26:40-07:00 OPNsense.avril openvpn 27799 - [meta sequenceId="16"] Initialization Sequence Completed
尝试连接时没有日志消息 - 这些消息是在服务启动时记录的,之后尽管重复尝试连接,但没有记录任何其他内容。
我确实注意到Could not determine IPv4/IPv6 protocol. Using AF_INET6
了看起来就像一个错误,尽管此评论表明不是。无论如何,我添加proto udp4
到服务器配置并重新启动服务器,连接尝试仍然以相同的方式失败。
客户
[Oct 24, 2023, 19:33:47] OpenVPN core 3.6.7 mac x86_64 64-bit built on Nov 28 2022 04:35:53
⏎[Oct 24, 2023, 19:33:47] Frame=512/2048/512 mssfix-ctrl=1250
⏎[Oct 24, 2023, 19:33:47] UNUSED OPTIONS
1 [persist-tun]
2 [persist-key]
6 [resolv-retry] [infinite]
8 [lport] [0]
⏎[Oct 24, 2023, 19:33:47] EVENT: RESOLVE ⏎[Oct 24, 2023, 19:33:47] Contacting 23.93.75.229:1179 via UDP
⏎[Oct 24, 2023, 19:33:47] EVENT: WAIT ⏎[Oct 24, 2023, 19:33:47] UnixCommandAgent: transmitting bypass route to /var/run/agent_ovpnconnect.sock
{
"host" : "23.93.75.229",
"ipv6" : false,
"pid" : 87514
}
⏎[Oct 24, 2023, 19:33:47] Connecting to [vpn.scubbo.org]:1179 (23.93.75.229) via UDPv4
⏎[Oct 24, 2023, 19:33:57] EVENT: CONNECTION_TIMEOUT BYTES_OUT : 860
PACKETS_OUT : 10
CONNECTION_TIMEOUT : 1
⏎[Oct 24, 2023, 19:33:57] EVENT: DISCONNECTED ⏎[Oct 24, 2023, 19:33:59] Raw stats on disconnect:
BYTES_OUT : 860
PACKETS_OUT : 10
CONNECTION_TIMEOUT : 1
⏎[Oct 24, 2023, 19:33:59] Performance stats on disconnect:
CPU usage (microseconds): 39543785
Network bytes per CPU second: 21
Tunnel bytes per CPU second: 0
调试步骤
您的域名/IP地址正确吗?
是的:来自路由器的响应与来自客户端curl ifconfig.io
的结果相匹配。nslookup vpn.scubbo.org
您的防火墙规则设置正确吗?
我认为是这样?我按照指南中的说明操作。无论如何,OpnSense 中的“防火墙 > 日志文件 > 实时视图”筛选为“操作 = 阻止”,不会显示与连接尝试相关的结果。
答案1
要修复你的 ipv4 绑定问题: https://forums.openvpn.net/viewtopic.php?t=26953
验证它是否在本地监听:
netstat -ltnup | grep 1179
如果您看到它在本地监听,那么它实际上只指向 opensense 上的端口转发问题。publicip:1179 to 192.168.1.X:1179