Locally forward tcp port bidirectional
up vote
0
down vote
favorite
I wonder how it is possible to locally forward a tcp port, bidirectional, i. e. all packets leaving the local machine on port 25 (this port of course is actually dynamically assigned) should be rewritten to have a source port of e. g. 500 (thats the part I dont know how to do), and all ports coming in on port 500 should be forwarded to port 25 (I know how to do this).
In consequence, a daemon listening on port 25 would be happy, while all destinations would believe the daemon is listening on port 500. Correct me if I am wrong.
linux iptables tcp port-forwarding
add a comment |
up vote
0
down vote
favorite
I wonder how it is possible to locally forward a tcp port, bidirectional, i. e. all packets leaving the local machine on port 25 (this port of course is actually dynamically assigned) should be rewritten to have a source port of e. g. 500 (thats the part I dont know how to do), and all ports coming in on port 500 should be forwarded to port 25 (I know how to do this).
In consequence, a daemon listening on port 25 would be happy, while all destinations would believe the daemon is listening on port 500. Correct me if I am wrong.
linux iptables tcp port-forwarding
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wonder how it is possible to locally forward a tcp port, bidirectional, i. e. all packets leaving the local machine on port 25 (this port of course is actually dynamically assigned) should be rewritten to have a source port of e. g. 500 (thats the part I dont know how to do), and all ports coming in on port 500 should be forwarded to port 25 (I know how to do this).
In consequence, a daemon listening on port 25 would be happy, while all destinations would believe the daemon is listening on port 500. Correct me if I am wrong.
linux iptables tcp port-forwarding
I wonder how it is possible to locally forward a tcp port, bidirectional, i. e. all packets leaving the local machine on port 25 (this port of course is actually dynamically assigned) should be rewritten to have a source port of e. g. 500 (thats the part I dont know how to do), and all ports coming in on port 500 should be forwarded to port 25 (I know how to do this).
In consequence, a daemon listening on port 25 would be happy, while all destinations would believe the daemon is listening on port 500. Correct me if I am wrong.
linux iptables tcp port-forwarding
linux iptables tcp port-forwarding
edited yesterday
Rui F Ribeiro
38.6k1479128
38.6k1479128
asked Nov 2 at 14:44
L. Riemer
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
When you redirect port 25 to port 500, you don't need to redirect port 500 to port 25 again. NAT works with connections and it will handle return packets for you.
For example try to redirect port 23 to port 22 which ssh is listening
iptables -t nat -A PREROUTING -p tcp --dport 23 -j REDIRECT --to-port 22
Now you can connect that device via port 23
ssh foo@mysshserver -p 23
In your case you should add this rule
iptables -t nat -A PREROUTING -p tcp --dport 500 -j REDIRECT --to-port 25
Now all client are able to connect via port 500 to daemon which is listening port 25
add a comment |
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',
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%2f479412%2flocally-forward-tcp-port-bidirectional%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
When you redirect port 25 to port 500, you don't need to redirect port 500 to port 25 again. NAT works with connections and it will handle return packets for you.
For example try to redirect port 23 to port 22 which ssh is listening
iptables -t nat -A PREROUTING -p tcp --dport 23 -j REDIRECT --to-port 22
Now you can connect that device via port 23
ssh foo@mysshserver -p 23
In your case you should add this rule
iptables -t nat -A PREROUTING -p tcp --dport 500 -j REDIRECT --to-port 25
Now all client are able to connect via port 500 to daemon which is listening port 25
add a comment |
up vote
1
down vote
When you redirect port 25 to port 500, you don't need to redirect port 500 to port 25 again. NAT works with connections and it will handle return packets for you.
For example try to redirect port 23 to port 22 which ssh is listening
iptables -t nat -A PREROUTING -p tcp --dport 23 -j REDIRECT --to-port 22
Now you can connect that device via port 23
ssh foo@mysshserver -p 23
In your case you should add this rule
iptables -t nat -A PREROUTING -p tcp --dport 500 -j REDIRECT --to-port 25
Now all client are able to connect via port 500 to daemon which is listening port 25
add a comment |
up vote
1
down vote
up vote
1
down vote
When you redirect port 25 to port 500, you don't need to redirect port 500 to port 25 again. NAT works with connections and it will handle return packets for you.
For example try to redirect port 23 to port 22 which ssh is listening
iptables -t nat -A PREROUTING -p tcp --dport 23 -j REDIRECT --to-port 22
Now you can connect that device via port 23
ssh foo@mysshserver -p 23
In your case you should add this rule
iptables -t nat -A PREROUTING -p tcp --dport 500 -j REDIRECT --to-port 25
Now all client are able to connect via port 500 to daemon which is listening port 25
When you redirect port 25 to port 500, you don't need to redirect port 500 to port 25 again. NAT works with connections and it will handle return packets for you.
For example try to redirect port 23 to port 22 which ssh is listening
iptables -t nat -A PREROUTING -p tcp --dport 23 -j REDIRECT --to-port 22
Now you can connect that device via port 23
ssh foo@mysshserver -p 23
In your case you should add this rule
iptables -t nat -A PREROUTING -p tcp --dport 500 -j REDIRECT --to-port 25
Now all client are able to connect via port 500 to daemon which is listening port 25
edited Nov 9 at 10:14
answered Nov 6 at 19:01
ibrahim
392212
392212
add a comment |
add a comment |
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%2f479412%2flocally-forward-tcp-port-bidirectional%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