Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

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 0.0.0.0:localport:remote_host:remote_port -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 0.0.0.0 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

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

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

share|improve this answer

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

Your Answer

 
discard

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.