无法通过 wan 访问 ssh(路由器拒绝授予访问权限)

无法通过 wan 访问 ssh(路由器拒绝授予访问权限)

过去我能够轻松地通过 wan 连接 ssh,但现在我无法通过 wan 连接到我的调制解调器/路由器,我有 D-link DSL-2890AL 调制解调器/路由器,我想通过 ssh 通过 wan 连接到我的 Linux 笔记本电脑,所以我设置了 ddclient,我对其进行了配置,接下来我在调制解调器中转发端口 22,但是当我尝试通过 wan 连接时,我的路由器拒绝连接,这里是 ssh 日志:

 ssh -v [email protected]
 OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
 debug1: Reading configuration data /etc/ssh/ssh_config
 debug1: /etc/ssh/ssh_config line 19: Applying options for *
 debug1: Connecting to xxxxxxxxxxxxxx.dlinkddns.com [x.xxx.xx.xxx] port 22.
 debug1: connect to address x.xx.xxx.xxx port 22: Connection timed out
 ssh: connect to host korousharian3390.dlinkddns.com port 22: Connection timed out

我使用 ssh 调试日志检查了我的外部 IP 地址并且它运行完美,我甚至通过 wan 启用 ping 请求并使用我的 ddns 地址对其进行测试并且它运行完美,我不知道我的问题是什么。

我花了很多时间解决这个问题,感谢任何建议和帮助

答案1

快速检查一下你的主机,发现它对 ping 做出了响应:

vesemir:~> ping -c 5 korousharian3390.dlinkddns.com
PING korousharian3390.dlinkddns.com (5.236.18.209) 56(84) bytes of data.
64 bytes from 5.236.18.209 (5.236.18.209): icmp_seq=3 ttl=47 time=189 ms
64 bytes from 5.236.18.209 (5.236.18.209): icmp_seq=4 ttl=47 time=157 ms
64 bytes from 5.236.18.209 (5.236.18.209): icmp_seq=5 ttl=47 time=187 ms

--- korousharian3390.dlinkddns.com ping statistics ---
5 packets transmitted, 3 received, 40% packet loss, time 4001ms
rtt min/avg/max/mdev = 157.354/178.397/189.965/14.908 ms

所以那里有东西。但是 nmap 在那里找不到任何响应的端口:

vesemir:~> nmap -Pn -p 22,80,443 korousharian3390.dlinkddns.com

Starting Nmap 6.40 ( http://nmap.org ) at 2019-07-30 18:22 CEST
Nmap scan report for korousharian3390.dlinkddns.com (5.236.18.209)
Host is up.
PORT    STATE    SERVICE
22/tcp  filtered ssh
80/tcp  filtered http
443/tcp filtered https

Nmap done: 1 IP address (1 host up) scanned in 3.02 seconds

(与更长的默认检查相同)。

发生这种情况的原因有多种:

  1. 您的路由器位于 NAT(运营商级 NAT 或 CG-NAT)后面,并且 DDNS 选择的公共 IP 地址不是您的地址,而是您的提供商地址。如果是这种情况,那么一切就结束了(除了将您自己的 VPS 设置为代理之外)。
  2. 这是路由器的旧地址,更改后未正确更新。在这种情况下,您可能必须重新启动路由器(但请将此视为一种解决方法,而不是解决方案)。
  3. 您的路由器未配置为执行到 Linux 笔记本电脑的端口转发。
  4. 您的路由器转发流量,但您的 Linux 笔记本电脑已打开防火墙,这就是您无法连接的原因。
  5. 如果您的路由器/网络上有 DHCP - 您的笔记本电脑的 IP 地址可能已更改。这很可能需要更改您的转发规则(我的建议 - 为您的笔记本电脑使用静态 IP 或 DHCP 保留)。

相关内容