1 00:00:00,090 --> 00:00:01,020 In this lesson, 2 00:00:01,020 --> 00:00:01,853 we're going to discuss 3 00:00:01,853 --> 00:00:03,810 some network port fundamentals. 4 00:00:03,810 --> 00:00:05,939 Now, when we transfer data over our networks, 5 00:00:05,939 --> 00:00:07,650 we have to find a way to tell the data 6 00:00:07,650 --> 00:00:08,880 where it's going. 7 00:00:08,880 --> 00:00:10,890 Now we can use IP addresses to get data 8 00:00:10,890 --> 00:00:13,080 to the right system, but how does it know 9 00:00:13,080 --> 00:00:14,490 what application is listening 10 00:00:14,490 --> 00:00:16,230 on that particular system? 11 00:00:16,230 --> 00:00:18,780 Well, this is where ports come into play. 12 00:00:18,780 --> 00:00:20,310 I like to think about it this way. 13 00:00:20,310 --> 00:00:21,750 If I give you my street address 14 00:00:21,750 --> 00:00:24,180 that's like my IP address on my computer. 15 00:00:24,180 --> 00:00:25,710 You'll be able to find my exact house 16 00:00:25,710 --> 00:00:26,850 within my neighborhood. 17 00:00:26,850 --> 00:00:28,890 But how are you going to find my bedroom, 18 00:00:28,890 --> 00:00:30,900 my home office, or my living room? 19 00:00:30,900 --> 00:00:31,740 Each of those rooms 20 00:00:31,740 --> 00:00:33,240 is going to serve a different function 21 00:00:33,240 --> 00:00:35,880 like sleeping, working, or relaxing. 22 00:00:35,880 --> 00:00:38,550 Now, this is where a port comes into play. 23 00:00:38,550 --> 00:00:40,920 A port is a logical opening in a computer 24 00:00:40,920 --> 00:00:42,600 that represents a service or application 25 00:00:42,600 --> 00:00:44,670 that's listening and waiting for traffic. 26 00:00:44,670 --> 00:00:46,860 So in the example of my house, 27 00:00:46,860 --> 00:00:48,060 if I give you my address 28 00:00:48,060 --> 00:00:50,940 at 123 Main Street, room number two, 29 00:00:50,940 --> 00:00:52,770 this tells you to go to the house located 30 00:00:52,770 --> 00:00:56,160 at 123 Main Street and then enter the second room, 31 00:00:56,160 --> 00:00:57,390 which is my home office 32 00:00:57,390 --> 00:00:59,070 where I'm going to be working at. 33 00:00:59,070 --> 00:01:00,360 Now, in computer networks, 34 00:01:00,360 --> 00:01:02,580 all ports are going to be numbered from zero 35 00:01:02,580 --> 00:01:06,360 all the way up to 65,535. 36 00:01:06,360 --> 00:01:08,520 Now that is a lot of ports, 37 00:01:08,520 --> 00:01:10,800 so even though you only have one IP address 38 00:01:10,800 --> 00:01:12,240 on your machine, you can have 39 00:01:12,240 --> 00:01:15,720 over 65,535 different openings for you 40 00:01:15,720 --> 00:01:17,070 to be able to run different services 41 00:01:17,070 --> 00:01:18,750 and applications on. 42 00:01:18,750 --> 00:01:20,100 Now, that large number of ports 43 00:01:20,100 --> 00:01:22,129 is actually going to be broken down 44 00:01:22,129 --> 00:01:23,730 into three different groups or categories. 45 00:01:23,730 --> 00:01:25,620 We call these the well-known ports, 46 00:01:25,620 --> 00:01:28,530 the registered ports, and the ephemeral ports. 47 00:01:28,530 --> 00:01:30,870 Now first we have well-known ports. 48 00:01:30,870 --> 00:01:32,310 These well-known ports are numbered 49 00:01:32,310 --> 00:01:35,070 from zero to 1,023. 50 00:01:35,070 --> 00:01:37,020 These ports include well-known services 51 00:01:37,020 --> 00:01:38,730 like the File Transfer Protocol, 52 00:01:38,730 --> 00:01:41,190 which exists on ports 20 and 21, 53 00:01:41,190 --> 00:01:42,840 the Simple Mail Transfer Protocol, 54 00:01:42,840 --> 00:01:44,640 which operates on Port 25, 55 00:01:44,640 --> 00:01:47,400 web browsing on port 80 and secure web browsing 56 00:01:47,400 --> 00:01:51,030 on Port 443 among many others. 57 00:01:51,030 --> 00:01:53,220 Second, we have registered ports. 58 00:01:53,220 --> 00:01:54,750 Now registered ports are numbered 59 00:01:54,750 --> 00:01:59,550 from 1,024 to 49,151. 60 00:01:59,550 --> 00:02:00,990 Now both our well-known ports 61 00:02:00,990 --> 00:02:02,520 and our reserve ports are actually going to 62 00:02:02,520 --> 00:02:04,680 be registered with an organization known 63 00:02:04,680 --> 00:02:06,630 as the Internet Assigned Numbers Authority 64 00:02:06,630 --> 00:02:09,900 or IANA pronounced iyana. 65 00:02:09,900 --> 00:02:12,000 So if you go on to create a new video game 66 00:02:12,000 --> 00:02:13,890 and you want to reserve the registered port 67 00:02:13,890 --> 00:02:17,100 of 33,333 for your game to communicate 68 00:02:17,100 --> 00:02:18,540 with other systems over, 69 00:02:18,540 --> 00:02:19,590 you're going to have to request 70 00:02:19,590 --> 00:02:20,850 that port to be reserved 71 00:02:20,850 --> 00:02:23,970 for your organization's use through IANA. 72 00:02:23,970 --> 00:02:26,190 Third, we have ephemeral ports. 73 00:02:26,190 --> 00:02:27,060 Now, ephemeral ports 74 00:02:27,060 --> 00:02:28,890 are short-lived temporary ports, 75 00:02:28,890 --> 00:02:30,540 which are open just for a short period 76 00:02:30,540 --> 00:02:33,150 of time from a predefined range of ports. 77 00:02:33,150 --> 00:02:34,620 You may also hear ephemeral ports 78 00:02:34,620 --> 00:02:36,930 called dynamic ports or private ports 79 00:02:36,930 --> 00:02:38,850 because these ports can be used by anyone 80 00:02:38,850 --> 00:02:41,400 or any system without having to request them 81 00:02:41,400 --> 00:02:42,630 like you would with a well-known 82 00:02:42,630 --> 00:02:44,130 or registered port. 83 00:02:44,130 --> 00:02:46,650 Ephemeral ports consists of any ports numbered 84 00:02:46,650 --> 00:02:50,837 from 49,152 all the way up to 65,535. 85 00:02:53,460 --> 00:02:55,860 For example, as I'm recording this lesson, 86 00:02:55,860 --> 00:02:57,450 I record the audio on a device, 87 00:02:57,450 --> 00:02:59,040 which acts as a file server 88 00:02:59,040 --> 00:03:00,930 and it's going to pick a random port somewhere 89 00:03:00,930 --> 00:03:03,570 around Port 60,000 for me to use. 90 00:03:03,570 --> 00:03:05,400 Now when I want to download the audio file 91 00:03:05,400 --> 00:03:07,560 from that device, I'm going to go to the web browser 92 00:03:07,560 --> 00:03:08,940 on my computer, and then I'll type 93 00:03:08,940 --> 00:03:11,250 in the IP address of that device as well 94 00:03:11,250 --> 00:03:13,020 as the port number that it chose. 95 00:03:13,020 --> 00:03:14,760 That way I can download that audio 96 00:03:14,760 --> 00:03:17,550 using my web browser to my main computer. 97 00:03:17,550 --> 00:03:19,620 Now, when I do this, what really happens is 98 00:03:19,620 --> 00:03:20,700 that I'm opening up a port 99 00:03:20,700 --> 00:03:22,110 on the recording device 100 00:03:22,110 --> 00:03:23,400 just for as long as I need it 101 00:03:23,400 --> 00:03:24,780 so I can download the file 102 00:03:24,780 --> 00:03:27,540 and then that port is going to close up again. 103 00:03:27,540 --> 00:03:29,250 Now, whenever we're doing data transfer, 104 00:03:29,250 --> 00:03:30,930 we're going to have to have an IP address 105 00:03:30,930 --> 00:03:32,070 and a port. 106 00:03:32,070 --> 00:03:34,290 This way we know what system we want to go to 107 00:03:34,290 --> 00:03:35,970 and what service or application 108 00:03:35,970 --> 00:03:38,250 on that system we want to communicate with. 109 00:03:38,250 --> 00:03:40,950 So what does this look like in the real world? 110 00:03:40,950 --> 00:03:42,660 Well, let's say I have a client 111 00:03:42,660 --> 00:03:43,920 and I have a website. 112 00:03:43,920 --> 00:03:48,780 The client address is going to be 192.168.1.24, 113 00:03:48,780 --> 00:03:51,253 and the website is going to be at 64.82.46.21. 114 00:03:54,360 --> 00:03:56,160 So for the client to make a request 115 00:03:56,160 --> 00:03:57,150 to this website, 116 00:03:57,150 --> 00:03:58,890 it's going to go from the source IP, 117 00:03:58,890 --> 00:04:01,740 that 192 address, and a port number, 118 00:04:01,740 --> 00:04:03,600 which is just going to be some random high port 119 00:04:03,600 --> 00:04:04,433 that we're going to pick 120 00:04:04,433 --> 00:04:06,060 from the ephemeral port range randomly 121 00:04:06,060 --> 00:04:07,320 by our system. 122 00:04:07,320 --> 00:04:12,240 Now in this case, we see port number 49,163, 123 00:04:12,240 --> 00:04:14,010 but it could have been any of the ephemeral port. 124 00:04:14,010 --> 00:04:15,060 It really doesn't matter 125 00:04:15,060 --> 00:04:17,160 because they're randomly selected. 126 00:04:17,160 --> 00:04:19,048 Now what we're going to do is take that data 127 00:04:19,048 --> 00:04:20,820 and we're going to set it to the destination 128 00:04:20,820 --> 00:04:22,170 of our website, which is going 129 00:04:22,170 --> 00:04:23,220 to be the IP address 130 00:04:23,220 --> 00:04:26,010 of 64 dot something dot something dot something 131 00:04:26,010 --> 00:04:27,750 that you see here on the web server. 132 00:04:27,750 --> 00:04:30,030 This will be our destination IP. 133 00:04:30,030 --> 00:04:31,890 Now, what port do you think it's going to send 134 00:04:31,890 --> 00:04:34,200 that data to on the web server? 135 00:04:34,200 --> 00:04:36,780 Well, if we're browsing an insecure website, 136 00:04:36,780 --> 00:04:38,130 we're going to use port 80, 137 00:04:38,130 --> 00:04:40,020 which is the default for that. 138 00:04:40,020 --> 00:04:42,150 So when the website receives the request, 139 00:04:42,150 --> 00:04:43,740 it's then going to reverse this process 140 00:04:43,740 --> 00:04:45,840 by sending data from its source IP, 141 00:04:45,840 --> 00:04:48,330 which is at 64 dot something IP address, 142 00:04:48,330 --> 00:04:50,910 and it's well-known port of Port 80. 143 00:04:50,910 --> 00:04:52,410 Then it's going to send that over 144 00:04:53,278 --> 00:04:54,810 to the destination IP, which is the IP address 145 00:04:54,810 --> 00:04:55,980 of the client, which started 146 00:04:55,980 --> 00:04:58,770 with 192 dot something dot something dot something 147 00:04:58,770 --> 00:05:00,690 and the port number that the client first used 148 00:05:00,690 --> 00:05:02,640 to initiate this communication session, 149 00:05:02,640 --> 00:05:03,630 which in this case was 150 00:05:03,630 --> 00:05:08,630 that randomly picked ephemeral port of 49,163. 151 00:05:08,670 --> 00:05:10,800 Now, at this point, we have two-way communication 152 00:05:10,800 --> 00:05:12,480 established between the web server coming 153 00:05:12,480 --> 00:05:17,370 from Port 80 and the client on port 49,163, 154 00:05:17,370 --> 00:05:18,480 and the client will send data 155 00:05:18,480 --> 00:05:22,500 from port 49,163 back to the web server 156 00:05:22,500 --> 00:05:24,090 over port 80. 157 00:05:24,090 --> 00:05:25,800 Whenever we're done transmitting data back 158 00:05:25,800 --> 00:05:28,260 and forth, then the session will be torn down 159 00:05:28,260 --> 00:05:29,850 and that random ephemeral port 160 00:05:29,850 --> 00:05:31,170 will actually be closed, 161 00:05:31,170 --> 00:05:32,370 and that way we can move on 162 00:05:32,370 --> 00:05:34,740 to the next communication session. 163 00:05:34,740 --> 00:05:36,360 Now, next time the client wants to go ahead 164 00:05:36,360 --> 00:05:37,740 and communicate the web server, 165 00:05:37,740 --> 00:05:39,720 it's still going to send the data to port 80 166 00:05:39,720 --> 00:05:41,490 because that is a well-known port, 167 00:05:41,490 --> 00:05:42,960 and the server will always be listening 168 00:05:42,960 --> 00:05:45,180 on port 80, but the client 169 00:05:45,180 --> 00:05:47,400 will now pick a new randomly generated 170 00:05:47,400 --> 00:05:49,500 ephemeral port for it to send the data from, 171 00:05:49,500 --> 00:05:51,660 and it will use that random ephemeral port 172 00:05:51,660 --> 00:05:53,310 to listen to any responses coming 173 00:05:53,310 --> 00:05:56,010 from the web server from Port 80 as well. 174 00:05:56,010 --> 00:05:58,290 So remember, when we talk about a port, 175 00:05:58,290 --> 00:06:00,570 a port is a logical opening in a computer 176 00:06:00,570 --> 00:06:01,590 that represents a service 177 00:06:01,590 --> 00:06:03,180 or application that's listening 178 00:06:03,180 --> 00:06:05,850 and waiting for communication or traffic. 179 00:06:05,850 --> 00:06:07,560 As we used in the house example, 180 00:06:07,560 --> 00:06:08,820 we have the IP address, 181 00:06:08,820 --> 00:06:10,200 which represents the building, 182 00:06:10,200 --> 00:06:11,160 but then we use the port, 183 00:06:11,160 --> 00:06:13,290 which represents the door for specific room 184 00:06:13,290 --> 00:06:14,970 inside of that building. 185 00:06:14,970 --> 00:06:16,440 It's the same thing logically 186 00:06:16,440 --> 00:06:18,907 inside of a computer, your IP address says, 187 00:06:18,907 --> 00:06:19,770 "This is the server 188 00:06:19,770 --> 00:06:21,600 or client I want to communicate with," 189 00:06:21,600 --> 00:06:23,820 and your port number says, "This is the application 190 00:06:23,820 --> 00:06:25,770 or service I want to communicate with 191 00:06:25,770 --> 00:06:27,567 on that given server or client."