In this lesson,
we're going to discuss
some network port fundamentals.
Now, when we transfer data over our networks,
we have to find a way to tell the data
where it's going.
Now we can use IP addresses to get data
to the right system, but how does it know
what application is listening
on that particular system?
Well, this is where ports come into play.
I like to think about it this way.
If I give you my street address
that's like my IP address on my computer.
You'll be able to find my exact house
within my neighborhood.
But how are you going to find my bedroom,
my home office, or my living room?
Each of those rooms
is going to serve a different function
like sleeping, working, or relaxing.
Now, this is where a port comes into play.
A port is a logical opening in a computer
that represents a service or application
that's listening and waiting for traffic.
So in the example of my house,
if I give you my address
at 123 Main Street, room number two,
this tells you to go to the house located
at 123 Main Street and then enter the second room,
which is my home office
where I'm going to be working at.
Now, in computer networks,
all ports are going to be numbered from zero
all the way up to 65,535.
Now that is a lot of ports,
so even though you only have one IP address
on your machine, you can have
over 65,535 different openings for you
to be able to run different services
and applications on.
Now, that large number of ports
is actually going to be broken down
into three different groups or categories.
We call these the well-known ports,
the registered ports, and the ephemeral ports.
Now first we have well-known ports.
These well-known ports are numbered
from zero to 1,023.
These ports include well-known services
like the File Transfer Protocol,
which exists on ports 20 and 21,
the Simple Mail Transfer Protocol,
which operates on Port 25,
web browsing on port 80 and secure web browsing
on Port 443 among many others.
Second, we have registered ports.
Now registered ports are numbered
from 1,024 to 49,151.
Now both our well-known ports
and our reserve ports are actually going to
be registered with an organization known
as the Internet Assigned Numbers Authority
or IANA pronounced iyana.
So if you go on to create a new video game
and you want to reserve the registered port
of 33,333 for your game to communicate
with other systems over,
you're going to have to request
that port to be reserved
for your organization's use through IANA.
Third, we have ephemeral ports.
Now, ephemeral ports
are short-lived temporary ports,
which are open just for a short period
of time from a predefined range of ports.
You may also hear ephemeral ports
called dynamic ports or private ports
because these ports can be used by anyone
or any system without having to request them
like you would with a well-known
or registered port.
Ephemeral ports consists of any ports numbered
from 49,152 all the way up to 65,535.
For example, as I'm recording this lesson,
I record the audio on a device,
which acts as a file server
and it's going to pick a random port somewhere
around Port 60,000 for me to use.
Now when I want to download the audio file
from that device, I'm going to go to the web browser
on my computer, and then I'll type
in the IP address of that device as well
as the port number that it chose.
That way I can download that audio
using my web browser to my main computer.
Now, when I do this, what really happens is
that I'm opening up a port
on the recording device
just for as long as I need it
so I can download the file
and then that port is going to close up again.
Now, whenever we're doing data transfer,
we're going to have to have an IP address
and a port.
This way we know what system we want to go to
and what service or application
on that system we want to communicate with.
So what does this look like in the real world?
Well, let's say I have a client
and I have a website.
The client address is going to be 192.168.1.24,
and the website is going to be at 64.82.46.21.
So for the client to make a request
to this website,
it's going to go from the source IP,
that 192 address, and a port number,
which is just going to be some random high port
that we're going to pick
from the ephemeral port range randomly
by our system.
Now in this case, we see port number 49,163,
but it could have been any of the ephemeral port.
It really doesn't matter
because they're randomly selected.
Now what we're going to do is take that data
and we're going to set it to the destination
of our website, which is going
to be the IP address
of 64 dot something dot something dot something
that you see here on the web server.
This will be our destination IP.
Now, what port do you think it's going to send
that data to on the web server?
Well, if we're browsing an insecure website,
we're going to use port 80,
which is the default for that.
So when the website receives the request,
it's then going to reverse this process
by sending data from its source IP,
which is at 64 dot something IP address,
and it's well-known port of Port 80.
Then it's going to send that over
to the destination IP, which is the IP address
of the client, which started
with 192 dot something dot something dot something
and the port number that the client first used
to initiate this communication session,
which in this case was
that randomly picked ephemeral port of 49,163.
Now, at this point, we have two-way communication
established between the web server coming
from Port 80 and the client on port 49,163,
and the client will send data
from port 49,163 back to the web server
over port 80.
Whenever we're done transmitting data back
and forth, then the session will be torn down
and that random ephemeral port
will actually be closed,
and that way we can move on
to the next communication session.
Now, next time the client wants to go ahead
and communicate the web server,
it's still going to send the data to port 80
because that is a well-known port,
and the server will always be listening
on port 80, but the client
will now pick a new randomly generated
ephemeral port for it to send the data from,
and it will use that random ephemeral port
to listen to any responses coming
from the web server from Port 80 as well.
So remember, when we talk about a port,
a port is a logical opening in a computer
that represents a service
or application that's listening
and waiting for communication or traffic.
As we used in the house example,
we have the IP address,
which represents the building,
but then we use the port,
which represents the door for specific room
inside of that building.
It's the same thing logically
inside of a computer, your IP address says,
"This is the server
or client I want to communicate with,"
and your port number says, "This is the application
or service I want to communicate with
on that given server or client."