16

I'd like to assign a friendly name to a port number, how should I do it?

For example: I'd like "0.0.0.0:my-service-name" translates to "0.0.0.0:1234"

Braiam
  • 35,991

1 Answers1

29

Yes, you can do this, by adding your port definition to /etc/services. For a TCP service, you’d add

my-service-name    1234/tcp

Once that’s done, you’ll be able to write “0.0.0.0:my-service-name” instead of “0.0.0.0:1234”.

The canonical list of services is maintained by the IANA, but you can add local definitions; you might even see a “# Local services” comment at the end of your /etc/services file already.

Stephen Kitt
  • 434,908
  • It's important to note that this will only work on your local machine. If you want some other computers on the network to use that name, you'll have to modify /etc/services on those machines. – HiddenWindshield Sep 26 '20 at 22:41
  • 1
    @user431397 it won’t, /etc/services is a conffile (see /var/lib/dpkg/info/netbase.conffiles). More generally, /etc belongs to the system administrator, it’s a bug if a package doesn’t preserve changes made there. – Stephen Kitt Sep 27 '20 at 08:23