Disclaimer: This article may contain information about third-party products. Such information is for reference only. Alibaba Cloud does not make any guarantee, express or implied, with respect to the performance and reliability of third-party products, as well as potential impacts of operations on the products.
This article describes how to test the connectivity between TCP and UDP ports in ECS instances of Linux.
Alibaba Cloud reminds you that:
- Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
- If you modify the configurations and data of instances including but not limited to ECS and RDS instances, we recommend that you create snapshots or enable RDS log backup.
- If you have authorized or submitted security information such as the logon account and password in the Alibaba Cloud Management console, we recommend that you modify such information in a timely manner.
The following is the details of testing the connectivity between TCP and UDP ports:
Test TCP port connectivity
The following describes how to test port connectivity by using the Telnet tool and the Python Web server.
Telnet to test port connectivity
In the ECS instance, run the following command to test port connectivity by using the telnet tool.
telnet [$Host] [$Port]
- [$Host] is the IP address of the target server.
- [$Port] is the Port to be tested.
- Run the following command to test the connectivity from port 22:telnet 127.0.0.1 22If the connection is successful, a message similar to the following is displayed. The display may vary depending on the Linux. However, if the
connectedto.Information, the connection is successful.Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Create a new listening port for testing.
The following describes how to use the Python Web server to temporarily create a new listening port for testing. Run the following command to test the port.
python -m SimpleHTTPServer [$Port]
The following command output is returned.
Serving HTTP on 0.0.0.0 port 123 ...
Note: The Web service is started with a single thread. Take the current directory as the root directory as an example. Only one request can be accepted for testing at a time. After the test is completed, press Ctrl C to terminate the process.
Test UDP port connectivity
The following describes how to test the connectivity of a UDP port by using an nc program:
- Run the following command to check whether the nc program is installed.
which ncIf a similar output is displayed, the nc program has been installed.
Note: If the nc is not installed, use tools such as yum or apt-get to install the nc based on the operating system.
- Run the following command on the server to listen to a port to be tested, such as port 1234:
nc -uvlp 1234The following command output is returned.
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Listening on :::1234
Ncat: Listening on 0.0.0.0:1234
- Run the following command on the client to connect the server to the port to be tested, such as port 1234.
nc -u [$Host] 1234
- After the connection is established, enter a test character (abc) on the client and confirm the display in the server. If no response is synchronized by the backend server, the port connectivity is abnormal.