Submitted by Brianprokpo456 t3_zx7osk in explainlikeimfive

I've always seen it on some devices and games (like terraria) where you specifically have to configure the port too so that you can successfully connect a server. But never truly understood what it was.

Similarly I never understood wether a port is represented by data inside the computer that associates something to something or if for every port there is a specific cable/wire that transmits only the information from that port or if a port is just a medium of input in the computer.

37

Comments

You must log in or register to comment.

FriedMule t1_j1yt2qp wrote

Imagine a giant mid evil city with walls all around and some ports that either are open, closed, locked and even hidden.

Some of these ports are dedicated to particular functions. Port 80 in for the normal internet, but there are also a lot of other ports.

Configuration a port would be like setting up what it shall be used for, if it needs to be from open and right up to hidden and locked.

0

pauliebb t1_j1yu6px wrote

Imagine a city has many pathways in and out... Leading to different cities for trading or entertainment etc.

Now imagine all these pathways are closed, you can choose to open them for access into or out of the city.

But the more you open the more likely the city is going to be attacked by something you wouldn't want in your city.

2

KrakenOfLakeZurich t1_j1yuiea wrote

Think of it like a big building with many apartments. The building has a street address. That is basically equivalent to the IP address of your computer.

But since there can be many tenants (services) in the same building, you also need to know the apartment number.

More technical explanation: Many services (e.g. email server, web server, file server, print server, etc.) can be running on the same computer, sharing the same network interface and therefore the same IP address.

To keep those apart, each service is listening on a different port (e.g. `25` for email, `80` for web server, etc.). When you send a TCP/IP message, you have to specify the recipients IP address, but also the port on which the message is to be received.

Ports are a logical concept. They physically use the same cable as all other messages. It's just an additional number encoded in the TCP/IP package. When your operating systems network stack receives such a message, it will read the port number and forward the message to whichever service (tenant) is currently holding that port.

106

sterlingphoenix t1_j1yukqy wrote

As an IT professional, when you say "Network port" I think it's the physical port on the computer you plug the network cable in. E.g., the ethernet port.

If you're asking "What is a port in networking terms?" that gets asked pretty often, but the bottom line is that you have one network cable and one network address, but you can run multiple services on that connection, and ports are used to differentiate them.

So the software on the connecting side will go "Hey, I'm trying to talk to port 443" and the networking software on the target will go "hey someone's trying to reach port 443, anyone listening to that?" and a piece of software (in this case, the web server) will say "Oh yeah that's me."

0

Schnutzel t1_j1yv3pi wrote

A port is a 16-bit number, i.e. from 0 to 65535.

0 is a special number (so not actually used as a port) and certain ports are commonly used by certain protocols (for example 80 is for HTTP, 443 for HTTPS, 22 for SSH), but most are free for use.

1

icydee t1_j1yvee6 wrote

Think of it like a big apartment block with a single letter delivery address. Each room in the apartment is identified by a number 0 to 65535 and any incoming letter is sent to that room.

Any incoming letters with address 80 go to apartment 80. Now apartment 80 may be unoccupied in which case the letter is ignored. However it is agreed that by convention apartment 80 is the home of the HTTP application, that knows how to read and process that letter, and send back a reply letter to the sender.

Other applications have their preferred room number, to make it easier to communicate with, simple email prefers room 25, file transfer is greedy and needs two rooms, 20 and 21. Etc.

These common applications prefer the ground floor rooms, 0 to 1023 so it usually means that they have to have special permission from the building supervisor to move in.

Of course there is nothing stopping applications taking other room numbers, you will sometimes find HTTP also in room 8080 but any number is possible from 1024 to 49151 and applications are free to move in to any room so long as it’s not already occupied. Terraria likes the view from room 7777 and tries to move in there (and because it’s users have difficulty remembering their room number otherwise!)

All the rooms on the top floors, 49152 to 65535 are available to be used by applications dynamically, think of them as Airbnb rooms, use them for a short while then move out and let someone else use them.

8

Brianprokpo456 OP t1_j1ywal0 wrote

Thanks. This was the answer I understood the most. And honestly I didn't expect such a quick response. So thank you!

So in the end it is just a way to transmit information from one point to another by the same cable but without getting things awfully mixed.

30

andouconfectionery t1_j1yweo1 wrote

Port numbers are used to distinguish TCP connections between two IP addresses. Without this extra number, you could only have one connection between any two IP addresses at one time. They can take any value between 0 and 65535.

The computer you're connecting to may have a Terraria server and a Minecraft server running on it at the same time. You need to specify the destination port number so the game traffic knows where to go once it gets to that computer.

In addition, your computer assigns a source port number to that connection. This is in case you also have Minecraft running and connect to that same computer. When you get data back, it'll send that data to the right program on your computer based on the source port.

1

BaconReceptacle t1_j1z8g8x wrote

Yes, and the ports exist at layer 4 of the transmission protocol. So it's not hardware related at all. They exist in the headers (just a few bits) of the packets that are being sent back and forth. So, to continue the example above, the ports are not a component of the apartments themselves, it's just written on the envelope of any mail or packages sent to and from those apartments.

14

Psyese t1_j1zokwj wrote

It's a number that the computer expects incomming data packets to specify for specific destinations. It lets computer know which running program to send the packet to. There's many programs that simultaneously run on a computer. It is not omniscient, it needs a number to know where to send the packet further.

When a country receives a phone call, they need a specific phone number to know which person to connect. Phone number in this case is like a port. And country like a computer.

2

insultant_ t1_j1zyqgd wrote

Why can’t port numbers below 49152 act like “Airbnb for applications?” Conversely, why can’t port 49153 and above have, per your analogy, “long-term tenants.” Or can they?

Furthermore, what event on the server would be equivalent to “evicting” a program from its “apartment?”

1

stevekeiretsu t1_j1zz71q wrote

See here:

https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

In summary, the Internet Assigned Numbers Authority officially assigns certain ports for certain services, but in other cases it's just convention, and either way you are completely free to ignore it if you want. For example I'm a web developer and so I routinely run web servers on my laptop for local work, if you're running multiple for different projects you might stick them on 8080, 8081, whatever. Also sometimes people use non-standard ports as a form of security by obscurity. (To continue parent analogy somewhat, imagine if every apartment building was supposed to have a bank vault in apartment 762, it would make it kind of easy for thieves to find, so you might stick it in 638, and have an intermediary stationed at 762 to vet anybody who turns up and only forward known bank customers to the correct place)

11

DragonFireCK t1_j20a7hk wrote

>Why can’t port numbers below 49152 act like “Airbnb for applications?” Conversely, why can’t port 49153 and above have, per your analogy, “long-term tenants.” Or can they?

Convention - the same as why a hotel room generally won't have a long-term occupant and an apartment won't have a short-term renter. With that, its also likely somebody else may be using them for their intended purpose, thus causing random failures if an application tries to use them incorrectly.

Firewalls will also frequently block or allow specific ports by number, though they will normally only block incoming connections, not outgoing. This may cause a program using an unexpected port to get incorrectly blocked, requiring users to manually open those ports.

>Furthermore, what event on the server would be equivalent to “evicting” a program from its “apartment?”

Generally, the operating system will have a method of force disconnecting a socket, though such APIs are normally tightly restricted in usage. In most cases, they are restricted to usage by debugging tools.

2

SwirlySauce t1_j20fydi wrote

What happens when multiple services use the same port number?

1

metaphorm t1_j20i3uy wrote

A network port is a "channel" for information received over the network. Your computer has physical ports, where a wire is plugged in (or a wireless connection by radio in many cases), but this port is not the same thing as a port being referenced by software. From the perspective of software a network port is the location of a stream of data made available to the software by the operating system. The operating system takes the data coming in to the physical port and divides it up into thousands of different virtual locations that can be used by all the different software running on the system.

1

wappledilly t1_j20zwan wrote

Fun fact for anyone who gives a shit:

For standard mail access and transmission, ports 25 (SMTP, sending) and 143 (IMAP, receiving) have been largely replaced by 587/465 and 993 respectively to facilitate SSL/TLS encryption. In some cases IMAP is absent from primary use and may be disabled by default (Microsoft, where Exchange services are primary, and Google, where MAPI is heavily utilized), but are still available for compatibility purposes.

Some legacy services still utilize 25 for sending alerts, but most everything recent allows for SMTPS for mail-enabled services.

The more you know (cue the rainbow ->🌈)

4

interwebz_2021 t1_j210clo wrote

>socket

Just in case anyone's not seen the term 'socket' before: this is a logical address comprised of the IP address and port. So, for instance, if you have a web server listening on port 80 on your local loopback interface with IP address 127.0.0.1, you can connect to the webserver via the socket with address 127.0.0.1:80

3

bbqroast t1_j210p6p wrote

Applications that are waiting for anyone to mail them (i.e. server apps) need to "bind" a port and listen for traffic.

They generally do this on a specific port, this is so applications that want to talk to them can find them.

Applications that just want to start a chat with someone (i.e. client apps) can use a random one of the temporary ports as a return address for the duration of the correspondence.

If they use a port outside that range, then potentially they might prevent one of the applications that needs to listen to a specific port from starting (only one app can use a port at once). Likewise, if you decide to use a specific port in the temporary range, you run the risk it's randomly in use by someone else

2

interwebz_2021 t1_j210zsg wrote

Excellent description. I often use the metaphor of an apartment building's mailboxes with "the internet" (really, the network elements, obv) being the postal service, the building being the IP address and the mailboxes being the ports, mapped to services/programs. So far, it's worked pretty well. This also lets me extend the discussion to TCP vs UDP, where I compare UDP to simply mailing a letter and TCP to requiring a signature verifying receipt.

1

wappledilly t1_j2113qg wrote

Many ports are reserved for common functions (22 and 53 are always ssh and dns), but many are used for different things altogether (8080 for instance can be used for many different services across many different vendors/developers).

IANA maintains the list of reserved ports when dealing with internet, and can be found at their website (along with other lists such as top level domains, IP address allocation, etc.) https://iana.org/

2

egoalter t1_j228faf wrote

All communication on a TCP/IP network needs a socket pair for communication for destination and source. This means IP/PORT for both sender and receiver. They are equally important to make communication work because a computer representing an IP run more than one thing at a time, but each process that runs need a unique transmission pipe. That's the sender port. The destination is "what service" do you want - in general servers have many programs running to handle different incoming traffic. In other words, an IP by itself doesn't work. Just like the type of protocol can be different. Some protocols use different ways of addressing the service (such as ICMP) but in general the sender specifies what service the data is meant for.

A bit more technical, when you write server code that responds to incoming network traffic you bind/select a given port, telling the OS that traffic that comes in to this port is responded to by your process. Only ONE process can do this at a time. Some ports are restricted and a lot of ports have been standardized (see /etc/services on Linux) but to the computer the number is arbitrary. You can easily make your web-server respond to incoming requests to port 7777 if you want. It's just a number.

The sender's port number is very rarely specified manually (but you can). The OS provides a pool of free sender port numbers and assigns a "random" port number when you open a connection. Every time you open a connection a new port is created, and if the programmer forgets to close the connection the OS will quickly run out of port numbers in the pool. But the IP/port of the source/destination stays the same throughout the whole communication. A lot of this is small/quick communication - when you browse a web-page you're often directed to 10,20 or more sites for style, scripts and more - each of them the browser creates a separate connection to (although modern protocols can share connections to the same server). Point is, that the socket pairs are key to identify the connection.

1

Brainfuck t1_j22x9ec wrote

Yes they are standardized and default ports. However many a times things aren't run on default ports.

Most of the standardized ports are below 1024. These are called privileged ports and only an Administrator can open them. This is additional security to make sure that a malicious user for example cannot run a webserver on port 80 to hack users.

1