Ports are used at the transport layer of TCP/IP model to identify applications.
Ports are divided into well known, registered and dynamic ports
Well known and registered ports are used by Known applications
Dynamic ports are used by connections initiated by users.
When applications that use well known and registered ports are installed on an operating system, they always listen for incoming clients.
A process space is created in memory of the operating system for accepting incoming connections.
The corresponding port numbers would be exposed on the operating system to service incoming connections for the application
Well known ports are used by applications like FTP, Telnet, DNS. The port number ranges between 1-1023.
FTP Server uses TCP port 20 and 21
Telnet Server used TCP port 23
DNS Server uses UDP port 23
Registered Ports are used by applications like Radius. The port numbers ranges between 1024-49151
Radius Server uses UDP port 1812.
Dynamic Ports are used by users which connect to specific applications. The port numbers ranges between 49152-65535
The port numbers are embedded in the source port and destination port field inside the transport layer headers in a communication.
The source port number inside the TCP header of a client initiating a telnet request would be a dynamic port number assigned by the operating system.
The destination port number inside the TCP header of a client initiating a telnet request would be 23.
The IP and TCP headers of the packet initiated by the client would contain the following
The source port in the TCP header would be a dynamic port, selected randomly by the operating system
The destination port in the TCP header is a well known port , which is 23 for telnet servers.
The source IP address in the IP header would be the clients IP address
The destination IP address in the IP header would be the Telnet Servers IP address
In the scenario mentioned previously, the telnet client has direct connectivity to the telnet server.
What would happen in the following scenarios
Telnet Server is configured to run on a different port number other than 23.
Note: This is a configuration which can be performed based on the capacity of the telnet server
Telnet server is behind an internet router.
In the first scenario, the destination port in the IP header of the packet initiated by the client is 23.
The telnet server is configured on a different port number other than 23.
Due to this, when the packet from the client reaches the server, the connection would be unsuccessful, since the required port is unavailable on the Telnet server.
In the Second scenario, the IP address of the Telnet Server is not exposed.
The Telnet client cannot initiate a communication to the telnet Server
Port –forwarding is used in both the scenarios.
The Router is configured to forward incoming TCP/IP packets with destination IP address as 192.168.1.3 and destination port 23 to the IP address 192.168.1.3 and on the specific port on which the telnet Server is configured.
When the TCP/IP packet shown in the previous slide reaches the router, it would be forwarded to the telnet Server.
The above process explains how Port-Forwarding works in the scenario as per the diagram.
The telnet Server is not exposed on the internet
The telnet client, to achieve connectivity to the telnet server would connect to the public IP address of the router.
The router is configured to forward all incoming packets with destination IP address as it public IP address and port number 23 to the Telnet Server’s IP address and port 23.
This is how port-forwarding works in the mentioned scenario