LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Simple port forwarding question (http://www.linuxquestions.org/questions/linux-networking-3/simple-port-forwarding-question-4175440970/)

abentkov 12-11-2012 08:42 AM

Simple port forwarding question
 
Hi folks,
Not a guru by any means and everything i have learned on linux is from google and search. Now this one i cant seem to find an answer to.

Scenario: Centos 5.
I have a service running on port 11111 and 22222. I have incoming connections from different IPs to these two ports. Now I need to merge them and forward all incoming 11111 to 22222.

So from different perspective, a user connecting on 11111 would connect to xx.xx.xx.xx:11111 but would be connected to xx.xx.xx.xx:22222

Any help would be appreciated.

blueh2o 12-11-2012 09:50 AM

You could redirect the port using xinetd, or iptables could do this for you as well.

abentkov 12-11-2012 10:10 AM

could you please let me know which method is easier? is there a guide i can read to quickly set this up?

blueh2o 12-11-2012 10:25 AM

To use xinetd, you would drop a file in to /etc/xinetd.d with a name of your choosing, containing something like the following:

Code:

service some-useful-name
{
    disable = no
    port = 11111
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    redirect = xx.xx.xx.xx 22222
}

Make sure xinetd is set to start at boot and is running:
Code:

# chkconfig xinted on
# service xinetd start

Here's a useful guide for redirecting with iptables:

http://www.cyberciti.biz/faq/linux-p...with-iptables/

abentkov 12-11-2012 10:32 AM

Quote:

Originally Posted by blueh2o (Post 4847059)
To use xinetd, you would drop a file in to /etc/xinetd.d with a name of your choosing, containing something like the following:

Code:

service some-useful-name
{
    disable = no
    port = 11111
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    redirect = xx.xx.xx.xx 22222
}

Make sure xinetd is set to start at boot and is running:
Code:

# chkconfig xinted on
# service xinetd start

Here's a useful guide for redirecting with iptables:

http://www.cyberciti.biz/faq/linux-p...with-iptables/

So if I have user db that are strictly for 11111 and migrate them over to db on 22222 anyone connecting on 11111 should be able to hit port 22222 correct?

also

for redirect = xx.xx.xx.xx 22222 would I do 127.0.0.1 22222 ?

blueh2o 12-11-2012 10:42 AM

Quote:

Originally Posted by abentkov (Post 4847063)
So if I have user db that are strictly for 11111 and migrate them over to db on 22222 anyone connecting on 11111 should be able to hit port 22222 correct?

Yes.

Quote:

for redirect = xx.xx.xx.xx 22222 would I do 127.0.0.1 22222 ?
Try that.


All times are GMT -5. The time now is 12:16 PM.