Given a service name, get its port number?
To get the port number of a service by its name in a Unix/Linux environment, you can use various methods and commands. Here are some common approaches: 1. **Using `getent` and `/etc/services`**: You can use the `getent` command along with the `/etc/services` file to look up the port number of a service. For example, to find the port number for the SSH service (OpenSSH), you can run: ```bash getent services ssh ``` This will return the port number associated with the SSH service, such as `22/tcp`. 2. **Using `nc` (netcat)**: You can use the `nc` (netcat) command to attempt a connection to the service by name, and it will display the port if successful. For example: ```bash nc -z -v -n -w 1 localhost 22 ``` This will attempt to connect to the SSH service (port 22) on the localhost, and if successful, it will display the port number. 3. **Using `ss` (Socket Statistics)**: The `ss` command can provide information about active sockets, which can include the