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
Main Topics
Browse All TopicsIs 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
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.
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!!
I would suggest you detect the browser close event and close the socket properly. There are some information here: http://www.linuxforums.org
Business Accounts
Answer for Membership
by: ciulyPosted on 2006-07-21 at 03:30:34ID: 17152850
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.