[Design] Linux and TCP ports - Shuatiblog.com
a port is a software construct serving as a communications endpoint in a computer's host operating system.
purpose of ports is to uniquely identify different applications or processes running on a single computer and thereby enable them to share a single physical connection to a packet-switched network like the Internet.
The protocols that primarily use ports are the Transport Layer protocols, such as TCP and UDP.
Port info can be viewed on Linux /etc/services files.
Protocol number
In an IP header, the Protocol field identifies the service in the next higher level in the protocol stack to which data is passed. Do not confuse this with port number, which is used for communication by TCP/UDP.
Socket is combination of software Port and IP address.
a port is a software construct serving as a communications endpoint in a computer's host operating system.
purpose of ports is to uniquely identify different applications or processes running on a single computer and thereby enable them to share a single physical connection to a packet-switched network like the Internet.
The protocols that primarily use ports are the Transport Layer protocols, such as TCP and UDP.
Port info can be viewed on Linux /etc/services files.
there're only 65536 ports
In TCP/IP stack, port number field is just 16bit size unsigned integer. Port number thus ranging from 0 to 65535.Protocol number
In an IP header, the Protocol field identifies the service in the next higher level in the protocol stack to which data is passed. Do not confuse this with port number, which is used for communication by TCP/UDP.
When the IP packet contain TCP data the protocol number field will have the value 6 in it, so the payload will be sent to the TCP stack, TCP would then use the port numbers to send the data to the correct application. The same is for UDP with protocol number 17.
Another way to look at the IP protocol number field is, if we didn’t have this field in the IP packet header, IP would only be capable of carrying one type of data, while adding this field allowed the IP to carry multiple types of data differentiated by the protocol number, the same goes for TCP/UDP using TCP/UDP ports to serve multiple applications and Ethernet using the Ethertype, and so on.
can multiple app bind to (or listen to) the same port?
Can’t. Because You can only have one application listening on a single port at one time.
There may be multiple ip address(NIC card), different app can bind to same port on different ip addresses.
http://www.linuxnix.com/2011/05/important-port-numbers-linux-system-administrator.htmlthe app opens a port, gets a handle to it, and the OS notifies it (via that handle) when a client connection (or a packet in UDP case) arrives.If the OS allowed two apps to open the same port, how would it know which one to notify?
Socket is combination of software Port and IP address.
Q. Why port numbers are just 65536?
This is because limitation in TCP/IP stack where the port number field is just 16bit size. So we get only 2^16(2 to the power of 16) ports which are equal to 65536 available ports
Q.What are the well-known ports or assigned ports or default ports?
Well known ports are from 0 to 1023(total 2^10=1024 ports)
Q.What do you mean by default port?
Default port is a designated port for particular well-known service such as web server, mail server, ftp server etc. By default FTP uses 21 port, DNS uses 53 and Apache uses 80 port.
Q.Can we change default port for a service(example Apache, squid)?
Yes, we can change. In Apache and DNS we can change this using listen configuration entry in httpd.conf and named.conf. Squid have port entry in its squid.conf file to mention port number.
Q.What are the protocol numbers for TCP and UDP?
Do not confuse this one with port numbers. TCP and UDP have their own numbers in TCP/IP stack.
TCP protocol number:6
UDP protocol number:17
Q. Is there any way I can see all the port information in Linux?
Yes, you can get that from /etc/services files.
Q. How can I see open ports in Linux?
Use nmap command.
Read full article from [Design] Linux and TCP ports - Shuatiblog.com