当前位置:网站首页>SSH port forwarding (Tunneling Technology)
SSH port forwarding (Tunneling Technology)
2022-07-28 13:11:00 【Love in Nanxin】
1. Local port forwarding
Assume the following scenarios , Local client A, The remote server has B and C, B and C In the same intranet , And B The public network is configured on ip,C Intranet only ip. Now there is a need , I want to make A Be able to access C The one deployed above nginx( monitor 80 port ) Service for . So how to solve this problem ? ( Premise : A Be able to initiate ssh Connect to B Server ). As shown in the figure , have access to ssh Provide local port forwarding technology to realize .

( The red arrow indicates the data return flow , Black represents the requested data flow ).
So now we can do this ssh and ssh The service side ssl The flow of data is : client A To the server B, Until then C Such a process .
curl and nginx The application data flow of is also : from A To B Until then C
command :
ssh -L 80:192.168.1.3:80 [email protected]( This can be configured ssh adopt key Form of login , Do not enter the password , Otherwise, enter the password )So now A On the implementation , curl localhost:80 You can access C Server's nginx page .
If ssl The data flow direction is consistent with the application data flow direction , Then we call it local port forwarding . On the contrary, it becomes remote port forwarding , I'll talk about it later .
In local port forwarding , We can see B In fact, it acts as a proxy The function of proxy server , hold A From local 80 Port data , after B When , The discovery packet is A Of 80 Forwarded , that B It will be forwarded to C So as to get the data and return to A.
Common practical application scenarios : long-range docker Container development , But you can't connect containers directly , Only through one agent proxy In the form of ssh Connect to the container . long-range phpstorm Only through sftp The form of is direct ssh How to connect , at present phpstorm Nothing can be configured proxy Connect by proxy fstp Remote development function of Web . At this point, the local port forwarding is working , Tunnel to remote docker The port of is ok , such phpstorm sftp The connection information can be directly connected to the local port sfpt File upload function .
2. Remote port forwarding
Suppose the above situation is now reversed , B can ssh Connect A, however A Make sure you can't connect B. So at this time ssl Data flow has become B->A, But the application data flow is still A->B->C At this time, the data flow and ssl Inconsistent flow is called remote port forwarding .
command :
ssh -f -N -L 80:192.168.1.3:80 [email protected] The server ip( This can be configured ssh adopt key Form of login , Do not enter the password , Otherwise, enter the password )such , Application data flow is still A->B->C Realization A Visit local 80 port , You can access C above nginx service .
Whether to use local port forwarding or remote port forwarding , It depends on the actual situation .
3. Dynamic port forwarding
This and the local port forward the application data flow and ssl Consistent flow direction , It's just in dynamic port forwarding ,ssh-server The server acts as socks5 Such a role of agent . It can break through the function of firewall to visit overseas websites , The premise is that you ssh-server Can visit overseas websites .
ssh -D 1080 [email protected] Offshore server ipAt this point, set the local browser proxy to socks5 For the local 1080 Port can break through the firewall restrictions to access overseas servers .
In essence, it is still that principle , When the data passes through the firewall, it is ssh-server Encrypted, so I can't judge the legitimacy of your data , So we can't intercept your request . The same is true when data is returned . however ssl Handshake has obvious flow characteristics , As long as the firewall works hard, it can recognize your data type .
Article reference : https://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/index.html
边栏推荐
- mysql limit 分页优化
- Pointnet++ Chinese Translation
- SQL most commonly used basic operation syntax
- STM32 Development Notes - experience sharing
- Black cat takes you to learn UFS agreement part 2: Interpretation of UFS related terms
- Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
- 云原生—运行时环境
- 黑猫带你学eMMC协议第27篇:什么是eMMC的动态容量(Dynamic Capacity)?
- 2020-12-07
- 机器学习实战-神经网络-21
猜你喜欢

机器学习基础-主成分分析PCA-16

Brother bird talks about cloud native security best practices

Zurich Federal Institute of technology | reference based image super resolution with deformable attention transformer (eccv2022))

Li FuPan: application practice of kata safety container in ant group

【嵌入式C基础】第5篇:原码/反码/补码

Which big model is better? Openbmb releases bmlist to give you the answer!

Ccf201912-2 recycling station site selection

Low code: reduce technical capability requirements and improve software development efficiency

Original juice multifunctional Juicer touch chip-dlt8t02s-jericho

Change the document type in endnode and import it in word
随机推荐
QT signal and slot mechanism (detailed)
Li FuPan: application practice of kata safety container in ant group
Remove the plug-in of category in WordPress link
[FPGA]: ISE generates MCS file and burning process
Ccf201912-2 recycling station site selection
Fundamentals of machine learning Bayesian analysis-14
子线程更新UI全解
机器学习实战-神经网络-21
Led aquarium lamp touch chip-dlt8t02s-jericho
[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things
企业数字化本质
Leetcode394 string decoding
[embedded C foundation] Part 9: basic usage of C language pointer
[embedded C foundation] Part 5: original code / inverse code / complement code
Problem solving during copilot trial
Black cat takes you to learn EMMC Protocol Part 26: hardware reset operation of EMMC (h/w reset)
Transaction of MySQL underlying principle (2)
Review the IO stream again, and have an in-depth understanding of serialization and deserialization
《TiDB 6.x in Action》发布,凝聚社区集体智慧的 6.x 实践汇总!
Connected Block & food chain - (summary of parallel search set)