services 中文man頁面
NAME(名稱)
services - Internet 網(wǎng)絡(luò)服務(wù)列表
DESCRIPTION(描述)
services 是一個(gè)普通的 ASCII 碼文件, 它在 internet 服務(wù)的友好原文名以及這些服務(wù)預(yù)先分配的端口和協(xié)議類型之間提供了映射. 每個(gè)聯(lián)網(wǎng)程序必須查找該文件以獲取其服務(wù)的端口號(hào)(和協(xié)議). C 庫例程 getservent(3), getservbyname(3), getservbyport(3), setservent(3), 和 endservent(3) 支持由程序查詢該文件.
端口號(hào)由 IANA(Internet Assigned Numbers Authority) 分配, 他們當(dāng)前的工作是分配端口號(hào)時(shí), 指定 TCP 和 UDP 協(xié)議. 這樣, 大多數(shù)記錄會(huì)包括兩條子記錄, 即使只是 TCP 的服務(wù)也是如此
端口號(hào)在 1024 之下的(也稱作'低編碼'端口)只能由 root (參見 bind(2),tcp(7),和udp(7).) 綁定. 這樣連接到低編碼端口的客戶可信任運(yùn)行在該端口上的服務(wù)是標(biāo)準(zhǔn)的實(shí)現(xiàn), 而不是由某臺(tái)機(jī)器的用戶運(yùn)行的無聊的服務(wù).由 IANA 確定的眾所周知的端口號(hào)通常只在 root 的控制范圍之內(nèi)
在 services 文件中出現(xiàn)的一條服務(wù)記錄并不表示該服務(wù)當(dāng)前在機(jī)器上運(yùn)行.參見 inetd.conf(5) 以獲知提供的Internet服務(wù)的配置.注意不是所有聯(lián)網(wǎng)服務(wù)都由 inetd(8) 啟動(dòng),因而也不會(huì)出現(xiàn)在 inetd.conf(5) 之中. 特別地,news (NNTP)和mail (SMTP)服務(wù)程序通常由系統(tǒng)引導(dǎo)腳本初始化.
services 文件所存放的位置由 /usr/include/netdb.h 中的 _PATH_SERVICES 定義. 它通常設(shè)為 /etc/services.
每行描述了一個(gè)服務(wù),其格式如下:
- 服務(wù)名 端口/協(xié)議 [別名 ...] 這里的
- 服務(wù)名
- 是給服務(wù)所起的可供查找的友好的名字.它是區(qū)分大小寫的.通常,客戶端程序都以 服務(wù)名 命名.
- 端口
- 為該服務(wù)所用的端口號(hào)(十進(jìn)制格式).
- 協(xié)議
- 為所使用的協(xié)議類型.該字段應(yīng)與 protocols(5) 文件中的一條記錄相匹配.典型的值包括 tcp 和 udp.
- 別名
- 可以空缺,或者是以tab分隔的該服務(wù)的其他名字的列表(不過請查看下面的BUGS章節(jié)).同樣, 這些名字也是區(qū)分大小寫的.
可以使用空格或者tab分隔這些字段.
注釋以hash標(biāo)識(shí)(#)開頭,一直到該行末結(jié)束.空行可跳過.
服務(wù)名 必須是該文件的第一列,因?yàn)槠淝懊娴目崭癫粫?huì)刪去. 服務(wù)名 可以為任何可打印的字符,包括空格和tab,但是,應(yīng)該使用字符的保守選擇來最低限度地減少操作中的問題.例如:a-z,0-9,和連字符(-)看上去就是一個(gè)合理的選擇.
不匹配該格式的行不應(yīng)該在該文件中出現(xiàn).(當(dāng)前情況下, getservent(3),getservbyname(3),和getservbyport(3) 可以忽略它們.不過,不應(yīng)該依靠這種方法.)
為了向后兼容,在 端口 號(hào)和 協(xié)議 名之間的斜杠(/)實(shí)際可以為斜杠或者是逗號(hào)(,).在現(xiàn)代的安裝中使用逗號(hào)是落后的.
該文件也可以通過使用網(wǎng)絡(luò)級(jí)命名服務(wù)如黃頁/NIS(Yellow Pages/NIS)或BIND/Hesiod來在一個(gè)網(wǎng)絡(luò)中發(fā)布.
一個(gè) 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個(gè)別名,這是由 getservent(3) 代碼的寫入方式?jīng)Q定的.
比 BUFSIZ (當(dāng)前為1024)個(gè)字符更長的行, getservent(3),getservbyname(3),andgetservbyport(3) 會(huì)忽略掉. 不過,這也會(huì)導(dǎo)致錯(cuò)過下一行.
FILES(相關(guān)文件)
- /etc/services
- Internet網(wǎng)絡(luò)服務(wù)列表
- /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)