静态 IP 导致“无主机路由”。可以 ping 通

静态 IP 导致“无主机路由”。可以 ping 通

我刚刚从 DigitalOcean 配置了一台新服务器。除了将 ssh 端口从 22 更改为 2202 之外,我认为我没有更改服务器网络配置的任何内容,但突然间我无法通过 ssh 进入服务器。我最初能够通过 ssh 在端口 2202 上登录几次

请让我知道是否有更好的 StackExchange 来回答这个问题

$ ssh -p 2202 [email protected]     
ssh: connect to host 159.89.x.x port 2202: No route to host

我可以 ping 通服务器

$ ping 159.89.x.x    
PING 159.89.x.x (159.89.x.x) 56(84) bytes of data.
64 bytes from 159.89.x.x: icmp_seq=1 ttl=56 time=30.0 ms
64 bytes from 159.89.x.x: icmp_seq=2 ttl=56 time=29.7 ms
64 bytes from 159.89.x.x: icmp_seq=3 ttl=56 time=29.9 ms

--- 159.89.x.x ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 29.756/29.932/30.083/0.134 ms

我关闭了除以太网连接之外的所有网络配置

$ ifconfig 

eth0      Link encap:Ethernet  HWaddr 90:2b:34:d6:e1:d5  
          inet addr:192.168.0.8  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::737e:c4b0:f37c:ab45/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7449 errors:0 dropped:0 overruns:0 frame:0
          TX packets:139088 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6762469 (6.7 MB)  TX bytes:9333612 (9.3 MB)
          Interrupt:18 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1180 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1180 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:109431 (109.4 KB)  TX bytes:109431 (109.4 KB)

这是跟踪路由

$ traceroute 159.89.x.x
traceroute to 159.89.x.x (159.89.x.x), 30 hops max, 60 byte packets
 1  192.168.0.1 (192.168.0.1)  0.455 ms  0.613 ms  0.802 ms
 2  hlrn-dsl-gw09.hlrn.qwest.net (207.225.x.x)  3.641 ms  3.833 ms  4.532 ms
 3  hlrn-agw1.inet.qwest.net (71.217.x.x)  4.763 ms  4.733 ms  4.734 ms
 4  dvr3-brdr-01.inet.qwest.net (208.168.x.x)  4.911 ms  5.347 ms  5.131 ms
 5  den-b1-link.telia.net (213.248.93.94)  5.336 ms  5.327 ms  5.764 ms
 6  sjo-b21-link.telia.net (213.155.133.171)  33.313 ms  29.887 ms  29.980 ms
 7  digitalocean-ic-318773-sjo-b21.c.telia.net (62.115.149.7)  29.570 ms digitalocean-ic-306499-sjo-b21.c.telia.net (62.115.45.22)  30.931 ms  30.938 ms
 8  159.89.x.x (159.89.x.x)  29.617 ms !X  29.838 ms !X  29.614 ms !X

内容如下nmap(我不太熟悉如何有效地使用 nmap)

$ nmap 159.89.x.x

Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-20 09:34 MDT
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.08 seconds

$ nmap -Pn 159.89.x.x

Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-20 09:35 MDT
Nmap scan report for 159.89.x.x
Host is up (0.59s latency).
Not shown: 999 filtered ports
PORT   STATE  SERVICE
22/tcp closed ssh

$ nmap -Pn 159.89.x.x -p 2202  

Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-20 12:56 MDT
Nmap scan report for 159.89.x.x
Host is up (0.036s latency).
PORT     STATE    SERVICE
2202/tcp filtered unknown

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

从 DigitalOcean 控制台(目前访问该机器的唯一方式),我能够 ping 通,8.8.8.8并且curl -vL google.com成功

同样从 DO 控制台,

(myserver)$ ip route

default via 159.89.128.1 dev eth0
10.46.0.0/16 dev eth0 proto kernel scope link src 10.46.0.5
159.89.128.0/20 dev eth0 proto kernel scope link src 159.89.x.x

由于我无法从 DO 控制台复制/粘贴,因此这里有一张sudo iptables -nvL INPUT

<code>sudo iptables -nvL INPUT</code> 的输出

答案1

您忘记在防火墙中打开端口。您需要这样做,例如,因为您正在使用firewalld:

firewall-cmd --add-port=2202/tcp

一旦它开始工作,使其永久化

答案2

听起来你可能有一个iptables冲突阻止端口2202。尝试此过程作为测试,看看你是否可以重新获得访问权限:

iptables-save > ~/iptables.save
iptables -F

然后重新尝试在端口 上使用 SSH 2202。如果成功,则需要调整防火墙规则;如果失败,请确保与 Digital Ocean 防火墙没有冲突。

要恢复规则,请运行以下命令:

iptables-restore < ~/iptables.save

相关内容