Use putty to access local services through the public network server proxy

Sometimes when you need to call a public network service for debugging, the public network service interface needs to call back the local service. For example, there is a payment interface on a public network, the interface needs to actively notify the customer of the payment status here, and the development is in the local intranet environment. Generally, the external interface service cannot be called to the local intranet, then if we have a public network with Fixed ip server, then it can be solved.

The premise is: there is a server (linux) with a fixed public network ip, local intranet customers can connect to the server through ssh, and the root account must be used.

My test example here is: public network server linux, local development machine windows7,.

Proceed as follows:

1 Install and open putty and fill in the server ip:


2 Then expand ssh > Tunnels, enter the source port as 3000, the Destination as 127.0.0.1:8080, and check Remote, then Add.



 

 

Then click the Open connection and enter the account and password.

At this point, you can find that the server has listened to port 3000. And you can use wget 127.0.0.1:3000/xxxx to access your local server xxxx listening on 8080.

But it's not over yet, because it needs to be accessed by any external machine on the public network, not on the server itself. If you directly use the server ip to access: http://115.28.16.179:3000/xxxx, it cannot be accessed because ssh limits.

Then the third step is required

3 Use putty to open another window to connect to the server. This time, don't open Tunnels as above, just connect to linux as usual.

After connecting, (requires root account login) execute the command: ssh -g -L 3001:127.0.0.1:3000 127.0.0.1

Then press Enter and enter the root password.

This step is to monitor port 3001 in the server's home province and forward it to 3000. This forwarding is local, but because the -g parameter is set, the monitoring service of 3001 can be accessed by all machines, not limited to local access.

At this point, you can ask a distant friend to access port 3001 of this server to access the services of your local intranet.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326725736&siteId=291194637