Forwarding a TCP Port using xinetd

Posted in Linux Corner on March 12th, 2010 by Friedrich Schäuffelhut – 2 Comments

Ever needed to forward a TCP port from one host to an other? Then xinetd is your friend!

Forwarding a port from one machine to an other one is pretty simple. Create a new file in /etc/xinetd.d, e.g. /etc/xinetd.d/portfw:

service my-web
    type        = UNLISTED
    socket_type = stream
    protocol    = tcp
    wait        = no
    user        = root
    bind        =
    port        = 8888
    only_from   =
    redirect    = 80

The keyword service is followed by the service name. The service name must either be listed in /etc/services or may be set to an arbitrary name which requires type to be set to UNLISTED. The two entries bind and port define the ip address and port xinetd will bind and listen to. Any incoming connection will be redirected to the ip address and port defined via the redirect entry.

Often you’ll find the entry only_from = localhost in /etc/xinted.conf . This will inhibit connections to the newly created port from any source besides localhost. Sadly xinetd is not very verbose about why a connection is aborted. So it can take some time to find the actual reason for a non working port forward. Using a only_from entry directly in the service configuration will overwrite the system wide default. A value of means connections from any source are accepted.

2 Comments on “ Forwarding a TCP Port using xinetd ”

Leave a Reply

1 + = four