This article explains how to test TCP and UDP port connectivity on a Linux ECS instance.
Test TCP port connectivity
Choose a method based on whether a listener is running on the port you want to test:
-
If a listener is already running on the port, see Method 1: Test an existing listener by using Telnet.
-
If no listener is running on the port, see Method 2: Create a temporary listener for testing.
Method 1: Test existing listeners with Telnet
-
Connect to the Linux instance.
For more information, see Log on to a Linux instance by using Workbench.
-
Run the following command to test port connectivity by using Telnet.
For example, to test port
1234on server121.11.XX.XX, runsudo telnet 121.11.XX.XX 1234.# Replace [$Host] with the IP address of the target server and [$Port] with the port number to test. sudo telnet [$Host] [$Port]If the connection succeeds, the system returns output similar to the following. A
Connected to ...message indicates success, although the exact output may vary across Linux distributions.NoteIf the port connectivity test fails, ensure that the security group of the target server allows inbound traffic on the test port. If it does not, you must add a security group rule. For more information, see Add a security group rule.
Trying 121.11.XX.XX... Connected to 121.11.XX.XX. Escape character is '^]'.
Method 2: Create a temporary listener
This method uses two instances, a server and a client, to verify port connectivity on the server.
-
Server: The instance where you create a temporary listener.
-
Client: The instance that connects to the server port to verify connectivity.
-
Connect to the Linux instance.
For more information, see Log on to a Linux instance by using Workbench.
-
On the server, run the following command to check if Python is installed and view its version.
python -V-
If a Python version is returned, Python is installed.
-
If Python is not installed, see Deploy a Python environment to install Python.
-
-
On the server, run the following command to create a temporary listener by using Python's built-in web server.
For example, to create a listener on port
1234by using Python 3.x, runsudo python3 -m http.server 1234.-
Python 2.x
# Replace [$Port] with the port number to test. sudo python -m SimpleHTTPServer [$Port] -
Python 3.x
# Replace [$Port] with the port number to test. sudo python3 -m http.server [$Port]
The system returns output similar to the following.
Serving HTTP on 0.0.0.0 port 1234 ...NoteAfter you complete the test on the client, press
Ctrl+Cto stop the process. -
-
On the client, run the following command to test connectivity to the new listener on the server by using Telnet.
For example, to test port
1234on server121.11.XX.XX, runsudo telnet 121.11.XX.XX 1234.# Replace [$Host] with the IP address of the server and [$Port] with the port number to test. sudo telnet [$Host] [$Port]If the connection succeeds, the system returns output similar to the following. A
Connected to ...message indicates success, although the exact output may vary across Linux distributions.NoteIf the port connectivity test fails, ensure that the security group of the server allows inbound traffic on the test port. If it does not, you must add a security group rule. For more information, see Add a security group rule.
Trying 121.11.XX.XX... Connected to 121.11.XX.XX. Escape character is '^]'.
Test UDP port connectivity
This method uses two instances, a server and a client, to verify port connectivity on the server.
-
Server: The instance that listens on the UDP port.
-
Client: The instance that sends data to the server port to verify connectivity.
-
Connect to the Linux instance.
For more information, see Log on to a Linux instance by using Workbench.
-
On both the server and client instances, run the following command to check whether nc (netcat) is installed.
which ncIf the system returns a response similar to the following, it indicates that the nc program is installed.
/usr/bin/ncNoteIf nc (netcat) is not installed, install it by using a package manager such as yum or apt-get, depending on your operating system. For example, run
sudo yum install -y nc. -
On the server, run the following command to start a listener on the port you want to test.
For example, to test the connectivity of port
3333, runsudo nc -uvlp 3333.# Replace [$Port] with the port number to test. sudo nc -uvlp [$Port]If the listener starts, the system returns output similar to the following.
Ncat: Version 7.92 ( https://nmap.org/ncat ) Ncat: Listening on :::3333 Ncat: Listening on 0.0.0.0:3333 -
On the client, run the following command to connect to the test port on the server.
For example, to connect to port
3333on server111.22.XX.XX, runsudo nc -u 111.22.XX.XX 3333.# Replace [$Host] with the IP address of the server and [$Port] with the port number to test. sudo nc -u [$Host] [$Port] -
After the connection is established, type a test string on the client, such as
test. If the server receives the data, the port connectivity is normal.NoteIf the port connectivity test fails, ensure that the security group of the server allows inbound traffic on the test port. If it does not, you must add a security group rule. For more information, see Add a security group rule.
[ecs-user@ixxx ~]$ sudo nc -u 1xxx 3333 test exampleThe server receives the
testandexamplemessages from the client. This confirms that connectivity on UDP port 3333 is working. Example output on the server:[ecs-user@ixxx ~]$ sudo nc -uvlp 3333 Ncat: Version 7.92 ( https://nmap.org/ncat ) Ncat: Listening on :::3333 Ncat: Listening on 0.0.0.0:3333 Ncat: Connection from 1xxx. test example