All Products
Search
Document Center

Elastic Compute Service:Test methods for TCP and UDP ports in Linux

Last Updated:Dec 24, 2025

This guide explains how to test TCP and UDP port connectivity on a Linux Elastic Compute Service (ECS) instance.

Test TCP port connectivity

Select a method based on the status of the port that you want to test:

Method 1: Test a listening port with Telnet

  1. Connect to your Linux instance.

    For more information, see Connect to a Linux instance using Workbench.

  2. Run the following command to test port connectivity.

    For example, to test port 1234 on the server at 121.11.XX.XX, run sudo 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]

    A successful connection returns output similar to the following. The exact output may vary across Linux distributions, but a message containing Connected to ... indicates success.

    Note

    If the test fails, ensure the target server's security group rules allow inbound traffic on the test port. To allow access, 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 listening port to test

This method requires two instances: a server and a client. The test verifies port connectivity on the server instance.

  • Server: The instance where a new port will listen for connections.

  • Client: The instance that connects to the server's port for testing.

  1. Connect to your Linux instance.

    For more information, see Connect to a Linux instance using Workbench.

  2. On the server instance, run the following command to check the installed Python version.

    python -V
    • If the command returns a version number, Python is installed.

    • If Python is not installed, see Deploy a Python environment to install it.

  3. On the server instance, run the following command to create a temporary listening port with Python's built-in web server.

    For example, to create a listener on port 1234 with Python 3.x, run sudo python3 -m http.server 1234.

    • Python 2

      # 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]

    Output similar to the following confirms the listener is active.

    Serving HTTP on 0.0.0.0 port 1234 ...
    Note

    After the test is complete, press Ctrl+C to stop the listening process.

  4. On the client instance, run the following command to test the server's new listening port.

    For example, to test port 1234 on the server at 121.11.XX.XX, run sudo telnet 121.11.XX.XX 1234.

    # Replace [$Host] with the server IP address and [$Port] with the port number to test.
    sudo telnet [$Host] [$Port]

    A successful connection returns output similar to the following. The exact output may vary across Linux distributions, but a message containing Connected to ... indicates success.

    Note

    If the test fails, ensure the server's security group rules allow inbound traffic on the test port. To allow access, 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 requires two instances: a server and a client. The test verifies port connectivity on the server instance.

  • Server: The instance where UDP port connectivity will be tested.

  • Client: The instance that sends data to the server's port for testing.

  1. Connect to your Linux instance.

    For more information, see Connect to a Linux instance using Workbench.

  2. On both the server and client instances, run the following command to check if the nc (or netcat) utility is installed.

    which nc

    If the command returns a path, such as /usr/bin/nc, the utility is installed.

    /usr/bin/nc
    Note

    If the command is not found, install the utility by using a package manager such as yum or apt-get. For example: sudo yum install -y nc.

  3. On the server instance, run the following command to listen on the test UDP port.

    For example, on UDP port 3333, run sudo nc -uvlp 3333.

    # Replace [$Port] with the port number to test.
    sudo nc -uvlp [$Port]

    The command starts a listener on the specified port and 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
  4. On the client instance, run the following command to connect to the test port on the server.

    For example, to connect to UDP port 3333 on the server at 111.22.XX.XX, run sudo nc -u 111.22.XX.XX 3333.

    # Replace [$Host] with the server IP address and [$Port] with the port number to test.
    sudo nc -u [$Host] [$Port]
  5. Once the command is running, type a test string (e.g., "test") and press Enter. If the same string appears in the server terminal, the port connection is successful.

    Note

    If the test fails (the server does not receive the data), ensure the server's security group rules allow inbound traffic on the test port. To allow access, add a security group rule. For more information, see Add a security group rule.

    image

    image