aws 服务器 connect: no route to host的解决方案

在aws上通过设置好安全组后,服务器之间可以ping,但不能telnet,可能是防火墙的问题。

在 Linux 上,常见的防火墙有两种:iptables 和 firewalld。

如果收到 “dial tcp 52.194.118.92:9090: connect: no route to host” 错误消息,则表示无法连接到指定的服务器和端口。

可能会有几个原因导致此错误,例如:

服务器已关闭:如果目标服务器已关闭或不可访问,则无法连接到该服务器。请检查服务器是否正在运行,并且网络连接是否正常。

防火墙阻止了连接:如果您的系统上启用了防火墙,则可能会阻止与某些端口的连接。请确保防火墙已正确配置以允许连接到端口 9090。您可以使用以下命令检查 iptables 是否允许连接到端口 9090

sudo iptables -L INPUT -n | grep 9090

如果没有任何反回信息,说明防火墙端口未打开

iptables

sudo iptables -A INPUT -p tcp --dport 9090 -j ACCEPT
sudo service iptables save
sudo service iptables reload

firewalld

如果在运行sudo service iptables 命令时收到 "iptables: unrecognized service" 错误消息,则可能是因为您的 Linux 系统使用的防火墙管理工具不是 iptables。

在某些 Linux 发行版中,例如 CentOS 7 或 RHEL 7,使用的是 firewalld 作为默认的防火墙解决方案,而不是 iptables。如果您正在使用 firewalld,请使用以下命令列出当前的防火墙状态:
sudo firewall-cmd --state
如果输出显示防火墙正常运行,则可以使用以下命令来修改防火墙规则:

sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

猜你喜欢

转载自blog.csdn.net/majiayu000/article/details/129518487