services 中文man頁面
NAME(名稱)
services - Internet 網絡服務列表
DESCRIPTION(描述)
services 是一個普通的 ASCII 碼文件, 它在 internet 服務的友好原文名以及這些服務預先分配的端口和協議類型之間提供了映射. 每個聯網程序必須查找該文件以獲取其服務的端口號(和協議). C 庫例程 getservent(3), getservbyname(3), getservbyport(3), setservent(3), 和 endservent(3) 支持由程序查詢該文件.
端口號由 IANA(Internet Assigned Numbers Authority) 分配, 他們當前的工作是分配端口號時, 指定 TCP 和 UDP 協議. 這樣, 大多數記錄會包括兩條子記錄, 即使只是 TCP 的服務也是如此
端口號在 1024 之下的(也稱作'低編碼'端口)只能由 root (參見 bind(2),tcp(7),和udp(7).) 綁定. 這樣連接到低編碼端口的客戶可信任運行在該端口上的服務是標準的實現, 而不是由某臺機器的用戶運行的無聊的服務.由 IANA 確定的眾所周知的端口號通常只在 root 的控制范圍之內
在 services 文件中出現的一條服務記錄并不表示該服務當前在機器上運行.參見 inetd.conf(5) 以獲知提供的Internet服務的配置.注意不是所有聯網服務都由 inetd(8) 啟動,因而也不會出現在 inetd.conf(5) 之中. 特別地,news (NNTP)和mail (SMTP)服務程序通常由系統引導腳本初始化.
services 文件所存放的位置由 /usr/include/netdb.h 中的 _PATH_SERVICES 定義. 它通常設為 /etc/services.
每行描述了一個服務,其格式如下:
- 服務名 端口/協議 [別名 ...] 這里的
- 服務名
- 是給服務所起的可供查找的友好的名字.它是區分大小寫的.通常,客戶端程序都以 服務名 命名.
- 端口
- 為該服務所用的端口號(十進制格式).
- 協議
- 為所使用的協議類型.該字段應與 protocols(5) 文件中的一條記錄相匹配.典型的值包括 tcp 和 udp.
- 別名
- 可以空缺,或者是以tab分隔的該服務的其他名字的列表(不過請查看下面的BUGS章節).同樣, 這些名字也是區分大小寫的.
可以使用空格或者tab分隔這些字段.
注釋以hash標識(#)開頭,一直到該行末結束.空行可跳過.
服務名 必須是該文件的第一列,因為其前面的空格不會刪去. 服務名 可以為任何可打印的字符,包括空格和tab,但是,應該使用字符的保守選擇來最低限度地減少操作中的問題.例如:a-z,0-9,和連字符(-)看上去就是一個合理的選擇.
不匹配該格式的行不應該在該文件中出現.(當前情況下, getservent(3),getservbyname(3),和getservbyport(3) 可以忽略它們.不過,不應該依靠這種方法.)
為了向后兼容,在 端口 號和 協議 名之間的斜杠(/)實際可以為斜杠或者是逗號(,).在現代的安裝中使用逗號是落后的.
該文件也可以通過使用網絡級命名服務如黃頁/NIS(Yellow Pages/NIS)或BIND/Hesiod來在一個網絡中發布.
一個 services 的樣本文件看上去如下:
-
netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp # message send protocol chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp 21/tcp # 22 - unassigned telnet 23/tcp
BUGS
最大只能有35個別名,這是由 getservent(3) 代碼的寫入方式決定的.
比 BUFSIZ (當前為1024)個字符更長的行, getservent(3),getservbyname(3),andgetservbyport(3) 會忽略掉. 不過,這也會導致錯過下一行.
FILES(相關文件)
- /etc/services
- Internet網絡服務列表
- /usr/include/netdb.h
- _PATH_SERVICES 的定義
SEE ALSO(另見)
getservent(3), getservbyname(3), getservbyport(3), setservent(3), endservent(3), protocols(5), listen(2), inetd.conf(5), inetd(8).
#p#
NAME
services - Internet network services list
DESCRIPTION
services is a plain ASCII file providing a mapping between friendly textual names for internet services, and their underlying assigned port numbers and protocol types. Every networking program should look into this file to get the port number (and protocol) for its service. The C library routines getservent(3), getservbyname(3), getservbyport(3), setservent(3), and endservent(3) support querying this file from programs.
Port numbers are assigned by the IANA (Internet Assigned Numbers Authority), and their current policy is to assign both TCP and UDP protocols when assigning a port number. Therefore, most entries will have two entries, even for TCP only services.
Port numbers below 1024 (so-called 'low numbered' ports) can only be bound to by root (see bind(2), tcp(7), and udp(7)). This is so clients connecting to low numbered ports can trust that the service running on the port is the standard implementation, and not a rogue service run by a user of the machine. Well-known port numbers specified by the IANA are normally located in this root-only space.
The presence of an entry for a service in the services file does not necessarily mean that the service is currently running on the machine. See inetd.conf(5) for the configuration of Internet services offered. Note that not all networking services are started by inetd(8), and so won't appear in inetd.conf(5). In particular, news (NNTP) and mail (SMTP) servers are often initialized from the system boot scripts.
The location of the services file is defined by _PATH_SERVICES in /usr/include/netdb.h. This is usually set to /etc/services.
Each line describes one service, and is of the form:
- service-name port/protocol [aliases ...]
- where:
- service-name
- is the friendly name the service is known by and looked up under. It is case sensitive. Often, the client program is named after the service-name.
- port
- is the port number (in decimal) to use for this service.
- protocol
- is the type of protocol to be used. This field should match an entry in the protocols(5) file. Typical values include tcp and udp.
- aliases
- is an optional space or tab separated list of other names for this service (but see the BUGS section below). Again, the names are case sensitive.
Either spaces or tabs may be used to separate the fields.
Comments are started by the hash sign (#) and continue until the end of the line. Blank lines are skipped.
The service-name should begin in the first column of the file, since leading spaces are not stripped. service-names can be any printable characters excluding space and tab. However, a conservative choice of characters should be used to minimize inter-operability problems. E.g., a-z, 0-9, and hyphen (-) would seem a sensible choice.
Lines not matching this format should not be present in the file. (Currently, they are silently skipped by getservent(3), getservbyname(3), and getservbyport(3). However, this behaviour should not be relied on.)
As a backwards compatibility feature, the slash (/) between the port number and protocol name can in fact be either a slash or a comma (,). Use of the comma in modern installations is depreciated.
This file might be distributed over a network using a network-wide naming service like Yellow Pages/NIS or BIND/Hesiod.
A sample services file might look like this:
-
netstat 15/tcp qotd 17/tcp quote msp 18/tcp # message send protocol msp 18/udp # message send protocol chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp 21/tcp # 22 - unassigned telnet 23/tcp
BUGS
There is a maximum of 35 aliases, due to the way the getservent(3) code is written.
Lines longer than BUFSIZ (currently 1024) characters will be ignored by getservent(3), getservbyname(3), and getservbyport(3). However, this will also cause the next line to be mis-parsed.
FILES
- /etc/services
- The Internet network services list
- /usr/include/netdb.h
- Definition of _PATH_SERVICES
SEE ALSO
getservent(3), getservbyname(3), getservbyport(3), setservent(3), endservent(3), protocols(5), listen(2), inetd.conf(5), inetd(8)