在CentOS系统上进行SSH端口转发(也称为SSH隧道)可以通过几种不同的方法实现。以下是一些常见的方法:
本地端口转发允许你将本地机器上的一个端口转发到远程服务器上的一个端口。
ssh -L local_port:destination_host:destination_port user@ssh_server
假设你想将本地机器的端口8080转发到远程服务器example.com的端口80:
ssh -L 8080:example.com:80 user@ssh_server
远程端口转发允许你将远程服务器上的一个端口转发到本地机器上的一个端口。
ssh -R remote_port:destination_host:destination_port user@ssh_server
假设你想将远程服务器ssh_server的端口9090转发到本地机器的端口9090:
ssh -R 9090:localhost:9090 user@ssh_server
动态端口转发允许你将本地机器上的一个端口转发到一个SOCKS代理服务器。
ssh -D local_port user@ssh_server
假设你想将本地机器的端口1080设置为一个SOCKS代理:
ssh -D 1080 user@ssh_server
为了简化多次使用SSH端口转发的命令,你可以在~/.ssh/config文件中配置SSH客户端。
Host ssh_server
HostName ssh_server.example.com
User your_username
IdentityFile ~/.ssh/your_private_key
Host example_forward
LocalForward 8080 example.com:80
HostName ssh_server.example.com
User your_username
IdentityFile ~/.ssh/your_private_key
然后你可以简单地使用以下命令来启动端口转发:
ssh example_forward
通过这些方法,你可以在CentOS系统上轻松地进行SSH端口转发。