2

I may sound silly but I seem to be getting confused with what port numbers are used for.

Someplace it's mentioned that port addresses are used for port translation using pat which i get. Somewhere it's mentioned that port address uniquely identifies the process within the host and if it's so how is a host uniquely determined since we need a port address along with ip.

3 Answers 3

2

Port numbers are used as subaddresses on a host. That way, multiple services can run on a single host and numerous connections can be made at the same time using the same transport protocol, e.g. HTTP over TCP port 80, FTP over TCP port 21, SMTP over port TCP port 25, ...

With source NAT - translating many local IP addresses to a single public IP address (or small number) - the NAT router often uses a different outgoing port than the local client did so there are no resource collisions.

1

A port number is an address for some Transport (OSI layer-4) protocols: TCP and UDP. Host processes bind to TCP or UDP at a particular port number, and the transport protocol sends any data destined for that port number to the process bound to that port number.

An important point is that the ports used by TCP and UDP are different, even if they are the same number: TCP port 1234 is not the same as UDP port 1234. Only one host process at a time can bind to TCP port 1234, but another process could bind to UDP port 1234 at the same time as TCP port 1234 is being used by a process.

Not all transport protocols use port numbers. Some use something else for addressing, and some don't use any addressing.

NAT (Network Address Translation) will change the IPv4 packet source, destination, or both addresses, but that requires an address for each address translated. NAPT (Network Address Port Translation) will also translate the port number for TCP or UDP, allowing multiple addresses to be translated to a single address.

RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations explains:

4.1.2. Network Address Port Translation (NAPT)

NAPT extends the notion of translation one step further by also translating transport identifier (e.g., TCP and UDP port numbers, ICMP query identifiers). This allows the transport identifiers of a number of private hosts to be multiplexed into the transport identifiers of a single external address. NAPT allows a set of hosts to share a single external address. Note that NAPT can be combined with Basic NAT so that a pool of external addresses are used in conjunction with port translation.

For packets outbound from the private network, NAPT would translate the source IP address, source transport identifier and related fields such as IP, TCP, UDP and ICMP header checksums. Transport identifier can be one of TCP/UDP port or ICMP query ID. For inbound packets, the destination IP address, destination transport identifier and the IP and transport header checksums are translated.

Understand that the TCP and UDP port numbers are separate. TCP will not be translated to UDP, or vice versa. A TCP segment using NAPT will have its port number translated to a TCP port, and UDP using NAPT will have its port number translated to a UDP port number, even if they are the same number. The same number can be used simultaneously for TCP and UDP because they are separate protocols.

2
  • Thanks i get it. So basically the port number added can identify the host and also the process running within the host ? Nov 12, 2017 at 19:59
  • Right, the IP address defines the host interface, and the port defines the transport interface.
    – Ron Maupin
    Nov 12, 2017 at 21:35
0

Ports are used to allow multiple clients and servers to use the same transport protocol at the same time on the same host. The combination of transport protocol, local IP, local Port, remote IP and remote port uniquely identifies a connection.

Not all transport protocols use ports but most of the important ones do. TCP, UDP and SCTP all use ports. ICMP doesn't use ports as such but the ICMP query ID serves a similar purpose.

The normal convention is that server's use well-known ports while clients use randomly selected ports. This allows multiple connections for the same protocol to coexist between two machines.


One to many NAT (aka NAPT, PAT) hides a network behind a single IP (or sometmes a pool of IPs). To do this it keeps track of connections so it can translate between internal IP/port combinations and external ones.

It is sometimes nessacery to replace the internal port number to avoid ambiguity. Different NAT implementations will have different policies on how exactly this is done and on whether the port number is replaced unconditionally or only replaced when needed to disambiguate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.