what is a port and why do computers have so many?

Right now sygate is scanning my hundreds of ports looking for weakness (Huh! I am trojan proof. Bring them on!). Now I have 1 IP address. What are all these ports, and why have so many? Are some reserved for certain protocols such as TCP or FTP or http? I presume these “ports” are only nominal software descriptions, not a real hardware connection so are they really necessary?

All ports below 1024 are reserved, so I believe. A port can be thought of as a virtual plug socket. Suppose you only had a single port, this would mean only one internet service could work with your machine at once, considerably slowing things down. The large number of ports allows numerous services to connect to yuor machine at once.

As I said before, some port numbers are reserved for established protocols. 80 for HTTP.

http://webopedia.internet.com/quick_ref/portnumbers.asp

If computers didn’t have ports, where do you expect us to get baby computers from? :confused:

Each program that communicates over a network connection uses at least one port, having a large number of ports allows a large number of programs to use your internet connection without messages for one program being recieved by another.

Each piece of information sent to your computer (called a packet) is addressed both to your machine (used by the routers on the internet to get the information to your card) and to a port on your machine to get it to the waiting program once it gets to your card. So in other words these ports are indeed virtual rather than physical

IIRC there are 2^15 ports per ip address, around 32 thousand. This is huge overkill but given that these are virtual addresses rather than physical items that have to be constructed the only disadvantage of having loads is that the address that preceeds every message your network card recieves is 1 bit longer for each power of 2, not overall a huge deal.

For the final part, yes there are standard ports that are used for commonly used protocols, there’s no reason that you have to use these ports except that other people expect you to.

for example telnet is port 23, mail is normally port 25, NTP (network time protocol) is 123, http is port 80 and so on and so forth.

Finally for your own amusement you can see what’s talking to what on your machine by issuing the command netstat -a at a command prompt (works on windows and most unix flavours).

Hope that helps.

The quick layman’s explaination is that each application that wants to send or receive data over the network needs a port. So you might have a mail program and a browser open while your anti-virus program is downloading an update in the background. Each needs to have it’s own port so the OS knows where to deliver the data to. But your computer only needs one IP address because it’s only connected to the network in one place.

For an analogy, think of street addresses. If you’re looking for an address, first you have to find the street (the IP), but there could be any number of unique addresses on that street (the ports).

It’s a huge simplification, but if you want a better understanding, you’ll probably have to take some graduate level CS classes.

Apparantly I don’t recall correctly. It’s double that, which makes a lot more sense. 2^16 is two bytes exactly, apologies for the goof.
Additionally These people appear to be in charge of keeping track of what’s to be commonly found where.

OK, I think I see. But does the port define the protocol or the protocol the port? E.g if the computer receives something addressed to port 80, does it think “aha must be http” even if it was actually ftp by accident. Ot does the packet say “port 80 please. I am http”, in which case why say “port 80” in the first place, but just “I am http”

from MDI “Suppose you only had a single port, this would mean only one internet service could work with your machine at once, considerably slowing things down. The large number of ports allows numerous services to connect to yuor machine at once.”

but if each packet of data coming in identified the type it was and where it was from - why does it also have to identify a ficticious port as well? E.g if I am downloading several pages of http at once form different servers, they must be using the same port, but there are no obvious logjams. I just wonder if the port concept if a hangover from earlier days when it had a real use

When you say “ports below 1024 are reserved” it might be instructive to note that during the era when most Internet hosts were running Unix derivatives, the “root” user or his equivalent was the user that these ports were reserved for.
I think other posters have explained the purpose of ports adequately. I always keep it straight by thinking that if traffic directed at boards.straightdope.com didn’t go to “Port 80” then there would be no way for the operating system on boards.straightdope.com to know whether a particular packet of traffic was meant for the web server, the ftp server, or the ntalk server.

Fun ports trivia:
You could set up an alternative HTTP server on another port if you wanted. It wouldn’t even have to run the same HTTP service as the one on port 80. If you wanted, you could have Apache HTTP server on 80, Zeus HTTP server on port 31337, the NCSA httpd running on port 61119, etc.
Or, if you felt like it you could put your web server on port 23, your FTP server on port 80, etc.
Doing things on non-standard ports would work fine, although it could confuse the crap out of everyone who dealt with your machine.

Another advantage to having all these ports is that a program can be written to simply toss data at port X and reasonably expect the data to get out of the computer, down the wire and arrive wherever it’s supposed to be.

An analogy would be FedEx. You’ve got a box to ship to Dallas and it can get there whenever. So, you drop it in the “Ground” bin at the mailroom. Your package that has to be in Chicago by 9:00 AM goes into the Priority Overnight bin. You don’t need to know how to move a package from your desk to Chicago overnight. You just have to know “overnight packages get put on the red cart in the mailroom” and someone or something else handles the rest.

Likewise, your email program doesn’t have to know how to get a message from your keyboard to your friend’s computer. It just has to know how to pour the data into port 25. The logic and programming behind the port take care of the rest.

From the perspective of a computer’s operating system, the notion of protocols is basically bunk.
Example:
I have a Windows 2003 Server server in my server room. It receives a packet addressed to port 80.
Windows proceeds to say to itself “ok, traffic addressed to port 80. Who does that go to?”
Windows then remembers that a particular service (IIS, aka Internet Information Server) has reserved port 80, and that thus this packet must be delivered to that service.
The concept of different protocols being attached to different ports is not really encoded anywhere at the level that operating systems operate at.
The OS just knows that a given program has asked that all traffic going to a given port be handed to said program.

If you still desire clarification, please let me know, I’d love to elaborate if I can.

Oh, and as a caveat, many modern OSs [WTH is the plural of OS without spelling OS out?] do in fact come bundled with web servers, ftp servers, and more. And those bundled servers do come out of the box with a belief that if you DO want them to operate, you’ll probably want them to operate on their default ports.
So my statements above are literally true, but due to all of the stuff that comes “in the box” with many operating systems, are somewhat of an oversimplification.

thanks jonathon, It is very clear now

To elaborate further, only the computer which accepts connections needs a well known port. When you make a connection to boards.straightdope.com, you send a packet to 65.201.198.9 (the IP of the SDMB) telling it that you want to make a connection with port 80 and that you are located at <your address> at <random port>. The random port is automatically generated by TCP and it’s a port >1024 thats not being used. Whenever the boards send back data, it sends it to the port you established the connection with which is how your computer knows its from the straight dope.

I would type “OS’s.” But this a whole other thread, and beware the poster who dares go there. :slight_smile:

OSes