1

Let's say I started a service by using sudo service service_name start, I am interested in knowing all the port opened by this service. I can know port - program mapping by sudo netstat -tulnp but I need to know for a specific service.

3

For this, I usually use lsof with the option to show the ports in use.

Here's an example:

[root@localhost ~]# lsof -Pi | grep myprog
myprog  23411  user    9u  IPv6 9828537      0t0  TCP 1.2.3.167:51163->1.2.3.54:8090 (ESTABLISHED)
myprog  23411  user   16u  IPv4 9827813      0t0  TCP 1.2.3.167:60783->1.2.3.186:23 (ESTABLISHED)
myprog  23411  user   23u  IPv4 9827817      0t0  TCP 192.168.2.8:37435->192.168.2.1:20003 (ESTABLISHED)
myprog  23411  user   24u  IPv4 9827815      0t0  TCP 192.168.2.8:38942->192.168.2.1:20001 (ESTABLISHED)
myprog  23411  user   30u  IPv4 9849168      0t0  TCP 1.2.3.167:52352 (LISTEN)
myprog  23411  user   31u  IPv4 9849242      0t0  TCP 1.2.3.167:52352->1.2.3.186:59323 (ESTABLISHED)
myprog  23411  user   33u  IPv4 9852370      0t0  TCP 1.2.3.167:40328 (LISTEN)
[root@localhost ~]#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.