How to Test Port [TCP/UDP] Connectivity from a Linux Server – The Geek Diary (2024)

by admin

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 [hostname/IP address] [port number]

Example of successful connection:

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

You May Also Like

How to Test Port [TCP/UDP] Connectivity from a Linux Server – The Geek Diary (2024)

FAQs

How do you check if TCP and UDP ports are open in Linux? ›

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.

How to test a TCP connection with port Linux? ›

On a Linux computer
  1. Open Terminal on your Linux computer.
  2. 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.
  3. If the port is open, a message will say Connected to 10.17. xxx. xxx.
Oct 19, 2021

How do I test UDP port connectivity? ›

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.

How to check port connectivity between two servers in Linux? ›

How to PROPERLY test port connectivity in Linux
  1. Method-1: Use timeout utility to test port connectivity. Syntax to use timeout utility. ...
  2. Method-2: Use nmap command to test port connectivity. ...
  3. Method-3: Use telnet command to test port connectivity. ...
  4. Method-4: Use nc command to test port connectivity. ...
  5. Summary.

How do you find the port information in Linux for TCP and UDP protocols? ›

Method 1: Using netstat tool
  1. Option -l: list only listening sockets.
  2. Option -n: show the port number.
  3. Option -t: list the TCP ports.
  4. Option -u: list the UDP ports.
Oct 17, 2021

How to check server connectivity in Linux? ›

How to troubleshoot network connectivity with Linux server
  1. Check your network configuration. ...
  2. Check the network configuration file. ...
  3. Check the servers DNS records. ...
  4. Test the connection both ways. ...
  5. Find out where the connection fails. ...
  6. Firewall settings. ...
  7. Host status information.
May 17, 2022

What is TCP and UDP in Linux? ›

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.

Does netstat show UDP ports? ›

netstat displays incoming and outgoing network connections (TCP and UDP), host computer routing table information, and interface statistics.

How do I test port connectivity? ›

Answer
  1. Open a command prompt.
  2. Type in "telnet <IP ADDRESS OF SERVER PC> <PORT>" and press enter.
  3. For example, you would type “telnet 123.45. ...
  4. If a blank screen appears then the port is open, and the test is successful.
  5. If you receive a connecting... message or an error message then something is blocking that port.
Jul 8, 2020

How do you check if TCP port is listening? ›

In order to check which application is listening on a port, you can use the following command from the command line:
  1. For Microsoft Windows: netstat -ano | find "1234" | find "LISTEN" tasklist /fi "PID eq 1234"
  2. For Linux: netstat -anpe | grep "1234" | grep "LISTEN"
May 19, 2022

How to check port connectivity in Linux without telnet? ›

Here are several different ways to test a TCP port without telnet.
  1. BASH (man page) $ cat < /dev/tcp/127.0.0.1/22 SSH-2.0-OpenSSH_5.3 ^C $ cat < /dev/tcp/127.0.0.1/23 bash: connect: Connection refused bash: /dev/tcp/127.0.0.1/23: Connection refused.
  2. cURL. ...
  3. Python. ...
  4. Perl.

How to check UDP port is open in Linux using telnet? ›

Linux test TCP/UDP port connectivity (Open port check) with nc...
  1. TCP. # nc -z -v [hostname or IP address] [port number] nc -z -v 192.168. ...
  2. UDP. # nc -z -v -u [hostname or IP address] [port number] # nc -z -v -u 192.168. ...
  3. Bouns. We can also test TCP port with telnet command telnet [hostname or IP address] [port number]
Nov 6, 2019

How do I check if a UDP port is listening? ›

Check Listening Ports with netstat

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

Can I test UDP port with telnet? ›

Note: Telnet is an application that operates using the TCP protocol. UDP connectivity can not be tested using Telnet.

How do I troubleshoot my UDP port? ›

Troubleshooting TCP and UDP Port Status
  1. Select Maintenance > Troubleshooting > Tools > Commands.
  2. Select the Portprobe command.
  3. Select either TCP or UDP.
  4. Enter the target server and port number. ...
  5. Enter the probe count. ...
  6. Enter the probe timeout. ...
  7. Select either the internal port or the management port.

How to check port status in Linux? ›

To check the listening ports and applications on Linux:
  1. Open a terminal application i.e. shell prompt.
  2. Run any one of the following command on Linux to see open ports: $ sudo lsof -i -P -n | grep LISTEN. $ sudo netstat -tulpn | grep LISTEN. ...
  3. For the latest version of Linux use the ss command. For example, ss -tulw.
Aug 14, 2022

How to check port traffic in Linux? ›

The procedure is as follows:
  1. Open the terminal application on Linux.
  2. Type any one of the following command to check if a port is in use on Linux. sudo lsof -i -P -n | grep LISTEN. ...
  3. Search for the TCP or UDP port description in /etc/services file on Linux: grep -E -w 'PORT_NUMBER_HERE/(tcp|udp)' /etc/services.
Mar 31, 2021

Where can I find open TCP UDP ports? ›

Opening TCP/UDP port
  1. Locate your router's IP address.
  2. Head over to your router's settings.
  3. Enter your credentials (username and password).
  4. Look around for the Port Forwarding tab.
  5. Open your preferred port—for example, type 8080 to open port 8080.
  6. Save your settings.
Jan 14, 2021

Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 5781

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

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.