• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Test Port [TCP/UDP] Connectivity from a Linux Server

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 22
Trying 192.168.12.10...
Connected to 192.168.12.10.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.6.1

Protocol mismatch.
Connection closed by foreign host.

Example of unsuccessful connection:

# telnet 192.168.12.10 22
Trying 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 22
Connection to 192.118.20.95 22 port [tcp/ssh] succeeded!

Example of unsuccessful connection:

# nc -z -v 192.168.10.12 22
nc: 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 123
Connection to 192.118.20.95 123 port [udp/ntp] succeeded!

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to create an XFS Filesystem
  2. CentOS / RHEL : Configure yum automatic updates with yum-cron service
  3. How to Configure rsyslog to Filter/discard Specific IP Address in CentOS/RHEL 6,7
  4. How to allow or deny telnet login to specific users only in CentOS/RHEL
  5. DHCP configuration file /etc/dhcp/dhcpd.conf explained
  6. dir Command Examples in Linux
  7. Yum Command – RPM Based Package Management Utility
  8. Tutorial on Linux Clustering (High Availability)
  9. How to disable lvmetad in CentOS/RHEL
  10. How to Remove virbr0 and lxcbr0 Interfaces on CentOS/RHEL 6,7

You May Also Like

Primary Sidebar

Recent Posts

  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found
  • macof: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright