44

I have a Linux VPS (virtuozzo) server and I need to setup port forwarding, but my hosting provider does not allow iptables-nat kernel modules so iptables -t nat - is not working.

I'm looking for other ways how to do it. I know I can forward port using openssh, but I need to forward 20+ different ports, tcp and udp so this is not an option.

Is there is any software for linux that can do port forwarding?

troex
  • 723
  • 2
  • 7
  • 9

8 Answers8

62

Use the tool called "socat", it is great tool for such things and it is already packaged in many linux distribution. Read about it here : http://www.dest-unreach.org/socat/doc/README

Port forwarding example with socat :

socat TCP4-LISTEN:80,fork TCP4:www.yourdomain.org:8080

This redirect all TCP connections on port 80 to www.yourdomain.org port 8080 TCP.

Fbo
  • 893
  • 5
  • 7
21

There's a tiny, light resources program called redir which is pretty configurable.

apt-get install redir to install on Debian-based distributions.

redir :SRC :DEST will run in the background as a daemon.

Eddie
  • 123
  • 6
Jonathan Ross
  • 2,173
  • 11
  • 14
  • I've used this tool in the past and it works very well... – Alex Sep 02 '16 at 16:06
  • I second this tool. It seems that this is not a package forwarding tool, but the tcp tunnel. It will change the source IP address seen by target. So it works great when you need to redirect one port to another computer which has a different routing setup. – scegg Oct 29 '18 at 05:10
  • wow, this is awesome, just the trick. – Eddie Apr 09 '21 at 01:09
13

What about rinetd ?
Its a daemon that redirects TCP connections. Have a look at the man page to see if it suits your needs: https://manpages.debian.org/unstable/rinetd/rinetd.8.en.html

Ian Hunter
  • 207
  • 3
  • 11
fab
  • 2,308
  • 2
  • 16
  • 14
6

xinetd supports a redirect attribute which will do what you want. As others have noted there are a number of programs which handle redirects.

Using xinetd or other program which uses the tcpwrappers library will allow you to apply access restrictions if and when it becomes necessary.

BillThor
  • 27,354
  • 3
  • 35
  • 69
4

xinet/inetd. For e. g.:

redirect

Allows a tcp service to be redirected to another host. When xinetd receives a tcp connection on this port it spawns a process that establishes a connection to the host and port number specified, and forwards all data between the two hosts.

http://linux.die.net/man/5/xinetd.conf

poige
  • 9,171
  • 2
  • 24
  • 50
4

I found small util called portfwd http://portfwd.sourceforge.net/ it does exactly what I need (TCP and UDP forwarding), homepage says it was last updated in 2002, but latest release is 2007, and it works on 2.6 kernel.

troex
  • 723
  • 2
  • 7
  • 9
  • I'll accept my answer as it seams this is the only software which fully supports both TCP and UDP protocols. – troex Apr 03 '11 at 14:41
3

SSH Does port forwarding, so long as you can tunnel in an SSL connection.

JeffG
  • 1,184
  • 6
  • 18
-3

Ok here is the simple answer that should work, it's not rocket science but most people over complicate the answer and confuse all the new to Linux users.

ufw allow 2xxx

2xxx = what ever your port number is just type that command into your server terminal and your desired port is opened up.

slm
  • 7,355
  • 16
  • 54
  • 72
denn
  • 1
  • It just opens the port on interfaces facing outside the server. It does not redirect or forward the port from one ip to the other. IT OPENS THE PORT. – HHHHHH Jul 05 '18 at 06:20