
我正在嘗試在伺服器上設定 OpenVPN,但無法使其正常工作。我更改了預設連接埠(主要是為了繞過可能的 VPN 封鎖),但無法連接到伺服器。
openvpnas@ip-xxx-xx-xx-xx:~$ sudo netstat -uapn | grep openvpn
udp 0 0 0.0.0.0:1190 0.0.0.0:* 1455/openvpn-openss
另一個輸出
openvpnas@ip-xxx-xx-xx-xx:~$ netstat -atnp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:904 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:905 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:906 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:907 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:908 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:909 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:943 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 172.31.42.30:22 xx.xx.xxx.xx:52882 ESTABLISHED -
tcp 0 0 127.0.0.1:42390 127.0.0.1:908 TIME_WAIT -
tcp 0 150 xxx.xx.xx.xx:34884 xxx.xxx.xx.xx:443 ESTABLISHED -
tcp6 0 0 :::22 :::* LISTEN -
在我的本機電腦上,連線逾時。
(base) ➜ dir nc -v x.xx.xx.xx 1190
nc: connect to x.xx.xx.xx port 1190 (tcp) failed: Connection timed out
為了解決這個問題,我嘗試執行以下命令但無濟於事:
sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1190 -j ACCEPT
當連接 Linux 上的 OpenVPN 用戶端時,我得到以下資訊:
2022-06-13 17:49:00 WARNING: --ns-cert-type is DEPRECATED. Use --remote-cert-tls instead.
2022-06-13 17:49:00 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
2022-06-13 17:49:00 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
2022-06-13 17:49:00 TCP/UDP: Preserving recently used remote address: [AF_INET]x.xx.xx.xx:1190
2022-06-13 17:49:00 Socket Buffers: R=[212992->212992] S=[212992->212992]
2022-06-13 17:49:00 UDP link local: (not bound)
2022-06-13 17:49:00 UDP link remote: [AF_INET]x.xx.xx.xx:1190
2022-06-13 17:49:04 Server poll timeout, restarting
2022-06-13 17:49:04 SIGUSR1[soft,server_poll] received, process restarting
2022-06-13 17:49:04 WARNING: --ns-cert-type is DEPRECATED. Use --remote-cert-tls instead.
2022-06-13 17:49:04 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
2022-06-13 17:49:04 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
2022-06-13 17:49:04 TCP/UDP: Preserving recently used remote address: [AF_INET]x.xx.xx.xx:1190
2022-06-13 17:49:04 Socket Buffers: R=[212992->212992] S=[212992->212992]
2022-06-13 17:49:04 UDP link local: (not bound)
2022-06-13 17:49:04 UDP link remote: [AF_INET]x.xx.xx.xx:1190
任何有關故障排除和修復的幫助將不勝感激。
答案1
這裡有幾件事。
- 您貼文中的第一個程式碼區塊顯示 OpenVPN 偵聽 UDP。
- 第二個程式碼區塊顯示 TCP。
nc
嘗試連線到 TCP 連接埠 1190,而不是 UDP 連接埠 1190。- 您的
iptables
規則再次顯示 TCP;不是UDP。
預設情況下 OpenVPN 使用 UDP,有充分的理由。
UDP 也意味著您無法像 TCP 一樣輕鬆地檢查連線;很難區分防火牆默默地丟棄封包和服務默默地丟棄未知輸入之間的差異。
使用 OpenVPN 用戶端而不是 NC 進行測試。解決 TCP 與 UDP 的問題。