[No audio]
curl and ping commands.
Why do we need them?
Well, those two commands are so useful when
you are troubleshooting system network related issues.
So if you are a system administrator and you get a
call from someone and says hey Mike, this server is not
reachable or this machine is out or down, or I cannot
ping this address or I cannot reach this website.
So what are the first few things that you need to do?
Well, first thing that you try to communicate to that
server yourself to see if you could reach it, right?
So how are you going to communicate to it?
So there are two very basic commands.
One of them is curl and the second one is ping.
So you have this Google website that you go
on Windows, you log in, you go to www.google.com.
Perfect, you could reach it so you know how it is.
But what if in Linux system you don't have
the GUI or you cannot open up a browser.
You have to find out how that works, right,
just like the wget command.
So for that in Linux we have curl.
Now curl specifically is for the URL.
So as you can see it's c and then url.
So you grab that URL and see whether you could get
to that specific http site. So you could ping the site,
let's say if you're pinging google.com, it will come back with
the IP address, it will try to ping that IP address
and you will see, hey, the server is up.
Okay, but if the server is up, what if the page
is not up for the server and the page is actually
run by what it says, run by Apache, right, httpd.
What if the server is up, and page is down?
Then you need this curl command which is very handy
command to find out if that page is up.
And of course the other one is the ping the server.
If you are server A and you want to see if
the server B is up or not, you ping that server
by its hostname or by its IP address.
So the example in Linux for curl is that you
specify the http and the entire URL and it will
bring you back the content of the page.
Not exactly the way it looks when you open up
a browser, but it will bring up all the HTML
source code most likely or some other information.
But when it brings it back, it means the page is up.
Then you also have curl -O, uppercase O
option if you want to download a file.
Remember we could use wget command as well.
In some computers if you don't have
wget, you could use curl command to download
a file to your Linux machine.
And of course at the end we have ping.
If you want to ping a server by hostname, which
is let's say google.com or your system hostname,
with the fully qualified domain name,
you could use ping command.
So we will try curl and ping
one by one in our Linux machine.
[No audio]
So this is my Linux machine and this time I
wanted to log into the Linux machine through PuTTY.
So before we get into the PuTTY, I need
to know the IP address of my Linux machine.
And my IP address is right here.
You'll see 192.168.1.20.
So now if you see the 182 always comes up
if you have the network adapter set as Bridged Adapter,
and if you are connecting to the Internet through wireless,
make sure the name is connected to wireless.
Or if you are hard coded with the wire, then
you ping the wire cable connection in the name. Anyway.
I know the IP address.
Now I'm going to open up a PuTTY session
and I'm going to put in my IP address.
192.168.1.20, I believe.
Let's confirm it one more time.
Yes, it is 20.
I'm going to go ahead and click Open, login as root.
[No audio]
Okay, so I am logged in as root.
I could confirm that I'm root and also by the
prompt right here it says the prompt is pound.
So I'm going to make this a little bigger as well.
So,
now let's say if I wanted to go to a website and
I wanted to make sure if that website is up or not.
So let's try our simple website,
as always, Google.
Hit enter, and you see all that
stuff that came up on the screen.
There's so much other stuff too, but you don't really
need to worry about what that stuff is or how
to decrypt that or how to understand the HTML
to understand that. All you have to do when you run
the curl followed by the hostname or the URL and you
get this entire page with HTML coding and stuff like that,
then it means that your website is up.
You could reach it. Good.
So if you want to ping it, so
you could do ping www.google.com, this will
only ping the IP address of the Google.
You see the IP address of
the Google right here, 216.58.217.68.
So it could change.
So you could ping it by the hostname
which is Google.com, which is URL.
Or you could ping by the IP address.
So let's say if I ping it by
IP address 216.58.217.68, you'll see you're getting a
response back and that is Google.
You can always do nslookup on this to find
out which website is that and you will see this
website belongs to these names and these names translates to,
which is the point of record, translates to Google.
Anyway, what if you want to download a file from
the Internet using curl command. For that, you need to
know the exact URL for the file that you're downloading.
So I have on my browser, I have a page
open which is download PuTTY, so if you know, you
could just go to, let's say Google and type download
putty, it will bring you to this page.
Click on Go to download,
[No audio]
and you see right here,
this is the msi file which runs on Windows.
We are not trying to download it
on Unix or anywhere, but in Windows,
then you could use this one.
If you're trying to download on Linux,
then you could use this one.
Anyway, it doesn't really matter for this
lesson because I'm just trying to explain
to you how you could download it.
So you could ping anyone.
Let's say if I ping this one, right click on that
link and you see right here it says, Copy link address.
Click on that.
Once you copy it, you could verify the link by opening
up your notepad and then you could paste it here.
You see this is the entire link for that tar.gz file.
Now go back to your PuTTY session,
and now this time type, curl -O, and right
click which will paste your copy link to your screen.
Once you have that, go ahead and
enter and you will see it's
downloading it, it tells you
the statistics of the download.
Now is it downloaded?
Where is it downloaded?
It will download whichever directory you
are in, you are in slash root.
So we are in root and let's say if it could verify
do ls -l, and you will see right here, this is
the file that we just downloaded with today's date and time.
So this is how you download if you don't have wget or
if you want to specifically download through the URL.
This curl and ping commands are very useful.
Also a lot of people in interview
would ask tell me the commands or
different ways that you could troubleshoot.
If a server A cannot reach server B, then you
could simply mention that you're going to use the ping
command, you're going to use the curl command.
If it's a web URL, you're going to use
different commands to check it also going back to
ping if you are paying Google and you will
notice that this is going to ping continuously.
Now sometimes if you are on Windows machine
and you try ping Google, it will ping
it three times and will stop.
So to use that ping on a Windows machine,
you would have to, I believe, use the option
minus s or minus t, one of those options.
So please try it.
I'm very sure that it's one of
the minus t or minus s option.
I'm sorry, I don't have the
exact option remember right now. But try those.
So it will ping continuously and you will see that
packets are dropped or how long it's taking for the
ping to go into ping and come back.
So these are the two basic commands
that I wanted to cover with.
You try them out and just
play around with it all right.
[No audio]