PrefaceAt first, I had a vague idea about the term "ssh port forwarding". It sounded obscure and difficult to understand. I didn't know what its function was or what its use was. So I started to look for relevant information, understand it, and use it. Later, I found that it was not that complicated. It was extremely easy to understand and use. First of all, ssh port forwarding can be divided into: local port forwarding, remote port forwarding, and dynamic port forwarding. Below I will explain each type of port forwarding separately. 1. Local port forwardingFirst run on your local host: Format ssh -L local-port:target-host:target-port tunnel-host -N Example ssh -L 8080:wwww.example.com:80 [email protected] -L is the identifier for local port forwarding At this time, local access to locahost:8080 is equivalent to remote access to www.example:com:80 Application scenarios: If the remote host deploys a server on port 9888, but the firewall does not open this port, 2. Remote port forwardingFirst run on your local host: Format ssh -R remote-port:target-host:target-port tunnel-host -N Example ssh -R 8888:localhost:8080 [email protected] -N -R is the identifier for remote port forwarding Application scenarios: 3. Dynamic port forwarding (SOCKS5)Format ssh -D local-port tunnel-host -N Example ssh -D 7999 [email protected] -N -D is the identifier for local port forwarding Note that this forwarding uses the SOCKS5 protocol and cannot be directly accessed like local/remote port forwarding. We have to convert the http request to SOCKS5 before forwarding it. The following is a request usage case curl -x socks5://localhost:7999 https://www.baidu.com curl -x socks5://localhost:7999 https://www.weibo.com At this time, local access to socks5://localhost:7999 https://www.baidu.com is equivalent to asking the remote server www.example.com to access https://www.baidu.com / https://www.weibo.com Application scenarios: If your server is located abroad, then local access to foreign links is equivalent to scientific access. Support proxy QQ data, making the host without network become connected to the network. 4. What is the difference between local port forwarding and dynamic port forwarding? The local port specifies the remote port number at the beginning, while the remote port number corresponding to dynamic port forwarding is unknown. Dynamic port forwarding is very powerful. It can not only handle HTTP, but also automatically adapt to other protocols and bind corresponding ports. For example, if you want to access QQ from a computer without Internet access, those who have used QQ know that there is a proxy setting, so we can use dynamic port forwarding to achieve Internet access. You can set the socks type and write the proxy address and port number in it, so that the data generated by QQ will be forwarded through the corresponding 111.222.333:1080 This way, even if the local machine has no network, I can use 111.222.333:1080 to help me forward data to have network access. For example, in the following situation, a host without Internet access is also connected to the Internet through the proxy method. 5. Multi-level port forwarding You can start multiple port forwarding locally, for example, we have a local machine A and two remote machines B and C Build the first ssh tunnel on the local machine ssh -L 7000:localhost:3000 [email protected] -N The remote machine www.example.com builds a second ssh tunnel by itself, which can be understood as monitoring itself. ssh -L 3000:localhost:8000 [email protected] -N The result is 6. ConclusionLocal port forwarding: local request === remote request Remote port forwarding: remote request === local request Dynamic port forwarding: local access to all external requests === remote replacement to access all external requests
So far, this article is about what is ssh port forwarding? What's the use? This is the end of the article. For more relevant ssh port forwarding content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: mysql splits a row of data into multiple rows based on commas
>>: JavaScript error handling try..catch...finally + covers throw+TypeError+RangeError
Table of contents 1. Download WeChat developer to...
1. First find the Data file on the migration serv...
The specific code is as follows: <!DOCTYPE htm...
This article is welcome to be shared and aggregat...
1. Parent components can use props to pass data t...
Docker provides multiple networks such as bridge,...
If you want to solve the slow problem once and fo...
This article records the installation and configu...
In the previous article - The charm of one line o...
An interesting discovery: There is a table with a...
The previous article introduced how Vue can reali...
The SQL query statement execution order is as fol...
The bash history command in Linux system helps to...
Simple description Since it was built with Centos...
Table of contents Integrity constraints Definitio...