我正在设置 OpenVPN 访问服务器,但我的客户端上不断收到“连接被拒绝”错误。所以我决定从头开始调试(服务器)并尝试telnet 127.0.0.1 2194
。结果:
openvpn_as_test_1:~$ telnet 127.0.0.1 2194
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
所以这意味着问题出在服务器上,所以我检查了端口是否打开ufw
,sudo ufw status
并注意到防火墙不允许该端口。添加端口后ufw allow 2194/udp
(ufw allow 2194/tcp
甚至在需要时)。再次检查后ufw status
,结果是这样的:
Status: active
To Action From
-- ------ ----
2194/udp ALLOW Anywhere
2194/tcp ALLOW Anywhere
22 ALLOW Anywhere
2194/udp (v6) ALLOW Anywhere (v6)
2194/tcp (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)
该端口是内部防火墙允许的,所以我telnet 127.0.0.1 2194
再次尝试,猜猜看,仍然是connection refused
:
openvpn_as_test_1:~$ telnet 127.0.0.1 2194
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
好吧,还有什么问题吗?也许 telnet 无法正常工作,所以我尝试了telnet 127.0.0.1 22
:
openvpn_as_test_1:~$ telnet 127.0.0.1 22
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
太好了,telnet 工作正常,所以..让我们检查 netstat 看看我们是否监听端口 2194:
openvpn_as_test_1:~$ netstat -al | grep "LISTEN"
tcp 0 0 0.0.0.0:943 0.0.0.0:* LISTEN
tcp 0 0 localhost:domain 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN
tcp 0 0 localhost:904 0.0.0.0:* LISTEN
tcp 0 0 localhost:905 0.0.0.0:* LISTEN
tcp 0 0 localhost:906 0.0.0.0:* LISTEN
tcp 0 0 localhost:907 0.0.0.0:* LISTEN
tcp 0 0 localhost:908 0.0.0.0:* LISTEN
tcp 0 0 localhost:909 0.0.0.0:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
unix 2 [ ACC ] SEQPACKET LISTENING 13660 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 22260 /run/user/1000/systemd/private
unix 2 [ ACC ] STREAM LISTENING 22264 /run/user/1000/gnupg/S.gpg-agent.ssh
unix 2 [ ACC ] STREAM LISTENING 22265 /run/user/1000/snapd-session-agent.socket
unix 2 [ ACC ] STREAM LISTENING 22266 /run/user/1000/gnupg/S.dirmngr
unix 2 [ ACC ] STREAM LISTENING 22267 /run/user/1000/gnupg/S.gpg-agent.extra
unix 2 [ ACC ] STREAM LISTENING 22268 /run/user/1000/gnupg/S.gpg-agent.browser
unix 2 [ ACC ] STREAM LISTENING 22269 /run/user/1000/gnupg/S.gpg-agent
unix 2 [ ACC ] STREAM LISTENING 13568 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 13578 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 16810 /run/uuidd/request
unix 2 [ ACC ] STREAM LISTENING 16816 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 16828 /run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 16830 /run/snapd.socket
unix 2 [ ACC ] STREAM LISTENING 16832 /run/snapd-snap.socket
unix 2 [ ACC ] STREAM LISTENING 13662 /run/lvm/lvmpolld.socket
unix 2 [ ACC ] STREAM LISTENING 13839 /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 16861 /var/lib/lxd/unix.socket
unix 2 [ ACC ] STREAM LISTENING 20300 /usr/local/openvpn_as/etc/sock/sagent
unix 2 [ ACC ] STREAM LISTENING 20303 /usr/local/openvpn_as/etc/sock/sagent.localroot
unix 2 [ ACC ] STREAM LISTENING 20304 /usr/local/openvpn_as/etc/sock/sagent.api
unix 2 [ ACC ] STREAM LISTENING 16865 @ISCSIADM_ABSTRACT_NAMESPACE
此处未列出端口 2194。好吧,现在我不知道如何继续。我的问题出在哪里?
答案1
我认为您允许了错误的端口ufw
:您尝试使用端口 2194 进行 telnet,并且根据ufw show status
您发布的输出,您已允许端口 1194。