• June 15, 2022

Test Connection With Curl

Datacenter proxies

  • HTTP & SOCKS
  • unlimited bandwidth
  • Price starting from $0.08/IP
  • Locations: EU, America, Asia

Visit fineproxy.de

How to troubleshoot network applications with curl - A2 Hosting

How to troubleshoot network applications with curl – A2 Hosting

There are many online tools for testing the services offered by a server but those tests only indicate the view from the online tool. Sometimes you need to test connectivity from your local computer. This article describes how to use curl to troubleshoot network of Contents
About curl
Using curl to troubleshoot
Troubleshooting web servers
Troubleshooting mail (SMTP) servers
Troubleshooting FTP
Troubleshooting SSH
More Information
Curl is a command line tool to transfer data from or to a server
Curl is available at the Linux command line, in the Macintosh Terminal and in the Windows Subsystem for Linux. Later versions of Windows 10 include curl in the command prompt. Curl can also be installed from Don’t want to install software? Try our articles on network troubleshooting using telnet or using PowerShell and tnc. Just about every computer will have one of these three programs installed.
To use curl to test basic network connectivity, you need to know several things:
The remote server name or IP address.
The protocol for the service to be tested (HTTP, FTP, SMTP, etc. )
The port number for the network application you want to test.
To open a connection to a remote server, open a terminal window on your computer, and then type curl protocolIP/host:port, where protocol is the communication protocol to be used IP/host represents the IP address or hostname of the server, and port represents the TCP port number. Port is optional when the standard port for a given protocol is used. For example, to connect to on the standard port for, type the following command:
curl
When you try to establish a connection to a remote server, one of two things happens:
The server accepts the connection. If this happens, curl may display some text from the server.
The server rejects the connection. If this happens, you receive a message such as Connection refused or Connect failed.
The following sections demonstrate how to do basic troubleshooting with curl.
Web server testing is probably the most common scenario for network troubleshooting. With curl, you can open a connection to a remote server on port 80 and get a response. Text in red represents commands typed by the user:
$ curl -I
HTTP/1. 1 200 OK
Date: Thu, 14 Feb 2019 20:11:29 GMT
Server: Apache
X-Powered-By: PHP/5. 5. 38
Content-Type: text/html
curl returns the entire content of the web page by default so in this example the -I option is added to return only the header. The HTTP response confirms that the server is accepting connections and responding to requests.
Use curl to try and connect via SMTP protocol
The following text shows a sample exchange between curl and a remote mail server. Text in red represents commands typed by the user:
$ curl smtp
214-Commands supported:
214 AUTH STARTTLS HELO EHLO MAIL RCPT DATA BDAT NOOP QUIT RSET HELP
The SMTP responses show the server is running and accepting requests.
Some ISPs block port the standard SMTP port (25) to help reduce spam on their you are testing connectivity to an A2 Hosting mail server, you can also use port 2525 or 587.
For example, to try and connect to SMTP on port 2525, add the optional port number at the end of the command. The following text shows a sample exchange between curl and a remote mail server using port 2525. Text in red represents commands typed by the user:
To test an FTP server, use curl to connect via ftp protocol or to port 21.
The following text shows a sample exchange between curl and a remote FTP server. Text in red represents commands typed by the user:
$ curl curl: (67) Access denied: 530
Because a valid user name was not supplied, curl returns Access denied.
More detail is available by using the FTP port (21) without the FTP protocol.
$ curl
220———- Welcome to Pure-FTPd [privsep] [TLS] ———-
220-You are user number 18 of 50 allowed.
220-Local time is now 12:46. Server port: 21.
220-This is a private system – No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Either response indicat the FTP server is active and running.
SSH uses encrypted connections. However, you can still use curl to verify that the service is running on a server.
The following text shows a sample exchange between curl and a remote SSH server. In this case we use the port number without the protocol. The standard port for ssh is 22 but port 7822 is used by A2 Hosting managed servers. Text in red represents commands typed by the user:
SSH-2. 0-OpenSSH_5. 3
The server returns a response showing the current OpenSSH version indicating the SSH server is active and Informationcurl is a very versatile tool. In addition to the basic connectivity checks shown in this document, it can:
send emails
upload and download files
post and retrieve information from web servers
Download and read about curl at the curl website.
Read the curl book online.
Test TCP connectivity with curl - Unix Tutorial

Datacenter proxies

  • HTTP & SOCKS
  • Price $1.3/IP
  • Locations: DE, RU, US
  • 5% OFF coupon: APFkysWLpG

Visit proxy6.net

Test TCP connectivity with curl – Unix Tutorial

You probably know about curl command: it’s great for downloading web pages or files from a Unix command line. But there’s another great usage curl command has: testing TCP ports connectivity.
Say, you’re helping with some firewall changes and need to confirm that connection from your server to some remote host and specific TCP port still works.
Here’s how you can do it using curl command and its telnet functionality.
Test SSH port connection with curl
In this example, SSH connection works because:
We get the “Connected” status
We see the SSH version prompt: SSH-2. 0-OpenSSH_7. 4
[email protected]:~ $ curl -v telnet127. 0. 1:22
* About to connect() to 127. 1 port 22 (#0)
* Trying 127. 1…
* Connected to 127. 1 (127. 1) port 22 (#0)
SSH-2. 4
^C
Test jBoss port 8080 with curl
This scenario shows that connection is refused (probably because there’s no service running on that port).
IMPORTANT: you would probably get a different message if firewall blocks the 8080 port. Connection refused is a clear sign that port is accessible, but nothing’s responding on it.
[email protected]:~ $ curl -v telnet127. 1:8080
* About to connect() to 127. 1 port 8080 (#0)
* Connection refused
* Failed connect to 127. 1:8080; Connection refused
* Closing connection 0
curl: (7) Failed connect to 127. 1:8080; Connection refused
See Also
Using wget and curl
Basic Unix Commands
iptables: keep rules after reboot
Advanced Unix Commands
11 cURL Command Usage with Real-Time Example - Geekflare

11 cURL Command Usage with Real-Time Example – Geekflare

cURL is a command-line tool to get or send data using URL syntax.
If you are working as a developer or in the support function, you must be aware of cURL command usage to troubleshoot web applications. cURL is a cross-platform utility means you can use on Windows, MAC, and UNIX.
The following are some of the most used syntaxes with an example to help you.
Verify if you can connect to the URL
If you are working on a UNIX system and trying to connect the external URL, the first thing you wish to do is to check if you can access the URL through curl.
curl
It will not throw any output. However, if the server can’t connect, then you will get errors such as could not resolve the host.
[[email protected] tmp]# curl
curl: (6) Could not resolve host:; Unknown error
[[email protected] tmp]#
Save URL/URI output to file
If you have to save the URL or URI contents to a specific file, you can use the following syntax
curl >
ex:
[[email protected] tmp]# curl > /tmp/gfhtml% Total% Received% Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 18557 0 18557 0 0 72565 0 –:–:– –:–:– –:–:– 72772
Above example will save all the contents from to /tmp/
Show request and response header
If you are having issues and would like to validate, you are getting the expected request and response header.
curl -v
Ex:
[[email protected] tmp]# curl -v * About to connect() to port 443 (#0)
* Trying 104. 25. 134. 107…
* Connected to (104. 107) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/
CApath: none
* SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject:, OU=PositiveSSL Multi-Domain, OU=Domain Control Validated
* start date: Nov 07 00:00:00 2019 GMT
* expire date: May 15 23:59:59 2020 GMT
* common name:
* issuer: CN=COMODO ECC Domain Validation Secure Server CA 2, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
> GET / HTTP/1. 1
> User-Agent: curl/7. 29. 0
> Host:
> Accept: */*
>
< HTTP/1. 1 200 OK < Date: Sat, 09 Nov 2019 19:41:37 GMT < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Set-Cookie: __cfduid=d2ce6cd359ebc0b6eb5ff3a454ed042021573328497; expires=Sun, 08-Nov-20 19:41:37 GMT; path=/;; HttpOnly; Secure < Vary: Accept-Encoding < Link: <>; rel=”
< Link: <>; rel=shortlink
< X-SRCache-Fetch-Status: HIT < X-SRCache-Store-Status: BYPASS < X-Frame-Options: SAMEORIGIN < X-Powered-By: EasyEngine v4. 0. 12 < Via: 1. 1 google < CF-Cache-Status: DYNAMIC < Strict-Transport-Security: max-age=15552000; preload < X-Content-Type-Options: nosniff < Alt-Svc: h3-23=":443"; ma=86400 < Expect-CT: max-age=604800, report-uri=" < Server: cloudflare < CF-RAY: 533243e4bcd4bbf4-LHR < Download at a limit rate If you are working on optimization and would like to see how much time does it take to download at a particular speed, you can:- curl –-limit-rate 2000B curl –-limit-rate 2000B Using a proxy to connect Very handy if you are working on the DMZ server where you need to connect to the external world using a proxy. curl --proxy yourproxy:port Test URL with injecting header You can use curl by inserting a header with your data to test or troubleshoot the particular issue. Let’s see the following example to request with Content-Type. curl --header 'Content-Type: application/json' By doing above, you are asking curl to pass Content-Type as application/json in the request header. Display only response header If you are doing some troubleshooting and quickly want to check the response header, you can use the following syntax. curl --head Ex: [[email protected] tmp]# curl --head HTTP/1. 1 200 OK Date: Sat, 09 Nov 2019 19:51:23 GMT Content-Type: text/html Connection: keep-alive Set-Cookie: __cfduid=d3cb2c7b8e566ad99c870b0af12b0f1eb1573329083; expires=Sun, 08-Nov-20 19:51:23 GMT; path=/;; HttpOnly X-GUploader-UploadID: AEnB2Uo96JhvJmR2zYUL-Ndh2ta3UD_ykQAB5C7O8cjZQhCf-GxHQ0MsodSzRnl3guSN3ywAYNjtWcPXfwDXjLg3bQ-P5vQMOA Expires: Sat, 09 Nov 2019 20:51:23 GMT Cache-Control: public, max-age=3600 Last-Modified: Mon, 06 Aug 2018 10:45:47 GMT x-goog-generation: 1533552347482034 x-goog-metageneration: 1 x-goog-stored-content-encoding: identity x-goog-stored-content-length: 24620 x-goog-hash: crc32c=DpDPAQ== x-goog-hash: md5=cIP/3rusdUx12Zla1kf1yA== x-goog-storage-class: MULTI_REGIONAL Accept-Ranges: bytes CF-Cache-Status: DYNAMIC Expect-CT: max-age=604800, report-uri=" Server: cloudflare CF-RAY: 53325234dc2fbb9a-LHR Connect HTTPS/SSL URL and ignore any SSL certificate error When you try to access SSL/TLS cert secured URL and if that is having the wrong cert or CN doesn’t match, then you will get the following error. curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate. Good news, you can instruct cURL to ignore the cert error with --insecure flag. curl --insecure Connect using a specific protocol (SSL/TLS) Very handy to test if a particular URL can handshake over specific SSL/TLS protocol. To connect using SSL v3 curl --sslv3 and for different TLS versions curl --tlsv1 curl --tlsv1. 0 curl --tlsv1. 1 curl --tlsv1. 2 curl --tlsv1. 3 Download file from FTP Server You can use curl to download the file as well by specifying username and password. curl -u user:password -O ftpftpurl/ You can always use “-v” with any syntax to print in verbose mode. Using Host Header The host header is useful to test the target URL over IP when the requested content is only available when host header matches. Or, if you want to test application using load balancer IP/URL. curl --header 'Host: ' How about using cURL online? Yes, that’s possible with the following tools. You can execute cURL remotely. Online CURL – a lightweight tool to fetch the URL online and the possibility to add the following options. --connect-timeout --cookie --data --header --head --location --max-time --proxy --request --user --url --user-agent cURL command line builder – this one is different. It helps you to build the curl command where you can enter information in nice UI, and at the bottom, you will get the cURL command. cURL is a useful utility to troubleshoot a real-time connectivity issue, and I hope the above helps you. If you are looking to learn more, then I would recommend Linux Command Line Basics online course.

Frequently Asked Questions about test connection with curl

How do I check if a port is open with curl?

2 AnswersPlease consider explaining your solution, and go into a little more detail as to why this works. … If you use command: curl -sL -w “%{http_code}n” google.com:443 -o /dev/null you receive code: 200 (OK) – service is working. … First of all, you should update this in your answer (edit it) with proper formatting.Dec 13, 2017

Can curl telnet?

NOTE: The telnet protocol does not specify any way to login with a specified user and password so curl can’t do that automatically. To do that, you need to track when the login prompt is received and send the username and password accordingly.Nov 9, 2017

How do you test curl?

To check whether the Curl package is installed on your system, open up your console, type curl , and press enter. If you have curl installed, the system will print curl: try ‘curl –help’ or ‘curl –manual’ for more information . Otherwise, you will see something like curl command not found .Nov 27, 2019

Leave a Reply

Your email address will not be published.