Link to home
Start Free TrialLog in
Avatar of smotbd
smotbd

asked on

500: Simply stop port listening

Is there command that I can type in the command prompt to stop a port from listening?? Not permanently.
I have a script, which when run, opens a few ports for listening....but it doesn't close them ever and I can't change the script so that's why I want to do it from the cammand line.


Many thanks in advance
Avatar of 2266180
2266180
Flag of United States of America image

provided that you are using ptables:

iptables -I INPUT -p tcp -m tcp --dport <the_port> -j DROP

and to remove it
iptables iD INPUT 1

this will still leave the port listening, but it will prevent connections to it.
anoter way would be to open some bogus program to listen on those ports, but that might raise errors in the script if it hadn't been written to deal with such issues.
Avatar of smotbd
smotbd

ASKER

I don't and won't use iptables sorry.

Is there not a simple command or script that can be run?? It's only a setting somewhere!

Thanks
well, if you are so sure that it is only a setting somewhere, what is thet setting? or where is somewhere?

you cannot have a OS setting that says that an applicaiton cannot bind to a specific port.
you either do that from the application or you block the access to that port for other applications. you don't want to do either of that.
and may I know:
- why is it a problem that the script binds to some ports?
- why don't you want to use iptables? or other kernal-firewalling module/app?
- why don't you want to modify the script?

maybe the problem is somewhere else and thus the solution is not even close to denying access to a port.
Avatar of noci
If you open a port it is listening, if you close a port it isn't

If you can't change the regime on opening/closing then blocking the the only other option.
There is no other option to enable/disable listening.
may be you should post your script here?
Avatar of smotbd

ASKER

The script is a PHP script which simply acts as a server listening on particular ports.
I start this PHP script via the url on a web browser..... If I click on the cross on my web browser, the script stops running. I thought then that the ports would stop listening since the script has stopped. The application has stopped yet the ports are still listening. How?
So I concluded this: when the application is ran, the functions socket_create/listen must set a value of some sort to set these ports to listening as oppose to not listening!! So then, when I stop the script nothing changes. I know that socket_close or what have you will close this sockeet.....but I just wondered if there was a command that one could enter in to the command line to stop these ports set to listening.

After all, computers, of course, are just electronic machines. They don't know about Linux and
menus, they don't know about programs or instructions, and they don't even know about 1s and 0s. All
that is really going on is that voltage is being measured at various places on an integrated circuit. I thought that one could do anything under linux and all I want to do is stop a port listening!!

Anyway,, it's just a question out of curiosity  more than anything....but if I'm talking nonsence then I apologise!!
ASKER CERTIFIED SOLUTION
Avatar of slyong
slyong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of smotbd

ASKER

yeh i do need to close ports properly............................
 lsof -i detected the ports left open....and their pid so I killed them thanks!!