try.directtry.direct

Back to explains list

How to check whether your server is online using a Linux command line.

How to check whether your server is online using a Linux command line.


We often need to check connectivity to troubleshoot network issues or want to check whether our server is online. We created this article to show you how to do this. There are many handy Linux tools for this:


1. ping

Ping is one of the most widely used commands to check whether a server or remote host is up and responding. Ping sends ICMP ECHO_REQUEST to the server. If ICMP is blocked from the server-side or cloud provider, then the ping command may not work as expected (like AWS ec2 instance). Here, we assume that cloud provider's firewalls do not block ICMP.

Syntax: ping <destination>


➜  ~ ping example.com
PING example.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: icmp_seq=0 ttl=53 time=129.615 ms
64 bytes from 93.184.216.34: icmp_seq=1 ttl=53 time=130.620 ms
^C
--- example.com ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 129.615/130.118/130.620/0.502 ms

2. telnet

Telnet is a network protocol that allows you to connect to a remote host. Telnet is usually installed on most Linux OS by default. Otherwise, you can run the following command in the terminal:


Redhat/CentOS/Rocky Linux


yum -y install telnet

Ubuntu/Debian


apt-get install telnet

Using telnet, you can identify the availability of certain ports. You can use telnet to make sure no firewalls in between are blocking incoming connections to the server.

System or network administrators use Telnet to configure network devices like routers and switches.


➜  ~ telnet example.com 22
Trying 111.201.251.32...
Connected to example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.5

The above command shows that port 22 is open on the example.com.

Let’s now check whether the webserver port is open.


➜  ~ telnet example.com 443
Trying 93.184.216.34...
Connected to example.com.
Escape character is '^]'.

Which means the port 443 is open and accessible.

If the port is firewalled on the remote host, then you will see something like this


➜  ~ telnet example.com 22
Trying 93.184.216.34...
telnet: connect to address 93.184.216.34: Operation timed out
Trying 2606:2800:220:1:248:1893:25c8:1946...
telnet: connect to address 2606:2800:220:1:248:1893:25c8:1946: No route to host
telnet: Unable to connect to remote host

3. nslookup

Simply speaking, nslookup is used for DNS record checks. You can use nslookup to check if your website is connected to the internet. It is also used to troubleshoot DNS-related problems.

➜  ~ nslookup example.com
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: example.com
Address: 93.184.216.34

It will show the IP address and other details. Otherwise you will see the following:


➜  ~ nslookup example.com1
Server: 8.8.8.8
Address: 8.8.8.8#53

** server can't find example.com1: NXDOMAIN

By default, nslookup command output shows A records of a domain.


4. nmap

Nmap or Network Mapper is a powerful tool for finding open ports and network audits. In case the nmap command is not available, you can install it executing the following command in terminal:

sudo apt install nmap

Nmap is also used to identify whether the host is up or not. This command will show open port and host status as below:

➜  ~ nmap example.com
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-15 12:36 EET
Nmap scan report for example.com (93.184.216.34)
Host is up (0.13s latency).
Not shown: 996 filtered tcp ports (no-response)
PORT STATE SERVICE
80/tcp open http
443/tcp open https
1119/tcp closed bnetgame
1935/tcp closed rtmp

Nmap done: 1 IP address (1 host up) scanned in 64.63 seconds

You can easily check whether your server is running using the following command:


➜  ~ nmap -sn example.com
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-15 12:39 EET
Nmap scan report for example.com (93.184.216.34)
Host is up (0.13s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.23 seconds

5. nc

Netcat is known as an nc command used for network scanning like Port Scanning, open Remote connections, Network debugging, read and write operation on the network, and many more.

You can easily check the reachability of remote ports using nc Command.

Syntax: nc -vz $HOSTNAME $PORT

If port 443 is running on the server, we will get the following:

➜  ~ nc -vz example.com 443
Connection to example.com port 443 [tcp/https] succeeded!

6. wget

Wget is a command-line download tool that supports HTTP, HTTPS and FTP. Wget is very useful for those who want to check any network-related issue or test connection from a Linux terminal. It will help you in web-related issues debugging.


➜  ~ wget example.com
--2022-03-15 12:42:10-- http://example.com/
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1256 (1.2K) [text/html]
Saving to: ‘index.html’

index.html 100%[=====================================================>] 1.23K --.-KB/s in 0s

2022-03-15 12:42:10 (120 MB/s) - ‘index.html’ saved [1256/1256]

➜ ~

Here we get the “200” response code from the web server and index.html file downloaded.


7. curl

You can use the curl command to transfer data either from or to a server. It supports proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, and many more. You can use curl command to test TCP ports connectivity. Let’s check SSH port connection to a temporary created demo server with CURL

➜  ~ curl -v telnet://example2.com:22
* Trying 93.184.216.35:22...
* Connected to example2.com (93.184.216.35) port 22 (#0)
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.5

Now let’s check whether our web server is running on port 80 using curl. -I option will show only headers in the output

curl -I example.com
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Age: 476807
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Tue, 15 Mar 2022 10:48:07 GMT
Etag: "3147526947+ident"
Expires: Tue, 22 Mar 2022 10:48:07 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (nyb/1D13)
X-Cache: HIT
Content-Length: 648

Let’s check the SMTP port

~ curl -v telnet://example.com:25
* Trying 93.184.216.34:25...
* connect to 93.184.216.34 port 25 failed: Operation timed out
* Failed to connect to example.com port 25: Operation timed out
* Closing connection 0
curl: (28) Failed to connect to example.com port 25: Operation timed out

As you see, CURL is a useful command-line tool available in Linux to check the connection with the server and port. We’ve examined the Linux command-line tools for checking server health and network connectivity in detail. These are the must-know tools for all the system and network administrators any network-related issues.


8. Python command

Also known as one liner.

python -c "from urllib.request import urlopen;resp=urlopen('http://www.google.com/');print(resp.status)"


Did not find the solution? Join our discord channel and consult with our tech experts
Still don't know how to check? Get system administration help from our partners


Next article: What is DNS propagation