All Products
Search
Document Center

Elastic Compute Service:Test TCP and UDP port connectivity in Linux

Last Updated:Jun 21, 2026

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:

Method 1: Test existing listeners with Telnet

  1. Connect to the Linux instance.

    For more information, see Log on to a Linux instance by using Workbench.

  2. Run the following command to test port connectivity by using Telnet.

    For example, to test port 1234 on server 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]

    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.

    Note

    If 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.

  1. Connect to the Linux instance.

    For more information, see Log on to a Linux instance by using Workbench.

  2. On the server, run the following command to check if Python is installed and view its version.

    python -V
  3. 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 1234 by using Python 3.x, run sudo 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 ...
    Note

    After you complete the test on the client, press Ctrl+C to stop the process.

  4. 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 1234 on server 121.11.XX.XX, run sudo 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.

    Note

    If 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.

  1. Connect to the Linux instance.

    For more information, see Log on to a Linux instance by using Workbench.

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

    which nc

    If the system returns a response similar to the following, it indicates that the nc program is installed.

    /usr/bin/nc
    Note

    If 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.

  3. 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, run sudo 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
  4. On the client, run the following command to connect to the test port on the server.

    For example, to connect to port 3333 on server 111.22.XX.XX, run sudo 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]
  5. 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.

    Note

    If 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
    example

    The server receives the test and example messages 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