1 00:00:00,290 --> 00:00:01,750 Okay, so let's have a look 2 00:00:01,750 --> 00:00:03,680 at the behaviors of IP in AWS. 3 00:00:03,680 --> 00:00:07,900 So we have a public IPv4 for our instance 4 00:00:07,900 --> 00:00:11,031 and this is the IPv4 we can use through SSH 5 00:00:11,031 --> 00:00:12,350 into our machine. 6 00:00:12,350 --> 00:00:13,930 And it works great, okay? 7 00:00:13,930 --> 00:00:15,960 So once we're logged in, remember, we see 8 00:00:15,960 --> 00:00:18,490 that there is a private IP attached 9 00:00:18,490 --> 00:00:20,170 as the host name of my instance. 10 00:00:20,170 --> 00:00:22,590 So once we are in, we can start using the private IP, 11 00:00:22,590 --> 00:00:25,510 but if we disconnect from our instance 12 00:00:25,510 --> 00:00:27,280 and we try to do the SSH command 13 00:00:27,280 --> 00:00:30,440 but this time using the private IPv4 address, 14 00:00:30,440 --> 00:00:32,360 as we can see, it will not work. 15 00:00:32,360 --> 00:00:34,030 Why? Well, let's have a look. 16 00:00:34,030 --> 00:00:35,120 So I'm going to press Enter. 17 00:00:35,120 --> 00:00:37,290 As you can see, this does not work, and why? 18 00:00:37,290 --> 00:00:40,760 Well, private IPv4s belong to a private network 19 00:00:40,760 --> 00:00:42,030 but right now I'm not connected 20 00:00:42,030 --> 00:00:43,383 to the private network of AWS. 21 00:00:43,383 --> 00:00:46,400 I can only connect to AWS for the internet. 22 00:00:46,400 --> 00:00:48,540 And this is why private IPs do not work. 23 00:00:48,540 --> 00:00:50,330 And this is why you have to use a public IP 24 00:00:50,330 --> 00:00:53,670 because the public IP allows you to access AWS 25 00:00:53,670 --> 00:00:55,640 from a public network, 26 00:00:55,640 --> 00:00:58,840 and therefore the public network being the internet. 27 00:00:58,840 --> 00:00:59,780 Okay. 28 00:00:59,780 --> 00:01:02,270 So now let's have a look at the behavior of our instance, 29 00:01:02,270 --> 00:01:05,798 just to observe it once when we stop it and restart. 30 00:01:05,798 --> 00:01:08,430 So we're going to stop our instance. 31 00:01:08,430 --> 00:01:10,040 And the instance is now stopping. 32 00:01:10,040 --> 00:01:13,750 And let's just save the IPv4 address right here 33 00:01:13,750 --> 00:01:16,370 just to have it on my screen. 34 00:01:16,370 --> 00:01:18,790 So we're going to stop our instance. 35 00:01:18,790 --> 00:01:20,390 So my instance is now stopped 36 00:01:20,390 --> 00:01:23,430 and I'm going to start my instance, 37 00:01:23,430 --> 00:01:25,960 which is different, by the way, from rebooting an instance. 38 00:01:25,960 --> 00:01:28,730 So you need to stop and start the instance 39 00:01:28,730 --> 00:01:31,750 to observe the behavior of the public IPv4 changing. 40 00:01:31,750 --> 00:01:35,673 So now that I've stopped it and started it, 41 00:01:36,560 --> 00:01:39,840 in a few seconds, we're going to obtain a new public IPv4. 42 00:01:39,840 --> 00:01:40,860 So here we go. 43 00:01:40,860 --> 00:01:44,040 This one right here, I'm going to copy it and paste it here. 44 00:01:44,040 --> 00:01:48,000 As you can see, yes, indeed, in this console, 45 00:01:48,000 --> 00:01:49,270 the two IPs are different. 46 00:01:49,270 --> 00:01:52,690 So if I use the previous IP through SSH, 47 00:01:52,690 --> 00:01:54,010 this is not going to go anywhere 48 00:01:54,010 --> 00:01:56,810 because my instance has changed its IPv4. 49 00:01:56,810 --> 00:02:00,740 But if I use the new IP to do my SSH command, 50 00:02:00,740 --> 00:02:03,290 then I can SSH again in my instance, 51 00:02:03,290 --> 00:02:05,020 but the private IP has not changed 52 00:02:05,020 --> 00:02:06,730 because it doesn't need to. 53 00:02:06,730 --> 00:02:09,210 Okay, so how do we solve this problem? 54 00:02:09,210 --> 00:02:11,510 Because maybe we want to stop and start our instance, 55 00:02:11,510 --> 00:02:14,240 but we don't want the public IPv4 to change. 56 00:02:14,240 --> 00:02:17,220 In this case, what we have to use is an Elastic IP. 57 00:02:17,220 --> 00:02:21,240 So right now you see Elastic IP addresses is zero. 58 00:02:21,240 --> 00:02:23,820 So on the left-hand side, you can find Elastic IPs. 59 00:02:23,820 --> 00:02:25,890 I'm going to open this in a new tab 60 00:02:25,890 --> 00:02:28,850 and we're going to allocate a new IP address 61 00:02:28,850 --> 00:02:31,630 from Amazon's pool of IPv4 address. 62 00:02:31,630 --> 00:02:34,880 And what this will do is that it will create an IPv4 address 63 00:02:34,880 --> 00:02:37,960 that we own now, at least for the time we rent it. 64 00:02:37,960 --> 00:02:42,240 And this can be allocated to a specific EC2 instance 65 00:02:42,240 --> 00:02:45,820 and it will keep the Elastic IP as long as it's attached. 66 00:02:45,820 --> 00:02:48,040 So, with Elastic IP addresses, 67 00:02:48,040 --> 00:02:50,870 you are charged as long as you don't use them. 68 00:02:50,870 --> 00:02:52,640 So we need to attach it as soon as possible, 69 00:02:52,640 --> 00:02:53,590 otherwise we will be charged. 70 00:02:53,590 --> 00:02:57,300 So for this, we can right-click or we can do Action 71 00:02:57,300 --> 00:03:00,780 and Associate Elastic IP address. 72 00:03:00,780 --> 00:03:01,800 So if we do so, 73 00:03:01,800 --> 00:03:03,590 then we need to say what we want to attach it to. 74 00:03:03,590 --> 00:03:06,060 So, is it an instance or a network interface? 75 00:03:06,060 --> 00:03:08,120 So it's going to be an instance. 76 00:03:08,120 --> 00:03:10,640 And I'm going to choose the instance that is running 77 00:03:10,640 --> 00:03:12,790 and then the private IP 78 00:03:12,790 --> 00:03:14,910 to which to associate the Elastic IP address. 79 00:03:14,910 --> 00:03:16,670 So there's only one private IP for my instance. 80 00:03:16,670 --> 00:03:17,980 So we're good to go. 81 00:03:17,980 --> 00:03:19,070 Okay. 82 00:03:19,070 --> 00:03:20,843 So we associate it. 83 00:03:22,490 --> 00:03:24,290 And now let's have a look at what happens. 84 00:03:24,290 --> 00:03:26,800 So if you go back to our EC2 instance, 85 00:03:26,800 --> 00:03:30,340 I'm going to refresh this window and close this. 86 00:03:30,340 --> 00:03:35,010 So as you can see now, the public IPv4 address is now equal 87 00:03:35,010 --> 00:03:37,140 to the value of the elastic IP address. 88 00:03:37,140 --> 00:03:41,963 And if I scroll down and refresh this fully, 89 00:03:44,920 --> 00:03:47,650 as we can see now, the Elastic IP addresses field 90 00:03:47,650 --> 00:03:49,770 also has an Elastic IP address right here, 91 00:03:49,770 --> 00:03:50,950 which is a public address. 92 00:03:50,950 --> 00:03:53,910 And now we can click on this Elastic IP. 93 00:03:53,910 --> 00:03:55,290 And this takes us directly 94 00:03:55,290 --> 00:03:59,030 into the Elastic IP console from EC2 95 00:03:59,030 --> 00:04:00,520 where we can get some more information 96 00:04:00,520 --> 00:04:02,330 around this Elastic IP. 97 00:04:02,330 --> 00:04:03,350 So this is good. 98 00:04:03,350 --> 00:04:04,890 So now let's have a look and see if that works. 99 00:04:04,890 --> 00:04:08,280 So we're going to copy the address right here 100 00:04:09,280 --> 00:04:10,920 and I'm going to run the SSH command. 101 00:04:10,920 --> 00:04:13,430 And this one will not work, so we have to use a new one. 102 00:04:13,430 --> 00:04:16,959 And yes, indeed, we can do an SSH right now 103 00:04:16,959 --> 00:04:18,610 in case we stop the instance. 104 00:04:18,610 --> 00:04:22,343 So let's stop this instance and see what happens. 105 00:04:24,070 --> 00:04:26,700 So as we can see now, the instance is in stopped state 106 00:04:26,700 --> 00:04:28,760 but it still has a public IPv4 107 00:04:28,760 --> 00:04:31,560 because the Elastic IP is still attached to it. 108 00:04:31,560 --> 00:04:34,463 So that means that if we start our instance again, 109 00:04:35,970 --> 00:04:38,420 then our instance is back in the running state 110 00:04:38,420 --> 00:04:40,650 and the Elastic IP address is still attached 111 00:04:40,650 --> 00:04:42,590 and the public IPv4 has not changed. 112 00:04:42,590 --> 00:04:44,160 So we can also check this 113 00:04:44,160 --> 00:04:45,850 by doing one more time the SSH command. 114 00:04:45,850 --> 00:04:48,490 And yes, it works using the same command as before. 115 00:04:48,490 --> 00:04:51,770 So if you finish this, we can go into this Elastic IP 116 00:04:51,770 --> 00:04:56,770 and we can disassociate it to remove it from our instance. 117 00:04:56,940 --> 00:04:58,900 And then, do not leave it running. 118 00:04:58,900 --> 00:05:01,440 Please make sure to release this Elastic IP address. 119 00:05:01,440 --> 00:05:03,540 It's not build for it. 120 00:05:03,540 --> 00:05:06,300 And then back into our EC2 instance, if we refresh it, 121 00:05:06,300 --> 00:05:08,340 it has obtained a new public IPv4 address 122 00:05:08,340 --> 00:05:11,300 because it has been released from the Elastic IP. 123 00:05:11,300 --> 00:05:12,320 And to finish this hands-on, 124 00:05:12,320 --> 00:05:15,480 I can just terminate my instance and be good to go. 125 00:05:15,480 --> 00:05:16,580 So that's it for this lecture. 126 00:05:16,580 --> 00:05:17,413 I hope you liked it. 127 00:05:17,413 --> 00:05:19,360 And I will see you in the next lecture.