0

As you see below jsvc.exe is running on 8910 with PID 23943.

[root@abc-163 ~]# netstat -tulpn | grep :8910
tcp6       0      0 :::8910                 :::*                    LISTEN      23943/jsvc.exec


[root@abc-163 ~]#  ps -lf -p 23943
F S UID          PID    PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
5 S admi+   23943   23942  3  80   0 - 2382184 hrtime Sep13 ?      12:01:07 jsvc.exec - 
java-home /opt/CSCOcpm/jre -server -user admin -outfile /abc/bcd

My requirement is to disable 8910 port completely i.e nothing should listen on 8910. But when needed (after doing some UI action in my website), i want 8910 port should be enabled again and start listening just like before. Can you please suggest how do i achieve this?

I tried kiling the PID 23943 by doing

[root@abc-161 ~]# fuser -k 8910/tcp
8910/tcp:            20570

And it killed the process as well. After that i checked using the netstat command and confirmed that nothing was listening on 8910. Till this point it was fine. But after that how do i enable 8910 port again? How do i make sure same jsvc.exec should run on 8910 again?

4
  • It is unclear for me what you are asking. Either the process is running and listening or it is not running and thus not listing. You make it running again by starting the process. How this needs to be done depends on the process, i.e. there is no generic process-independent way to do this. Note that you also might keep the process running and listening but make it inaccessible from outside by adding appropriate firewall rules and removing these once the process should be accessible. Commented Sep 30, 2022 at 4:39
  • @SteffenUllrich I can modify iptables rules in order to make the port inaccessible but it still keep listening on that port. The requirement for our project is to completely disable 8910 port and later when needed, need to again start listening on this port. Commented Sep 30, 2022 at 4:57
  • @SteffenUllrich So from the netstat command outputs above, could you please suggest any other/better way to stop listening on 8910 port and how to start listening again when needed? Commented Sep 30, 2022 at 4:59
  • 2
    "So from the netstat command outputs above" - no, this is not possible from the netstat and ps output alone. It only shows the process and command line but not the environment, or other other preconditions needed for the process to run. Usually there is a defined process specific way of how to start and stop processes - which does not involved looking at the process table or netstat and then kill the process and try to restart it from the observed information. Commented Sep 30, 2022 at 5:03

1 Answer 1

2

There are two ways to "enable" and "disable" ports like this.

You can enable them and disable them with firewall rules -- but this only affects external hosts accessing the port, really just blocking the port from external access.

The other way is by stopping and starting the process that is actively listening on the port. So by killing that process, you remove everything listening on the port. By restarting that process, it would come back.

So the real question you have here is how to stop and restart that process. The port itself is not something you can turn on and off -- only block and unblock. The process is what you turn on and off.

3
  • Is it possible to write a firewall rule that blocks localhost? Commented Mar 25, 2023 at 7:26
  • Probably not, and it doesn't make sense to do that. Just stop the service. Commented Mar 25, 2023 at 12:41
  • Java applications can be pretty fat, and slow to start. Much faster to close and then open a firewall port. It's moot, though, if you can't block localhost... Commented Mar 25, 2023 at 12:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.