1 00:00:00,000 --> 00:00:01,270 [No audio] 2 00:00:01,270 --> 00:00:02,794 curl and ping commands. 3 00:00:02,902 --> 00:00:04,074 Why do we need them? 4 00:00:04,171 --> 00:00:07,974 Well, those two commands are so useful when 5 00:00:08,012 --> 00:00:12,462 you are troubleshooting system network related issues. 6 00:00:12,596 --> 00:00:16,277 So if you are a system administrator and you get a 7 00:00:16,303 --> 00:00:20,634 call from someone and says hey Mike, this server is not 8 00:00:20,672 --> 00:00:23,794 reachable or this machine is out or down, or I cannot 9 00:00:23,842 --> 00:00:27,510 ping this address or I cannot reach this website. 10 00:00:27,680 --> 00:00:30,798 So what are the first few things that you need to do? 11 00:00:30,944 --> 00:00:35,478 Well, first thing that you try to communicate to that 12 00:00:35,504 --> 00:00:38,046 server yourself to see if you could reach it, right? 13 00:00:38,168 --> 00:00:40,110 So how are you going to communicate to it? 14 00:00:40,160 --> 00:00:43,426 So there are two very basic commands. 15 00:00:43,558 --> 00:00:46,978 One of them is curl and the second one is ping. 16 00:00:47,134 --> 00:00:49,710 So you have this Google website that you go 17 00:00:49,760 --> 00:00:54,786 on Windows, you log in, you go to www.google.com. 18 00:00:54,848 --> 00:00:58,290 Perfect, you could reach it so you know how it is. 19 00:00:58,340 --> 00:01:00,990 But what if in Linux system you don't have 20 00:01:01,040 --> 00:01:03,022 the GUI or you cannot open up a browser. 21 00:01:03,046 --> 00:01:06,342 You have to find out how that works, right, 22 00:01:06,416 --> 00:01:08,194 just like the wget command. 23 00:01:08,302 --> 00:01:11,854 So for that in Linux we have curl. 24 00:01:12,022 --> 00:01:15,958 Now curl specifically is for the URL. 25 00:01:16,114 --> 00:01:19,846 So as you can see it's c and then url. 26 00:01:19,918 --> 00:01:23,226 So you grab that URL and see whether you could get 27 00:01:23,288 --> 00:01:29,202 to that specific http site. So you could ping the site, 28 00:01:29,336 --> 00:01:33,114 let's say if you're pinging google.com, it will come back with 29 00:01:33,152 --> 00:01:36,390 the IP address, it will try to ping that IP address 30 00:01:36,560 --> 00:01:38,550 and you will see, hey, the server is up. 31 00:01:38,660 --> 00:01:40,854 Okay, but if the server is up, what if the page 32 00:01:40,892 --> 00:01:44,178 is not up for the server and the page is actually 33 00:01:44,264 --> 00:01:48,058 run by what it says, run by Apache, right, httpd. 34 00:01:48,214 --> 00:01:50,670 What if the server is up, and page is down? 35 00:01:50,720 --> 00:01:53,458 Then you need this curl command which is very handy 36 00:01:53,494 --> 00:01:56,466 command to find out if that page is up. 37 00:01:56,588 --> 00:02:00,994 And of course the other one is the ping the server. 38 00:02:01,102 --> 00:02:04,458 If you are server A and you want to see if 39 00:02:04,484 --> 00:02:07,894 the server B is up or not, you ping that server 40 00:02:07,942 --> 00:02:11,060 by its hostname or by its IP address. 41 00:02:11,870 --> 00:02:15,438 So the example in Linux for curl is that you 42 00:02:15,464 --> 00:02:21,978 specify the http and the entire URL and it will 43 00:02:22,124 --> 00:02:24,678 bring you back the content of the page. 44 00:02:24,764 --> 00:02:26,922 Not exactly the way it looks when you open up 45 00:02:26,936 --> 00:02:29,950 a browser, but it will bring up all the HTML 46 00:02:30,010 --> 00:02:33,294 source code most likely or some other information. 47 00:02:33,452 --> 00:02:37,280 But when it brings it back, it means the page is up. 48 00:02:37,910 --> 00:02:41,334 Then you also have curl -O, uppercase O 49 00:02:41,372 --> 00:02:44,218 option if you want to download a file. 50 00:02:44,314 --> 00:02:46,878 Remember we could use wget command as well. 51 00:02:46,904 --> 00:02:48,555 In some computers if you don't have 52 00:02:48,555 --> 00:02:51,310 wget, you could use curl command to download 53 00:02:51,370 --> 00:02:53,050 a file to your Linux machine. 54 00:02:53,170 --> 00:02:55,246 And of course at the end we have ping. 55 00:02:55,318 --> 00:02:57,522 If you want to ping a server by hostname, which 56 00:02:57,536 --> 00:03:02,322 is let's say google.com or your system hostname, 57 00:03:02,456 --> 00:03:04,314 with the fully qualified domain name, 58 00:03:04,352 --> 00:03:06,030 you could use ping command. 59 00:03:06,470 --> 00:03:08,914 So we will try curl and ping 60 00:03:08,962 --> 00:03:11,190 one by one in our Linux machine. 61 00:03:11,190 --> 00:03:18,330 [No audio] 62 00:03:18,330 --> 00:03:20,998 So this is my Linux machine and this time I 63 00:03:21,024 --> 00:03:24,374 wanted to log into the Linux machine through PuTTY. 64 00:03:24,422 --> 00:03:26,242 So before we get into the PuTTY, I need 65 00:03:26,256 --> 00:03:29,282 to know the IP address of my Linux machine. 66 00:03:29,426 --> 00:03:31,678 And my IP address is right here. 67 00:03:31,704 --> 00:03:35,796 You'll see 192.168.1.20. 68 00:03:35,796 --> 00:03:39,550 So now if you see the 182 always comes up 69 00:03:39,600 --> 00:03:43,598 if you have the network adapter set as Bridged Adapter, 70 00:03:43,694 --> 00:03:46,274 and if you are connecting to the Internet through wireless, 71 00:03:46,322 --> 00:03:48,710 make sure the name is connected to wireless. 72 00:03:48,770 --> 00:03:50,914 Or if you are hard coded with the wire, then 73 00:03:50,952 --> 00:03:55,306 you ping the wire cable connection in the name. Anyway. 74 00:03:55,488 --> 00:03:56,650 I know the IP address. 75 00:03:56,700 --> 00:03:58,514 Now I'm going to open up a PuTTY session 76 00:03:58,562 --> 00:04:00,070 and I'm going to put in my IP address. 77 00:04:00,120 --> 00:04:04,478 192.168.1.20, I believe. 78 00:04:04,624 --> 00:04:06,266 Let's confirm it one more time. 79 00:04:06,328 --> 00:04:07,262 Yes, it is 20. 80 00:04:07,336 --> 00:04:12,290 I'm going to go ahead and click Open, login as root. 81 00:04:12,290 --> 00:04:16,310 [No audio] 82 00:04:16,310 --> 00:04:18,598 Okay, so I am logged in as root. 83 00:04:18,634 --> 00:04:21,618 I could confirm that I'm root and also by the 84 00:04:21,644 --> 00:04:25,209 prompt right here it says the prompt is pound. 85 00:04:25,390 --> 00:04:28,100 So I'm going to make this a little bigger as well. 86 00:04:28,100 --> 00:04:29,100 So, 87 00:04:30,350 --> 00:04:34,014 now let's say if I wanted to go to a website and 88 00:04:34,052 --> 00:04:36,990 I wanted to make sure if that website is up or not. 89 00:04:37,100 --> 00:04:40,614 So let's try our simple website, 90 00:04:40,712 --> 00:04:42,260 as always, Google. 91 00:04:43,490 --> 00:04:46,794 Hit enter, and you see all that 92 00:04:46,832 --> 00:04:48,630 stuff that came up on the screen. 93 00:04:48,740 --> 00:04:51,546 There's so much other stuff too, but you don't really 94 00:04:51,608 --> 00:04:54,174 need to worry about what that stuff is or how 95 00:04:54,212 --> 00:04:57,214 to decrypt that or how to understand the HTML 96 00:04:57,262 --> 00:05:01,458 to understand that. All you have to do when you run 97 00:05:01,484 --> 00:05:06,498 the curl followed by the hostname or the URL and you 98 00:05:06,524 --> 00:05:10,398 get this entire page with HTML coding and stuff like that, 99 00:05:10,484 --> 00:05:13,974 then it means that your website is up. 100 00:05:14,012 --> 00:05:16,230 You could reach it. Good. 101 00:05:16,400 --> 00:05:19,434 So if you want to ping it, so 102 00:05:19,472 --> 00:05:23,454 you could do ping www.google.com, this will 103 00:05:23,492 --> 00:05:25,530 only ping the IP address of the Google. 104 00:05:25,580 --> 00:05:26,706 You see the IP address of 105 00:05:26,708 --> 00:05:31,974 the Google right here, 216.58.217.68. 106 00:05:32,012 --> 00:05:32,934 So it could change. 107 00:05:32,972 --> 00:05:34,899 So you could ping it by the hostname 108 00:05:34,899 --> 00:05:36,814 which is Google.com, which is URL. 109 00:05:36,862 --> 00:05:39,750 Or you could ping by the IP address. 110 00:05:39,800 --> 00:05:41,094 So let's say if I ping it by 111 00:05:41,132 --> 00:05:49,722 IP address 216.58.217.68, you'll see you're getting a 112 00:05:49,736 --> 00:05:51,942 response back and that is Google. 113 00:05:52,076 --> 00:05:55,506 You can always do nslookup on this to find 114 00:05:55,568 --> 00:06:00,354 out which website is that and you will see this 115 00:06:00,392 --> 00:06:07,158 website belongs to these names and these names translates to, 116 00:06:07,244 --> 00:06:11,406 which is the point of record, translates to Google. 117 00:06:11,588 --> 00:06:16,040 Anyway, what if you want to download a file from 118 00:06:16,550 --> 00:06:19,878 the Internet using curl command. For that, you need to 119 00:06:19,904 --> 00:06:25,498 know the exact URL for the file that you're downloading. 120 00:06:25,534 --> 00:06:30,750 So I have on my browser, I have a page 121 00:06:30,800 --> 00:06:34,938 open which is download PuTTY, so if you know, you 122 00:06:34,964 --> 00:06:41,870 could just go to, let's say Google and type download 123 00:06:41,990 --> 00:06:46,450 putty, it will bring you to this page. 124 00:06:46,500 --> 00:06:48,118 Click on Go to download, 125 00:06:48,118 --> 00:06:51,631 [No audio] 126 00:06:51,631 --> 00:06:53,068 and you see right here, 127 00:06:53,068 --> 00:06:57,174 this is the msi file which runs on Windows. 128 00:06:57,342 --> 00:06:59,318 We are not trying to download it 129 00:06:59,344 --> 00:07:01,614 on Unix or anywhere, but in Windows, 130 00:07:01,722 --> 00:07:02,858 then you could use this one. 131 00:07:02,884 --> 00:07:04,398 If you're trying to download on Linux, 132 00:07:04,434 --> 00:07:05,642 then you could use this one. 133 00:07:05,716 --> 00:07:07,934 Anyway, it doesn't really matter for this 134 00:07:08,032 --> 00:07:09,710 lesson because I'm just trying to explain 135 00:07:09,760 --> 00:07:11,006 to you how you could download it. 136 00:07:11,008 --> 00:07:11,810 So you could ping anyone. 137 00:07:11,860 --> 00:07:14,498 Let's say if I ping this one, right click on that 138 00:07:14,524 --> 00:07:17,546 link and you see right here it says, Copy link address. 139 00:07:17,668 --> 00:07:18,674 Click on that. 140 00:07:18,832 --> 00:07:22,038 Once you copy it, you could verify the link by opening 141 00:07:22,074 --> 00:07:25,694 up your notepad and then you could paste it here. 142 00:07:25,792 --> 00:07:30,858 You see this is the entire link for that tar.gz file. 143 00:07:31,014 --> 00:07:34,950 Now go back to your PuTTY session, 144 00:07:35,130 --> 00:07:42,854 and now this time type, curl -O, and right 145 00:07:42,892 --> 00:07:49,766 click which will paste your copy link to your screen. 146 00:07:49,948 --> 00:07:51,746 Once you have that, go ahead and 147 00:07:51,808 --> 00:07:54,654 enter and you will see it's 148 00:07:54,702 --> 00:07:56,486 downloading it, it tells you 149 00:07:56,608 --> 00:07:58,926 the statistics of the download. 150 00:07:59,058 --> 00:08:00,834 Now is it downloaded? 151 00:08:00,882 --> 00:08:01,998 Where is it downloaded? 152 00:08:02,094 --> 00:08:04,598 It will download whichever directory you 153 00:08:04,624 --> 00:08:07,134 are in, you are in slash root. 154 00:08:07,302 --> 00:08:10,782 So we are in root and let's say if it could verify 155 00:08:10,866 --> 00:08:15,640 do ls -l, and you will see right here, this is 156 00:08:16,210 --> 00:08:22,442 the file that we just downloaded with today's date and time. 157 00:08:22,576 --> 00:08:25,820 So this is how you download if you don't have wget or 158 00:08:25,820 --> 00:08:29,598 if you want to specifically download through the URL. 159 00:08:29,754 --> 00:08:33,966 This curl and ping commands are very useful. 160 00:08:34,158 --> 00:08:38,130 Also a lot of people in interview 161 00:08:38,250 --> 00:08:41,378 would ask tell me the commands or 162 00:08:41,404 --> 00:08:43,230 different ways that you could troubleshoot. 163 00:08:43,289 --> 00:08:46,741 If a server A cannot reach server B, then you 164 00:08:46,756 --> 00:08:49,278 could simply mention that you're going to use the ping 165 00:08:49,313 --> 00:08:50,933 command, you're going to use the curl command. 166 00:08:50,982 --> 00:08:53,534 If it's a web URL, you're going to use 167 00:08:53,572 --> 00:08:58,154 different commands to check it also going back to 168 00:08:58,192 --> 00:09:02,354 ping if you are paying Google and you will 169 00:09:02,392 --> 00:09:06,438 notice that this is going to ping continuously. 170 00:09:06,534 --> 00:09:09,726 Now sometimes if you are on Windows machine 171 00:09:09,858 --> 00:09:12,042 and you try ping Google, it will ping 172 00:09:12,066 --> 00:09:13,634 it three times and will stop. 173 00:09:13,792 --> 00:09:16,050 So to use that ping on a Windows machine, 174 00:09:16,110 --> 00:09:18,902 you would have to, I believe, use the option 175 00:09:18,976 --> 00:09:23,150 minus s or minus t, one of those options. 176 00:09:23,200 --> 00:09:24,460 So please try it. 177 00:09:25,930 --> 00:09:27,638 I'm very sure that it's one of 178 00:09:27,664 --> 00:09:30,266 the minus t or minus s option. 179 00:09:30,388 --> 00:09:31,958 I'm sorry, I don't have the 180 00:09:31,984 --> 00:09:35,066 exact option remember right now. But try those. 181 00:09:35,128 --> 00:09:38,150 So it will ping continuously and you will see that 182 00:09:38,200 --> 00:09:42,338 packets are dropped or how long it's taking for the 183 00:09:42,364 --> 00:09:45,170 ping to go into ping and come back. 184 00:09:45,340 --> 00:09:48,222 So these are the two basic commands 185 00:09:48,246 --> 00:09:50,198 that I wanted to cover with. 186 00:09:50,224 --> 00:09:53,630 You try them out and just 187 00:09:53,680 --> 00:09:55,160 play around with it all right. 188 00:09:55,160 --> 00:09:56,950 [No audio]