如何访问 AWS 上的端口 10,000?

Chl*_*loe -1 firewall centos amazon-web-services

如何访问 Amazon Web Services 上的端口 10000?我将端口 10,000 添加到安全组,但我仍然无法访问它。

伊格

我只能在本地访问该服务。

[root@ip-172-31-15-65 ~]# curl -I http://localhost:10000
HTTP/1.0 200 Document follows
Date: Sat, 5 Apr 2014 03:03:40 GMT
Server: MiniServ/1.680
Run Code Online (Sandbox Code Playgroud)

当我从我的外部(到 AWS)IP 尝试时,它不起作用。

$ curl -I http://54.186.222.91:10000
curl: (28) Connection timed out after 300138 milliseconds
Run Code Online (Sandbox Code Playgroud)

这是 netstat

[root@ip-172-31-15-65 ~]# sudo netstat -tunlp |grep 10000
tcp        0      0 0.0.0.0:10000               0.0.0.0:*                   LISTEN      14258/perl
udp        0      0 0.0.0.0:10000               0.0.0.0:*                               14258/perl
Run Code Online (Sandbox Code Playgroud)

这里是iptables。这是一个全新的实例。

[root@ip-172-31-15-65 ~]# sudo iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Run Code Online (Sandbox Code Playgroud)

出于某种原因,这个命令修复了它。我不明白为什么,因为第 1 行和第 3 行已经接受了所有内容。

iptables --delete INPUT 5 
Run Code Online (Sandbox Code Playgroud)

这是详细的 iptables

[root@ip-172-31-15-65 postfix]# iptables -L -nv
Chain INPUT (policy ACCEPT 3348 packets, 173K bytes)
 pkts bytes target     prot opt in     out     source               destination
89357   80M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0
  102  5883 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
   14  2248 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 50224 packets, 17M bytes)
 pkts bytes target     prot opt in     out     source               destination
Run Code Online (Sandbox Code Playgroud)

Jac*_*cob 7

危险!

请不要只是在这里关闭防火墙并认为这是一个解决方案。您走在正确的轨道上,只是您将调试步骤变成了解决方案。我们应该怎么做?

我该如何真正解决这个问题?

好吧,您是对的,您只接受 lo 界面中的所有内容。所以我们只需要在 REJECT 规则之前允许访问这个端口。以下是帮助您进行设置的示例规则。我会在下面分解它们吗?

  • iptables -I INPUT 1 -p tcp --dport 10000 -j ACCEPT
  • iptables -A INPUT -j REJECT
  • /etc/init.d/iptables save

这些命令有什么作用?

第一行告诉 iptables 在第 1 行插入规则-I 1并允许所有流向端口 10000 TCP 的流量被接受。我在本示例中使用规则一来确保它位于 REJECT 规则之前。(它也告诉 iptables 跳转-j到 ACCEPT 以允许流量)

第二行告诉 iptables 附加(在底部插入)-A以拒绝所有在其之前的规则中未明确允许的流量。这就是默认拒绝的设置方式,因为如果没有此规则,您可能不会如评论中所述那样运行防火墙。

第三行也是最后一行有 iptables 保存规则,以便它们在重新启动时保持不变。

我想启用的其他服务呢?

使用上面的第一个示例规则来允许这些。您还应该阅读 iptables 的灵活性,因为它在您可以使用规则执行的操作方面更加强大。