Preventing other applications from using a port
Clash Royale CLAN TAG#URR8PPP
One of my applications uses randomly-selected ports from a port range to listen on. By default, 40000-59999.
The application runs on a firewalled server, and of course expects me to open the whole range on the firewall.
I'm not comfortable opening a large range of ports, most of which will never be used. The main concern is that another application may, also randomly, choose a port in that range and end up open to the world. I can configure the port range to be smaller, which would reduce the problem somewhat, but not truly solve it.
I have two ideas how to solve this conceptually, but don't know how/if it can actually be implemented. Operating system is RedHat Linux 7.4. The firewall is iptables/firewalld. SELinux is disabled (yes, I know, I don't like that either...)
My first idea: somehow "magically" prevent all other applications from binding to ports in this range. SELinux might be able to do that, but unfortunately I cannot use SELinux on that server (another application chokes on it).
My second idea: somehow get iptables to open ports by executable instead of by port number. This is a feature in the Windows firewall, but I don't think I have seen a way to do this with iptables.
What I'm looking for is ideas for implementing either of my ideas, or a third approach.
linux iptables
add a comment |
One of my applications uses randomly-selected ports from a port range to listen on. By default, 40000-59999.
The application runs on a firewalled server, and of course expects me to open the whole range on the firewall.
I'm not comfortable opening a large range of ports, most of which will never be used. The main concern is that another application may, also randomly, choose a port in that range and end up open to the world. I can configure the port range to be smaller, which would reduce the problem somewhat, but not truly solve it.
I have two ideas how to solve this conceptually, but don't know how/if it can actually be implemented. Operating system is RedHat Linux 7.4. The firewall is iptables/firewalld. SELinux is disabled (yes, I know, I don't like that either...)
My first idea: somehow "magically" prevent all other applications from binding to ports in this range. SELinux might be able to do that, but unfortunately I cannot use SELinux on that server (another application chokes on it).
My second idea: somehow get iptables to open ports by executable instead of by port number. This is a feature in the Windows firewall, but I don't think I have seen a way to do this with iptables.
What I'm looking for is ideas for implementing either of my ideas, or a third approach.
linux iptables
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.
– Henrik
Dec 28 '18 at 9:29
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57
add a comment |
One of my applications uses randomly-selected ports from a port range to listen on. By default, 40000-59999.
The application runs on a firewalled server, and of course expects me to open the whole range on the firewall.
I'm not comfortable opening a large range of ports, most of which will never be used. The main concern is that another application may, also randomly, choose a port in that range and end up open to the world. I can configure the port range to be smaller, which would reduce the problem somewhat, but not truly solve it.
I have two ideas how to solve this conceptually, but don't know how/if it can actually be implemented. Operating system is RedHat Linux 7.4. The firewall is iptables/firewalld. SELinux is disabled (yes, I know, I don't like that either...)
My first idea: somehow "magically" prevent all other applications from binding to ports in this range. SELinux might be able to do that, but unfortunately I cannot use SELinux on that server (another application chokes on it).
My second idea: somehow get iptables to open ports by executable instead of by port number. This is a feature in the Windows firewall, but I don't think I have seen a way to do this with iptables.
What I'm looking for is ideas for implementing either of my ideas, or a third approach.
linux iptables
One of my applications uses randomly-selected ports from a port range to listen on. By default, 40000-59999.
The application runs on a firewalled server, and of course expects me to open the whole range on the firewall.
I'm not comfortable opening a large range of ports, most of which will never be used. The main concern is that another application may, also randomly, choose a port in that range and end up open to the world. I can configure the port range to be smaller, which would reduce the problem somewhat, but not truly solve it.
I have two ideas how to solve this conceptually, but don't know how/if it can actually be implemented. Operating system is RedHat Linux 7.4. The firewall is iptables/firewalld. SELinux is disabled (yes, I know, I don't like that either...)
My first idea: somehow "magically" prevent all other applications from binding to ports in this range. SELinux might be able to do that, but unfortunately I cannot use SELinux on that server (another application chokes on it).
My second idea: somehow get iptables to open ports by executable instead of by port number. This is a feature in the Windows firewall, but I don't think I have seen a way to do this with iptables.
What I'm looking for is ideas for implementing either of my ideas, or a third approach.
linux iptables
linux iptables
asked Dec 28 '18 at 8:08
Kevin KeaneKevin Keane
335111
335111
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.
– Henrik
Dec 28 '18 at 9:29
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57
add a comment |
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.
– Henrik
Dec 28 '18 at 9:29
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?
iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.– Henrik
Dec 28 '18 at 9:29
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?
iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.– Henrik
Dec 28 '18 at 9:29
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491263%2fpreventing-other-applications-from-using-a-port%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491263%2fpreventing-other-applications-from-using-a-port%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The cleanest solution would be to configure the application to listen on a specific port. A randomly selected listening port seems a bit awkward. How do the clients know where they're supposed to connect to?
– Haxiel
Dec 28 '18 at 9:21
The only group of applicationa I've heard of that does this is FTP servers supporting passive mode. Unless you have very good reasons, you shouldn't be running an FTP server. When configuring a smaller port range, can't you just configure a range that consist of exactly one port?
iptables
supports matching on UID, so if you run the application under a dedicated UID that would be a solution.– Henrik
Dec 28 '18 at 9:29
@Haxiel I agree, but this application does not have that option. It has one "main" listening port, and then seems to open additional ports/connections per transaction. Since there can be several different users concurrently, and each transaction may also need multiple connections, I'm reasonably sure that my appication needs a range, not a single port, to work with. Some comments in the configuration file suggests that it needs at least one port per user.
– Kevin Keane
Dec 29 '18 at 0:18
@Henrik. Thank you for that idea. There is a daemon that indeed runs as one particular user. I have to double-check that it actually opens the ports as the daemon user, or as the user on whose behalf the transactions take place. Either way, this is a very helpful idea.
– Kevin Keane
Dec 29 '18 at 0:21
As far as I remember it doesn't matter which user it opens the port as, only which user it runs as when receiving data.
– Henrik
Dec 29 '18 at 0:57