Viewing a single comment thread. View all comments

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

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

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

could_use_a_snack t1_j1zx19n wrote

Nicely explained. I have a follow up question.

Is the email service always on 25 and web service on 80? Basically are they standardized? Or at least mostly agreed on?

4

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

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

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

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_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

SsooooOriginal t1_j217mn0 wrote

Just wanting to comment, thank you.

This is the best thread I've seen today and very informative!

1