Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A simple method for testing TCP/UDP Port Connectivity in Linux operating system

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

When using Linux operating system, it is sometimes necessary to test the connectivity of ports to confirm whether the TCP and UDP protocol stacks of the system can run normally. This article explains this briefly.

TCP port test

Test existing listening port connectivity using telnet

You can use Linux's telnet tool to test connectivity of existing ports. The test command is:

telnet

# host is the target server IP, port is the port number to be tested

Examples:

The connectivity of port 22 can be tested with the following command:

telnet 127.0.0.1 22

If the connection is successful, a message similar to the following will be displayed. The display may vary depending on the Linux environment, but it usually contains "Connected to... "message, the connection is successful.

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

SSH-2.0-OpenSSH_5.3

In addition, in Windows, after a successful connection, a new window appears (with or without any echo). If the connection fails, a message similar to the following appears:

C:\>telnet 127.0.0.1 1111

Connecting to 127.0.0.1... Unable to open connection to host. On port 1111: connection failed

Create a new listening port test

Python's built-in Web server can be used to temporarily create new listening ports for testing. The usage is as follows:

python -m SimpleHTTPServer

Example output:

[root@centos]# python -m SimpleHTTPServer 123

Serving HTTP on 0.0.0.0 port 123 ...

Description: The Web service started is single-threaded, with the current directory as the root directory, and can only accept one request at a time, which is generally only used for testing. Press Ctr +C to terminate the process.

UDP Port Test

telnet can only be used for TCP port testing, to test UDP ports, you can use nc program.

Verify that nc is installed in your system using the following command:

which nc

Example output:

[root@centos]# which nc

/usr/bin/nc

If nc is not installed, use yum or apt-get to install it, depending on the operating system, which is not described in detail in this article.

Test the connectivity of the UDP port on the target server using the following command:

Usage:

nc -vuz

Example output:

[root@centos]# nc -vuz 192.168.0.1 25

Connection to 192.168.0.1 25 port [udp/smtp] succeeded!

#If the returned result contains the word "succeeded", it means that the corresponding port access is normal. If there is no return message, it means that the corresponding port access failed.

Parameter Description:

-v verbose output (two-v's for more verbose content)

-u Use UDP transport protocol

-z lets nc scan ports only and not send any data

Note: The above content is for reference only. The article reference source http://raksmart.idcspy.com, please indicate if it is reproduced.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report