2

Sorry for my limited knowledge in Networking.

If I understand correctly port numbers are application level addresses for network communication, e.g. port no 20 is assigned for FTP.

In PAT, we map one external IP address to multiple internal addresses. The mapping uses port numbers as shown in the following figure.

enter image description here

Here the port numbers are 1000, 1001, 1002.

My question is how the mapping will be if all the hosts in the local network are trying to connect the remote machine using FTP (port no 20) at the same time?. In this case how to uniquely identify the local machine when sending and receiving packets?

4 Answers 4

3

Ports are addresses used by some transport-layer protocols, not application addresses.

The NAT table for NAPT (PAT is really a misnomer, see RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations) will use the source and destination IPv4 and transport addresses and come up with a random port for the transport protocol.

The transport address on the remote host will multiplex to allow different connections. Web servers do this all the time. It is not unusual for a web browser to open multiple TCP connections from a host to the web server in order to get multiple page elements at the same time, and the server and browser maintain separate connection between them. RFC 793, Transmission Control Protocol explains multiplexing and connections:

Multiplexing:

To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.

The binding of ports to processes is handled independently by each Host. However, it proves useful to attach frequently used processes (e.g., a "logger" or timesharing service) to fixed sockets which are made known to the public. These services can then be accessed through the known addresses. Establishing and learning the port addresses of other processes may involve more dynamic mechanisms.

Connections:

The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream. The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.

When two processes wish to communicate, their TCP's must first establish a connection (initialize the status information on each side). When their communication is complete, the connection is terminated or closed to free the resources for other uses.

Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.

2
  • Thanks for the answer. If they assign random ports both hosts initiate FTP connections/whatever application will use some random port numbers in the PAT table. Am I correct? So who decides these numbers? The router or the host?
    – user570593
    Commented Jan 4, 2018 at 3:51
  • The NAT device (usually a router or firewall) decides the random source port. It is what maintains the NAT table, so it is the only device that needs to know which new addresses relate to which original addresses. By the way, NAT devices do not share tables, so sites with two routers running NAT can have a problem with asymmetric routing (the reply comes into the other router).
    – Ron Maupin
    Commented Jan 4, 2018 at 4:01
2

You can't map (private) IP addresses to (public) IP:port combinations. The NAT router always maps IP:port to IP:port combinations.

For private to public connections (dynamic source NAT), these mappings are somewhat random and change over time. The private port is chosen by the client, the public port is selected from the NAT router's pool.

To enable connections from public to private - a host behind the NAT router - a public port on the router's public IP needs to be statically mapped to a private IP:port combination (destination NAT).

0

PAT is port address translation whereas private ip address from inside network is translation to assigned exgress interfàce public ip address .

Generally Port address translation (PAT) is used to access resources in internet . It is for outbound connectivity .

Souce ports and destination ports we can see in traffic logs . Destination port is port used in service of application on which application is hosted . Source port is randomly generated by NAT table for reference to destine reverse traffic to correct source from where tràffic is initiated.

1
0

A TCP or UDP packet has TWO port numbers, a source port number and a destination port number. When replying to a packet the convention is to swap the destination address with the source address and the destination port number with the source port number.

The normal convention is that servers use well-known port numbers, while clients use ephemeral port numbers. This means that multiple clients can connect to the same service, even if those clients are running on the same computer.

It is this facility that NAPT exploits. When the NAPT implementation modifies the source IP, it can also modify the source port number. The destination port number of the outgoing packets is left at it's original value. So the request is still delivered to the correct server.

When the response comes back, the NAPT can look up the destination address and port in it's mapping tables and translate them back so the request is sent to the correct client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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