SSH port forwarding is divided into two types, one is local port forwarding, also known as the local SSH tunnel. is always remote port forwarding. SSH port forwarding, you must also specify the destination host for the data transfer, thus forming a point-to-point port forwarding.
Local Port forwarding
assume that there are three hosts a, B, C. For a variety of reasons (whether it is a firewall or a routing cause), there is no connection between the AC two hosts. But B can connect with a and C. At this point, you can use local port forwarding to achieve A and C through B to connect. A 192.168.7.27B 192.168.6.19C 192.168.30.686 network segment and 7 network segment, 30 network segment are all connected, but 7 network segment and 30 network segment is not pass, now need to access 7 network segment from 30 segment of a Web service, can be implemented by local port forwarding. First, make sure that the SSH service of A and B turns on allow forwarding: gatewayports Yes, allowtcpforwarding Yes execute the following command on a:
Ssh-l test-l 192.168.7.27:59000:192.168.30.68:80 192.168.6.19
There are four values separated by colons after the parameter-L, which are ' local address: Local Port: Target host: Destination host Port '. This command means that SSH binds the 59000 port of the 192.168.7.27, and then specifies that 192.168.6.19 will forward all the data to port 80 of the target host 192.168.30.68.
So, all we have to do is connect the 59000 port of a local address on a, which is equal to the 80 port of 192.168.30.68.
Curl Http://192.168.7.27:59000/
This local port forwarding is suitable for a is enterprise LAN machine, B, C are on the WAN has a separate public network IP machine, but the enterprise's firewall block A and C direct communication, but allow A and B communication, so that a can communicate through B and C.
Remote port forwarding
assume that there are three hosts a, B, C. A is the enterprise intranet machine, B is a company with a private network IP and public IP server (similar gateway), C is the Internet with a public IP server, a can be directly connected to the C,B can be directly connected to a (intranet), can also be directly connected to C (public network), However, because a is in the net, C cannot connect directly to a, but C can connect via B. A 10.1.6.234
B 114.80.130.88/10.1.10.1
C 119.75.218.77
Execute the following command on B:
Ssh-l taomee-p 58000-r 10.1.10.1:59000:10.1.6.234:80 119.75.218.77
Execute the following command on C:
Curl http://10.1.6.234