Check a Website Availability from the Linux Command Line

You can easily test a a website availability from the Linux command line and get the status codes from the web-server using commands like TELNET or CURL.

Check a website availability with CURL

Execute the following command to check whether a web site is up, and what status message the web server is showing:

$ curl -Is http://www.shellhacks.com | head -1
HTTP/1.1 200 OK

Status code ‘200 OK’ means that the request has succeeded and a website is reachable.

Here is an another example that shows you how curl displays different status codes.

$ curl -Is http://shellhacks.com | head -n 1
HTTP/1.1 301 Moved Permanently

You’ll notice that if you visit: http://shellhacks.com you are redirected to http://www.shellhacks.com, because I prefer to have www in my site’s URL. I do this by implementing a 301 Redirect (Permanently moved) for any visitor who goes to http://shellhacks.com.

You can also check the availability of a particular page on the site:

$ curl -Is http://www.shellhacks.com/Bash-Colors | head -n 1
HTTP/1.1 200 OK

Read more: Status Code Definitions

Check a website availability with TELNET

You can also test website availability and get the response code using telnet command:

$ telnet www.shellhacks.com 80
Trying 91.206.200.119...
Connected to www.shellhacks.com.
Escape character is '^]'.
HEAD / HTTP/1.0
HOST: www.shellhacks.com
<PRESS ENTER>
<PRESS ENTER>

You will get the output as follows:

HTTP/1.1 200 OK
Server: nginx/1.1.10
Date: Sun, 26 May 2013 19:29:46 GMT
***

That also means that the website is OK.

What is my Public IP address?

Use one of the following commands to check your public IP address from the Linux command line.

Get the Public IP address from the Linux Command Line

0. Easy to Remember Services

Get your external IP address using the curl command:

$ curl ifconfig.me
$ curl ip.appspot.com
$ curl icanhazip.com

Get your external IP address using the wget command:

$ wget -q -O - ifconfig.me
$ wget -q -O - ip.appspot.com
$ wget -q -O - icanhazip.com

Get the External IP address using DynDNS.org

1. Using the wget command:

$ wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

2. Using the curl command:

$ curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

3. Using the lynx command:

$ lynx -dump checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//' | sed '/^$/d'