Port forwarding with xinetd

jazaman picture jazaman · Feb 12, 2014 · Viewed 8.6k times · Source

I want to forward xinetd connection to another local port (say 12345). I based my solution on CentOS/Redhat documentation Chapter 17. TCP Wrappers and xinetd, article 17.4.3.3. In the example the configuration starts a daemon and also redirects the traffic to a host:port. The doco say it should be able to forward to different port on the same system too.

My current goal is to starts a daemon (say testsmpp) at any connection on port 12345 and redirect the stream to a particular port (say 54321). The tricky bit is I don't want the daemon (testsmpp) to read from STDIN, instead it should be able to read from the port where the xinetd is forwarding the traffic to.

I created a service under /etc/service e.g

testsmpp    12345/tcp

And my xinetd configuration for the daemon is

service testsmpp
{
    sock_type =     stream
    protocol =      tcp
    wait =          no
    user =          root
    server =        /home/me/bin/testsmpp        
    redirect =      54321
}

testsmpp listens on port 54321. The problem is when a connection made from outside, xinetd starts the daemon but do not forward the traffic to 54321. Once the server started I can connect directly to 54321 port but the connection made via xinetd (at port 12345) is not forwarded.

Is server and redirect tags are mutually exclusive? I looked at the discussion about xinet forking concurrent server but my motivation are slightly different. I want to listen for incoming connection on another port as the other application will communicate with the daemon on that port too in a distributed computing environment.

Any clues much appreciated.

Answer

galets picture galets · May 14, 2014

This is a sample config, obtained from this source, and it worked for me:

service smtp_forward
{
    disable         = no
    type            = UNLISTED
    socket_type     = stream
    protocol        = tcp
    user            = nobody
    wait            = no
    redirect        = remote_server 25
    port            = 2000
}