Following up from an issue today, I have a question, possibly stupid, but here goes.

How can I block/prevent an application binding to a specific port? This pertains to linux/unix, but I'd be interested in NT as well.

I know I can prevent traffic using a firewall, and ports under 1024 require root, but I wasn't aware of a way to protect a port, only allowing a designated app to bind.

Is there a way?

Thanks

link|improve this question
feedback

2 Answers

up vote 3 down vote accepted

when you are on linux you can use selinux to accomplish this. you would create a port type for your application and add only the ports you would like your application to connect to. all other ports would generate an error message.

but be aware that selinux rules can get a bit nasty.

link|improve this answer
feedback

You don't mention whether it's one specific application you want to block, or any application.

To do it for any app, just have something bind to it before it starts. Netcat is your friend here. Assuming you want to block tcp/1234, your command would look something like: nc -lp 1234 > /dev/null will do what you want

link|improve this answer
Ok, I need to keep a port free for a given app, preventing any other app from taking it. – Alex Jan 25 '10 at 22:06
feedback

Your Answer

 
or
required, but never shown

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