# How to tunnel traffic from one machine to another?

I have a server, which can be seen from outside of my small network, sever has domain name and such. And I have a local machine, which can be seen by server, but is not accessible from outside.

So I want to be able to connect to port on the sever, but talk to my local machine instead.

Can I make traffic arriving on one port on the server be relayed to another port on my local machine?

-

## 2 Answers

You can simply use openssh to do so: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding

The commands to look for are -L or -R.

Let's say you want to forward port 4444 on the server to port 5555 on the local machine. On the Server use

ssh -L 4444:local_machine_name:5555 user@local_machine_name


or on the local machine use

ssh -R 4444:localhost:5555 user@server_machine_name


(In the first example you could connect to any other machine, no need to connect to local_machine_name, you could just use localhost to connect to the server itself).

Another more complex way is to use the server as a router. See https://help.ubuntu.com/community/Router and especially https://help.ubuntu.com/community/Router#Enable_IP_forwarding_and_Masquerading. This is what most small cable or DSL home router do.

-
Method with ssh works, but only for duration of the session, and requires password of user of local machine. I wanted something what could be started up automatically on the server. But still, thanks! –  Rogach Sep 21 '11 at 19:47
Guess you could use keep-alive packet for the ssh session and a non password login. Never tried it but check out following: debian-administration.org/articles/152 embraceubuntu.com/2006/02/03/keeping-ssh-sessions-alive –  mount.cifs Sep 22 '11 at 10:35

This is possible using iptables. There is a nice howto on linuxhomenetworking.com and more info on iptables can be found on the ubuntu wiki . Note that there is also a GUI interface to iptables called Firestarter.

-