Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

You can simply use openssh to do so:

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 and especially This is what most small cable or DSL home router do.

share|improve this answer
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: – mount.cifs Sep 22 '11 at 10:35

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.