Method of using SSH to implement port mapping under Linux system

Source: Internet
Author: User
Tags socket ssh server port

You can bind the remote server port Remote_port to the local port, where-c is data compression,-f is the background operation, only when the user name password is prompted to the foreground. -N is not a remote command, which is useful in the case of only port forwarding. -G allows the remote host to connect to the local forwarding port. -R indicates that the remote host port is mapped to a local port. If-l, the local port is mapped to the remote host port.

Three powerful port forwarding commands for SSH:

Forward to remote: ssh-c-f-n-g-l Local port: Destination IP: Destination port user name @ Destination IP

Forwarding to Local: ssh-c-f-n-g–r Local port: Destination IP: Destination port user name @ Destination IP

The code is as follows:

Ssh-c-f-n-g-d Listen_port user@tunnel_host

-C: Compressed data transfer.

-F: Background authenticated user/password, usually used with-n without logging on to the remote host.

-N: Script or command is not executed, and is usually used with-F.

-G: In the-l/-r/-d parameter, the remote host is allowed to connect to the established forwarding port, and if this parameter is not added, only the local host is allowed to establish a connection.

-L Local Port: Destination IP: Destination port

Forwards a port on the local machine (client) to the specified port on the remote specified machine. How it works is that a socket on the local machine is assigned to listen on the port, and once connected on the port, the connection is forwarded through a secure channel, while the remote host and the host's Hostport port are connected. You can specify the forwarding of ports in the configuration file. Only Root can forward privileged ports. The IPV6 address is described in another format: Port/host/hostport

-R Local Port: Destination IP: Destination port

Forwards a port on a remote host (server) to the specified port on the local-side specified machine. How it works is that a socket on the remote host is assigned to listen on port ports, and once a connection is made on the port, the connection is diverted through a secure channel, while the local host and host Hostport ports are connected. You can specify the forwarding of ports in the configuration file. You must log on to a remote host with Root to forward privileged ports. The IPV6 address is described in another format: Port/host/hostport

-P: The SSHD service port of the logged on SSD server.

-D Port

Specifies a local machine "dynamic" Application port forwarding. How it works is that a socket on the local machine is assigned to listen to the port, and once a connection is made on the port, the connection is forwarded through a secure channel, depending on the protocol of the application to determine where the remote host will be connected. Currently supports the SOCKS4 protocol and will act as a SOCKS4 server. Only Root can forward privileged ports. You can specify the forwarding of dynamic ports in the configuration file. >

Application examples

1. Forward 80 port access to the 174.139.9.66 to port 8080

The code is as follows:

Ssh-c-f-n-g-l 80:174.139.9.66:8080 master@174.139.9.66

2. Spoke to 174.139.9.66 8080 access forwarded to the local 80 port

The code is as follows:

Ssh-c-f-n-g-r 80:174.139.9.66:8080 master@174.139.9.66

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.