Server Fault is a question and answer site for system and network administrators. 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

Please suggest the easiest way to forward all connections from host:port(external interface) to host2:port(external interface)

When i use

ssh -L local_port:remote_host:remote_port -N -l user remote_host

main problem is that local_port must support connection also on external interface to allow connections not only from localhost on that machine

Thanks in advice

share|improve this question
up vote 1 down vote accepted

I'd go with either of these routes:

  • Use a bridge, this is only possible if you do not need access to the host on any of the 2 interfaces involved
  • Use ipf to install the corresponding firewall routes
  • ssh -L -N -l user remote_host this way ssh will bind to all interfaces not only to the local which is only a default
share|improve this answer
Instead of you can use * to bind all interfaces. Check ssh(1) manpage. – therek Jun 11 '09 at 8:41
The problem quickly solved, thanks! – duganets Jun 11 '09 at 8:52

You did not explain what are you going to use port forwarding for. So, I'd venture to propose, additionally to using -L flag, setting up a SOCKS proxy for applications that support it (for example Firefox):

ssh -D *:9999 user@remote_host

Common use is to configure Firefox to use this SOCKS proxy, with network.proxy.socks_remote_dns turned on, to tunnel your HTTP session through other host.

share|improve this answer
main purpose was transparently forward connections from host1(old) on concrete port to host2(new) same port host1 contains server, that accept users connections, this server were moved and until dns database is updating need support also connections to old host this is the task – duganets Jun 11 '09 at 9:16

You're missing the -g flag. Add that and remote hosts can use the tunnel too.

share|improve this answer

If you are using freebsd then best way is to use firewall:

kldload pf
echo "rdr on INT proto tcp from any to any port PORT1 -> IP2 port PORT2" > /etc/pf.conf
pfctl -f /etc/pf.conf
pfctl -e

INT - interface name (i.e. rl0)

this command will forward from INT:PORT1 to IP2:PORT2

It's fastest and most customizable method of forwarding ports but it's BSD-only

Check PF FAQ for more

share|improve this answer
thx, am i wrong when think you talk about one machine with serveral interfaces (ip's)? but i have to different freebsd host on two different ISP's and one possible connection between it only via internet – duganets Jun 13 '09 at 9:43

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.