1) The/etc/services file records the network service names and their corresponding port numbers and protocols. 2) Format
Each row in the file corresponds to a service. It consists of four fields separated by tabs or spaces, service name, port used, protocol name, And alias respectively ".
Service name "tab" port number/protocol name "tab" alias Kermit 1649/udpl2tp 1701/tcp l2fl2tp 1701/udp l2fh323gatedisc 1718/tcp3) This file is used by many system programs. If every service can strictly follow this mechanism and mark the port information used in this file, the use of ports between services on the host will be very clear, easy to manage; The service name defined in this file can be used as a parameter in the configuration file. For example, when configuring a routing policy, use "www" instead of "80" to call the "www 80" entry in this file "; In special cases, you only need to modify the WWW definition in/etc/services to change the port settings. For example, add the "privport 55555" entry to the file, which is widely used in multiple configuration files in a private service for configuration. To change the port configurations to 66666, you only need to modify the corresponding lines in the/etc/services file. In an application, you can obtain the corresponding port number through the service name and Protocol. By registering with this file, the application no longer cares about the port number. 4) The range of port numbers allocated to Linux systems is 0-65535. Different ranges have different meanings. 0 is retained by the 1--1023 system, and only 1024---4999 can be used by root users. 5000---65535 can be freely allocated by client programs.
4. How can I make the application do not care about the port number used by the service?
1) determine the service program name, protocol, and port number. 2) Configure in/etc/services. 1) 3) the application may not directly use the port number, use the getservbyname ("server", "TCP") function to obtain the port number. 4) if the Service wants to change the port number, you only need to change the port number in/etc/services, and the application does not need to make any changes. Note: You can also use the getservbyport (htons (50), "tcp") function to obtain the corresponding port and service name on the protocol. To use these two system functions, you must include the header file: # include <netdb. h>