A port is a logical address for each protocol, or you may think of it as a special door for each protocol where all the packets fit. Alternatively, we may say that each protocol’s mailbox is a box where each packet is dropped.
The recipient will later open that packet and read the material that was sent by the sender. Each protocol has its own dedicated line called a port for transmitting packets.
The Internet protocol (IP) and application programs can communicate with each other using the Transmission Control Protocol (TCP).
A port is a number that specifies the host and the service in order to specifically identify a transaction over a network.
It can be treated as a gateway to Internet. To facilitate different applications to make connections at the same time, each device connecting to web uses ports in a different manner. All operations are carried out using different ports when we simultaneously use web, download some files, use a printer, etc. For instance, HTTP
transfers use port number 80, whereas Telnet uses 23. As it is known, device (i.e., computer) is identified by its IP address. Since multiple services (tabs) or applications run by web browser simultaneously, to run network applications, the IP address alone is not sufficient.
Network port facilitates in identifying application or service running in browser/computer in same fashion as IP address does. Looking into an analogical situation – Supposedly you own a building. The street address corresponds to IP address. Also, the way there is a port number, each building also has a building number. Port numbers are also of different types and have unique numbers. The ports co-exist within an IP address because each and every service has its unique port. Top firms like Google or MSN use well-known ports (0 to 10231) for their services; Certain specific functions are assigned registered ports(1024 to 49151) when requested; There are also private or dynamic ports(49152 to 65535) which can be used by anyone who wishes for private servers and temporary purposes. It is highly advisable for you to know port numbers. You’ll have good control of your software if you know it. Applications should always be open for them to work since they use specific ports. While closing them can certainly improve your port security, it is upon you to keep a particular port open or close. You may also open or close a particular port if one of your apps aren’t able to get connected to Internet. Some ports are blocked by firewalls, so you may have to manually allow it to bypass them when needed.
Figure: Working of firewall
The need for a port number is discussed for now. But, who assigns a unique port number for different services/applications ? A web browser when connected to a web server, a port in range (49152- 65535) is self-allocated by web browser, which is called an ephemeral port. In image shown underneath, all unique services are assigned a unique port number, which you can see on 5th tuple on local address. Try netstat on your command to get details.
Note – Client port numbers are dynamically assigned, and can be reused once session is closed.
TCP/IP Ports – FAQs
1. What is the difference between TCP and IP?
TCP (Transmission Control Protocol): TCP is responsible for providing reliable, connection-oriented communication between devices over a network. It ensures that data is delivered in the correct order and without errors. TCP handles flow control, acknowledgment of received data, and retransmission of lost data packets.
IP (Internet Protocol): IP is responsible for addressing and routing packets of data so that they can be sent from the source to the destination across different networks. It provides logical addressing (IP addresses) that uniquely identify devices on a network and determines the best path for data to travel.
2. What is the purpose of a subnet mask in TCP/IP networking?
A subnet mask is used in TCP/IP networking to divide an IP address into two parts: the network address and the host address. It’s used in conjunction with an IP address to determine whether a destination IP is within the same local network or on a different network. By comparing the destination IP address with the subnet mask, a device can determine if the communication should happen within the local network (using MAC addresses) or if it needs to be forwarded to another network through a router.
3. How does NAT (Network Address Translation) work in TCP/IP?
NAT is a technique used to allow multiple devices in a local network to share a single public IP address for communication with external networks like the Internet. NAT works by modifying the source or destination IP addresses in the packet headers as they pass through a NAT-enabled router. Outgoing packets have their source IP changed to the router’s public IP, and incoming packets have their destination IP translated to the appropriate local device’s IP based on port numbers. This enables multiple devices with private IP addresses to access the Internet using a single public IP.
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation
Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation