ssh tunnel tunnel hole

Forward and reverse.

Suppose, the local machine can ssh to the remote machine. The local machine is called SSHClient below, and the remote machine is called SSHServer.

1. Forward proxy (local forwarding)

Execute on the SSHClient machine:

ssh -Nf L 1234 : localhost: 12300  SSHServer -p22
Note:
1. The blue part is an ssh statement. Green is local . Red is remote .
2. The "localhost" here refers to the localhost on the SSHServer. And green 1234 is local.
3. The function of this command is: open a port 1234 on the local machine (SSHClient machine), this 1234 can forward the received data to port 12300 on the SSHServer machine.
4. Note that 1234 on the SSHClient machine is on the localhost of the SSHClient. If you want other machines on the same intranet of SSHClient (machines that can directly access SSHClient) to also be able to access this 1234, what should you do? Add the -g parameter:
ssh -g -NfL 1234:localhost:12300 SSHServer -p22
(before and after adding the -g parameter, you can see  the difference between lsof -i:1234  : LISTEN has changed from localhost to *~)
5. If you want to forward other services that can be accessed on the SSHServer machine, such as www.baidu.com:80, then replace the red in the above command with www.baidu.com:80. Then the browser opens localhost:1234, but finds that there is no egg - "Empty reply from server". . . In fact, it has been forwarded successfully, but it should be like this for http:  curl -H " Host: www.baidu.com" -X GET http://localhost:1234

 

2. The reverse proxy (remote forwarding)

is executed on the SSHClient machine:

ssh -Nf 2222 : localhost:22  SSHServer -p22
Note:
1. The blue part is an ssh statement. Green is local . Red is remote .
2. The "localhost" here refers to the localhost on the local machine (SSHClient machine). And red is a 'hole' opened in the remote machine. At this time, when you run lsof -i:2222 on the SSHServer, you will find that the port listening has been opened.
3. The purpose of this command is to open a port 2222 on the remote machine SSHServer, and this 2222 will forward the received data to port 22 on the SSHClient.
(22 is ssh, then log on to SSHServer and use ssh to connect to SSHClient: ssh -p2222 user@SSHClient )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324902556&siteId=291194637