EC2 VPC Instance - Ports are filtered

2019-07-03 22:35发布

I've configured my server with a default security group, which has the following Inbound rules:

| Type | Protocol | Port Range | Source |
| All TCP | TCP | 0-65535 | 0.0.0.0/0 |
| All UDP | UDP | 0-65535 | 0.0.0.0/0|

With these rules, netstat shows the following output:

netstat -atn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:1113            0.0.0.0:*               LISTEN     
tcp        0      0 10.0.1.31:2113          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:2113          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:11300           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 :::5432                 :::*                    LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::6379                 :::*                    LISTEN  

So, in theory, I should be able to connect to port 1113 with TCP from any IP Address. But this is not working, the IP address is showing as filtered, as you can see in the following output:

The only ports that seem to be OK (open and not filtered) are 22 & 80. Here's the output I get when testing them with nmap:

PORT     STATE    SERVICE
22/tcp   open     ssh
80/tcp   open     http
1113/tcp filtered ltp-deepspace
2113/tcp filtered unknown
3306/tcp filtered mysql
6379/tcp filtered unknown

I even tried adding a custom inbound rule just for my IP and Port 1113, but the result is the same.

I suspect that some firewall is blocking traffic on those PORTS in my instance, but I'm not sure how to check that.

One thing to notice, is that this instance is in a Amazon VPC. However, the network ACL for this instance has the following inbound rule, that should allow income communications from all ports:

|Rule # | Type | Protocol | Port Range | Source | Allow / Deny |
| 100 | ALL Traffic | ALL | ALL | 0.0.0.0/0 |ALLOW |

Any ideas on what could be the issue here?

Thanks a lot for your help!

3条回答
Fickle 薄情
2楼-- · 2019-07-03 23:04

[I know this is an old post, but I was bitten by the very same thing just today and came across this very question.]

When you fire up a new EC2 instance from a new AMI there seem to be conditions where the local firewall is set to filter everything except SSH. Now that might be the default on the newer AMIs, or something at work such as fail2ban or such like. The symptoms are as you describe - you have a public-facing IP address (either directly attached or via Elastic IP), you have permissive Security Groups, and all is otherwise well. An nmap from another working server (NB be careful, AWS don't like people running nmap from EC2 instances even onto your own servers) will show port 22 open but everything else filtered.

TLDR; The quick fix is probably easy in order to flush the rules:

iptables -F

Ideally, run this first to list what the offending rule is:

iptables -L

But you should have a good look at why it was being set up that way. It's possible something like firewalld is running which is going to monkey with the rules and you have the choice of configuring or disabling it. These will tell you if it's running:

firewall-cmd --status
firewall-cmd --get-services

There are other firewall services, of course.

Once you think you have it right make sure you reboot the server to ensure everything comes up right rather than reverting to a catatonic state (services speaking).

查看更多
该账号已被封号
3楼-- · 2019-07-03 23:04

I know this is old post but I think it might help someone else too . I was running RHEL 7.6 got this issue . I had to re enable the firewall and added the ports in the firewall rule . Then it worked like charm .

查看更多
乱世女痞
4楼-- · 2019-07-03 23:07

For those who are seeking for an answer. It is because there is an additional firewall in your Linux system. For example, you probably need to do this if you are using Ubuntu: sudo ufw disable.

See this link for more information.

查看更多
登录 后发表回答