Routing – Why Can’t a Single Port Be Used for Both Incoming and Outgoing Traffic?

iprouting

I'm trying to understand something related to network ports, as it's not quite clear to me.

The question is, why can't you use the same port number for both incoming and outgoing traffic?

This question arose due to some advice on NAT port forwarding.

From what I can tell, IP packet headers contain fields for source address and destination address, which I'd imagine would be all you'd need to know to determine whether the packet was incoming or outgoing.

I realise this is a simple question. If there are learning resources you could point me to that you think would be useful in building up a deeper understanding of networking from the fundamentals up, I'd appreciate the links, even if there's a lot to learn.

Thanks.

Best Answer

You can, and some protocols do (isakmp), but it's not very flexible. There are two drawbacks:

  1. You can have only one data stream. A typical web browser makes several tcp connections to a web server to increase performance. That's why you often see the text appear before the graphics on a web page. you can't do that with only one stream.
  2. It's possible for a host to be both a client and a server at the same time. If the port numbers are the same, you can't do that either.

Ultimately, using well-known ports for destination and ephemeral ports for source gives the most flexibility.

Related Topic