How to Test TCP connectivity with curl

If you’re a network or system administrator, developer, or just someone who’s working on network-related tasks, you might encounter situations where you need to test the TCP connectivity between two machines.

Usually we use telnet, however because it’s insecure, it is not installed on the most distributions.

Alternatively, we can use Curl, a popular command-line tool used for transferring data over various protocols, including HTTP, FTP, SMTP, and others. it can also be used to test TCP connectivity. In this article, we’ll explore how to use Curl to test TCP connectivity on Linux.



The basic syntax for testing TCP connectivity with curl is as follows :

curl telnet://<host>:<port>

host is the hostname or IP address of the server you want to connect to, and port is the port number.

Test port connection with curl

Here I’m trying to access a Linux server with ssh but it doesn’t work :

[root@Linux ~]# ssh
ssh: connect to host port 22: Connection refused

So I need to check TCP connectivity to the server on port 22 with curl by running the following command :

[root@Linux ~]# curl telnet://
curl: (7) Failed connect to; Connection refused

In my case there is no firewall between the two machine, so either the local firewall blocks incoming ssh connection or the ssh service is not started.

After checking, I found that the ssh service is not started :

[root@server ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2023-03-12 12:45:16 +01; 16min ago
     Docs: man:sshd(8)
  Process: 1076 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1076 (code=exited, status=0/SUCCESS)

Now, After starting the service, here is the message I get when I test with curl :

[root@Linux ~]# curl telnet://

you can use -v option to get more informations about the connection :

[root@Linux ~]# curl -v telnet://
* About to connect() to port 22 (#0)
*   Trying
* Connected to ( port 22 (#0)

Want to discover other alternative tools to test connectivity ? click here.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *