Use SSH port forwarding to achieve remote access to network hosts Remote Desktop (a) establish SSH forwarding

The recent replacement of the broadband mobile home after dialing get is the beginning of the 10 network IP, it can not be like before, like remote desktop access from outside the network through the host router's port mapping. In this case you can use one server with a public IP network to act as transit, use SSH tunnel Remote Desktop forwarding function will forward the request to the host within the network.

SSH tunnel

SSH automatically encrypts and decrypts the data network between all SSH client and server, in addition to other SSH also be able to network data to TCP port forwarding through SSH link, and automatically provides the appropriate encryption and decryption services, this feature is also known as "SSH tunnel." SSH tunnel is divided into local forwarding, remote forwarding and dynamic forwarding.

Local Forwarding

Locally on the client listening on the specified port that receives data will be forwarded to the designated port designated IP server network.

Remote Forwarding

In the server listening on the specified port that receives data will be forwarded to the client specified IP local network of designated ports.

Dynamic forward

Locally on the client listening on the specified port, which is actually a SOCKS5 proxy, all requests issued by the server.

Preparing the Environment

  1. The server has a public IP, where the use of cloud Ali ECS
  2. Putty

Server Settings

Edit ssh configuration files, enable GatewayPorts. If GatewayPorts option is not enabled, remote port forwarding only the server can access the external host can not access.

vi / etc / ssh / sshd_config 
at the end add a line 
GatewayPorts yes 

# ssh restart the service 
service sshd restart

Client Settings

Start Putty on the client, enter the server address in the Session.

Switch to the Connection-SSH-Tunnels, enter the listening port outside the network server in the Source port, Destination forwarded enter the IP address and port number in the format IP地址:端口, select the type of forwarding remotely, click Add to add to the list. Here we will map the server port 10000 to the 3389 port of the machine.

 

Select the open, enter a user name and password. After the successful landing view the listening port, port 10000 has been found to listen.

[root@iZwz9ds6obifn90aw8j2khZ ~]# netstat -aon|grep 10000
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      off (0.00/0/0)

Such a tunnel between the network and the host server has been established, log in to the network through the host port 10000 to the remote access server.

However, using this method every time input on the host controlled manually run Putty username and password, in case of off network, system updates, restart, power outage, etc. can not automatically restore the connection. Then we configured to use SSH certificate avoid dense landing and Autossh automatically reconnect.

Guess you like

Origin www.cnblogs.com/lunarflyer/p/11408721.html