Here is a short post to check port [TCP/UDP] connectivity from a Linux server. A TCP/IP network connection may be either blocked, dropped, open, or filtered. These actions are generally controlled by the IPtables firewall the system uses and is independent of any process or program that may be listening on a network port.
Telnet and nc are common tools used to test port connectivity from Linux server. Telnet can be used to test tcp port connections, where as nc can be used to test both tcp/udp ports connectivity. Make sure telnet and nc tools are installed on the Linux server you are trying to test connectivity.
# yum install nc# yum install telnet
Testing TCP port connectivity with telnet
Lets see how we can use telnet command to test the TCP port connectivity. The syntax to use the telnet command is as follows:
# telnet 192.168.12.10 22Trying 192.168.12.10...Connected to 192.168.12.10.Escape character is '^]'.SSH-2.0-OpenSSH_6.6.1Protocol mismatch.Connection closed by foreign host.
Example of unsuccessful connection:
# telnet 192.168.12.10 22Trying 192.168.12.10...telnet: connect to address 192.168.12.10: No route to host
Using nc command to test TCP port connectivity
The syntax to use nc command for testing TCP post connectivity is as follows:
# nc -z -v [hostname/IP address] [port number]
Example of successful connection:
# nc -z -v 192.168.10.12 22Connection to 192.118.20.95 22 port [tcp/ssh] succeeded!
Example of unsuccessful connection:
# nc -z -v 192.168.10.12 22nc: connect to 192.118.20.95 port 22 (tcp) failed: No route to host
Testing UDP port connectivity wit nc command
The syntax to test UDP port connectivity with nc command is as follows:
# nc -z -v -u [hostname/IP address] [port number]
Example of successful connection:
# nc -z -v -u 192.168.10.12 123Connection to 192.118.20.95 123 port [udp/ntp] succeeded!
Use ss command to display all open TCP and UDP ports in Linux. Another option is to use the netstat command to list all ports in Linux. Apart from ss / netstat one can use the lsof command to list open files and ports on Linux based system. Finally, one can use nmap command to check TCP and UDP ports too.
Enter "telnet + IP address or hostname + port number" (e.g., telnet www.synology.com 1723 or telnet 10.17. xxx. xxx 5000) to run the telnet command and test the port status.
If the port is open, a message will say Connected to 10.17. xxx. xxx.
To check TCP and UDP ports, you can use Microsoft PortQry Command Line. If you could successfully connect, the dynamic ports are opened. If you receive error “The RPC server is unavailable”, the ports are closed. Ports 49152 – 65535 should be opened.
In a computer network, the network service runs a software in each of the computers that are part of the network. In Linux System this network software uses a protocol called TCP or UDP along with port number. TCP is known as transmission control protocol and UDP is known as user datagram protocol.
-u - Show UDP ports. -n - Show numerical addresses instead of resolving hosts. -l - Show only listening ports. -p - Show the PID and name of the listener's process.
Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping
Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.