-3

In /etc/services, a service name can have multiple (transport protocol, port number) pairs. For example,

http            80/tcp                  # Hypertext Transfer Protocol
http            80/udp
ssh             22/tcp                  # Secure Shell
ssh             22/udp
telnet          23/tcp                  # Telnet
telnet          23/udp
smtp            25/tcp                  # Simple Mail Transfer Protocol
smtp            25/udp

When a service is specified as (host name, port number), does that specify a transport protocol?

If yes, where and when is the transport protocol inferred from (host name, port number)? I guess not DNS server, because DNS server doesn't know about /etc/services on individual server machines.

If no, how would you specify a service, so that its transport protocol can be specified as well as its host name and port number?

Thanks.

Tim
  • 1,467
  • 3
  • 25
  • 38

2 Answers2

6

When a service is specified as (host name, port number), does that specify a transport protocol?

No. example.com:80 could be a http service but it could just as easily be a VPN service. If it were a VPN service running e.g. OpenVPN then it could be a tcp or udp it depends on how the application is configured.

If no, how would you specify a service, so that its transport protocol can be specified as well as its host name and port number?

I don't believe there is convention for this, I would probably use example.com:80/tcp but YMMV.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • Is `example.com:80/tcp ` a URL? If yes, `/tcp` is not a parameter or query, but what? – Tim Feb 13 '19 at 21:55
  • 3
    No, it's not a URL, it's a cluelessness detector. – user9517 Feb 13 '19 at 21:58
  • How in reality a user or client (implicitly or explicit) specifies the transport protocol of a service? – Tim Feb 13 '19 at 22:08
  • 2
    It's magical ... – user9517 Feb 13 '19 at 22:09
  • Your reply makes my head hurt trying to parse it. – Tim Feb 13 '19 at 22:25
  • 1
    Typically the application mandates usage of a specific protocol for client-server communication and the protocol mandates a specific transport. Some protocols allow multiple transports (DNS will use UDP for requests that fit in a single datagram and TCP for larger requests such as zone transfers ) others like OpenVPN can use both but require both client and server to both be explicitly configured to use the same specific transport. There is no one size fits all. – HBruijn Feb 13 '19 at 22:33
2

Hostname/DNS has nothing to do with the services running on specific ports. It strictly handles translating IP addresses to names, and vice versa.

/etc/services works as a hint lookup for getportbyname() so that scripts/programs on the local machine don't have to know what port they're dealing with. I.e. if I have a script that remotes into other machines, i could have it try all ports specified by /etc/services.

Services, and specifically the transport protocols they use are dependent on how they were written and/or configured. If you're looking at configuring a service to a specific port/transport protocol, you'd have to look at the configuration for that specific service. Some may not let you listen on UDP, but let you specify whatever TCP port you want. Others may let you set both, it is highly dependent on the service.

For example, when setting up nginx, you have the listen directive that lets you specify IP address and (tcp) port, but that's it. You can do udp load balancing, but not listen on HTTP with UDP.

Steve Butler
  • 1,016
  • 9
  • 19