- Newest
- Most votes
- Most comments
Using ping to check whether port 22 is open on a virtual machine is not appropriate, because:
-
pingdoes not check ports:pinguses the ICMP protocol, not TCP/UDP, and does not interact with any specific port like port 22.- A machine may respond to ICMP Echo Requests (ping), but port 22 (or other ports) could still be closed.
-
ICMP can be blocked:
- If a firewall blocks ICMP traffic, you won't get a response to
ping, but that doesn't mean port 22 is closed.
- If a firewall blocks ICMP traffic, you won't get a response to
More Effective Solutions:
To check whether port 22 (SSH) is open, use tools that work directly with TCP/UDP protocols, such as:
-
telnet:telnet <virtual machine IP> 22- If the connection succeeds, port 22 is open.
- If it fails, port 22 may be closed or blocked.
-
nc(Netcat):nc -zv <virtual machine IP> 22- The
-zoption checks the port without sending data, and-vdisplays verbose output.
- The
-
nmap:nmap -p 22 <virtual machine IP>- This tool can determine the port's status (open/closed/filtered) and whether it is blocked by a firewall.
answered 2 years ago
Based on the information provided, it appears that you're experiencing a connection issue specifically with RHEL 8 instances created from custom AMIs. Since you've already verified many common network and security configurations, the problem likely lies within the instance itself. Here are some potential causes and solutions to consider:
-
SSH service not running: When creating an AMI, sometimes the SSH service may not start automatically on the new instance. You can try to start the SSH service manually by accessing the instance through the EC2 console's "Get System Log" feature or by using EC2 Instance Connect (if available).
-
Firewall settings: RHEL 8 uses firewalld by default, which might be blocking incoming SSH connections. The firewall configuration from the source instance may have carried over to the new instance. You may need to adjust the firewall rules to allow SSH traffic.
-
SELinux: If SELinux is enabled and configured incorrectly, it could prevent SSH connections. You might need to check and adjust SELinux settings.
-
SSH configuration: The sshd_config file might have settings that are preventing connections. Check if there are any restrictive configurations in this file.
-
Network interface configuration: Ensure that the network interface is properly configured and that the IP address is correctly assigned to the instance.
-
Instance metadata: Make sure the instance can access the EC2 instance metadata service, as this is crucial for proper functioning of many AWS services.
To troubleshoot these issues, you may need to use EC2 Instance Connect (if available for your RHEL 8 AMI) or attach the root volume to another instance to investigate and fix the configuration.
If none of these solutions work, you might want to consider creating a new AMI from your RHEL 8 instance after ensuring that SSH is properly configured and all necessary services are running. This new AMI should then allow SSH connections when launching new instances.
Remember to also check the EC2 instance's system log for any error messages or indications of what might be preventing the SSH service from starting or accepting connections.
Sources
Tutorial: Complete the configuration required to connect to your instance using EC2 Instance Connect - Amazon Elastic Compute Cloud
Connect to an Amazon EC2 instance using EC2 Instance Connect Endpoint - Amazon Elastic Compute Cloud
Troubleshoot issues connecting to your Amazon EC2 Linux instance - Amazon Elastic Compute Cloud
AWSSupport-TroubleshootEC2InstanceConnect - AWS Systems Manager Automation runbook reference
answered 2 years ago
Hi,
The right way to do that initially to use Instance Connect to connect to your instance from the AWS console: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html
In case you've problems with Instance Connect, this KC article will help you: https://repost.aws/knowledge-center/ec2-instance-connect-troubleshooting
When you get the IC use case to work, it will be easy to switch to regular ssh from your laptop.
Best,
Didier
Relevant content
asked 6 years ago
asked 3 years ago

Based on your given output, I assume that you are ping to
10.0.0.250.If you are doing that, please change to use public IP instead
Hello, thank you for your contribution, I had already approved the telnet command, and testing the nc and nmap commands, I receive the same confirmation, port 22 is closed.
Ncat: Version 7.92 ( https://nmap.org/ncat ) Ncat: Connection refused.
Starting Nmap 7.92 ( https://nmap.org ) at 2024-12-10 02:08 UTC Nmap scan report for ip-10-0-0-250.us-west-1.compute.internal (10.0.0.250) Host is up (0.0015s latency).
PORT STATE SERVICE 22/tcp closed ssh
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
Thank you very much in advance
I have also performed the tests with the public IP
Starting Nmap 7.92 ( https://nmap.org ) at 2024-12-10 02:12 UTC Nmap scan report for ec2-3-101-154-123.us-west-1.compute.amazonaws.com (3.101.154.123) Host is up (0.00066s latency).
PORT STATE SERVICE 22/tcp closed ssh
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
[ec2-user@ip-10-0-0-55 ~]$ nc -zv 3.101.154.123 22 Ncat: Version 7.92 ( https://nmap.org/ncat ) Ncat: Connection refused.
thank you