A port is a number assigned to a specific process or sevice in the network to help comuters sort and direct network traffic correctly. It works on Layer 4(Transport Layer) of the OSI model and works with protocals such as TCP and UDP. They enable the simultaneous operaton of multiple network services on a single IP adress.
When a client application initiates a connection, it specifies the destination port number corresponding to the desired service. Client applications are those who request data or services while server applications respond to those requests and provide the data or services. The OS(opperating system) then directs the incoming traffic to the correct application based on this port number.
eg. a user accesses a website: the user’s browser initiates a connection to the server's IP address on port 80(which is designated for HTTP). The server, listening on this port, responds to the request. If the user needs to access a secure site, the browser instead connects to port 443, the standard for HTTPS.
Well-Known Ports
These ports are numbers 0 to 1023 and are reserved for common and universally recognized services and protocols. They are standerdized and managed by the IANA(Internet Assigned Numbers Authority). HTTP, for example, is used for data communication for the the WWW and uses port 80. Browsers do not tend to display the port number in order to simplyify the user exerience. And HTTPS, S standing for Secure, uses port 443. FTP, used for file transfers, uses ports 20 and 21.
Registered Ports
These ports go from 1024 to 49151 and, while they are not as strictly regulated as well-known ports, they still need to be registered and assigned to specific services by the IANA. They are used for external services that users might install such as Microsoft SQL Server, which is a database service and runs of port 1433. Software companies tend to register a port for their application in order to ensure that their software consistently uses the same port no matter the system. Registration also helps in managing network traffic and preventing port conflicts across different applications.
Dynamic/Private Ports
They are also known as ephemeral ports and range form 49152 to 65535 and are majorly used by client applications to send and recive data from servers. These ports are called dynamic because they are not fixed and can be randomly selected by the client's OS as needed. They act as temporary communication sessions and get closed once the session ends. They can also be assigned to custom server applications.
Browsing Internet Example
DNS Lookup - computer resolves the domain name to an IP address (eg. 93.184.216.34 for example.com)
Data Encapsulation
- Browser generates an HTTP request.
- Request is encapsulated with TCP, specifying the destination port 80 or 443.
- Packet includes the destination IP address (eg. 93.184.216.34.)
- On the local network, the computer uses ARP to find the MAC address of the default gateway (router).
- Data Transmission
- Data frame is sent to the router's MAC address.
- Router forwards the packet toward the destination IP address.
- Intermediate routers continue forwarding the packet based on the IP address.
- Server Processing
- Server receives the packet and directs it to the application listening on port 80 or 443.
- Server processes the HTTP request and sends back a response following the same path in reverse.
- Response Transmission
- Server sends the response back to the client’s temporary port, which was randomly selected by the client’s operating system at the start of the session.
- Response follows the reverse path back through the network, being directed from router to router based on the source IP address and port information until it reaches the client.
Anddd...thats all
Useful video I found to learn about ports - https://www.youtube.com/watch?v=h5vq9hFROEA
Top comments (0)