Ubuntu SSH端口转发技巧主要包括以下几种:
本地端口转发:
ssh -L 8080:localhost:80 username@server_ip
将本地8080端口转发到远程服务器的80端口。远程端口转发:
ssh -R 8080:localhost:80 username@server_ip
将远程服务器的8080端口转发到本地计算机的8080端口。动态端口转发:
ssh -D 1080 username@server_ip
在本地计算机上创建一个SOCKS代理,端口为1080。使用配置文件简化端口转发:
~/.ssh/config
文件,可以简化SSH连接和端口转发。例如,配置文件中可以指定 Host example
来简化连接命令。使用 ssh -f
参数后台运行端口转发:
-f
参数可以在后台运行SSH连接,例如 ssh -fNL 13306:aliyuncs.com:3306 root@39.23.80.6
。注意事项:
AllowTcpForwarding
选项,否则转发会失败。GatewayPorts
设置。以上就是在Ubuntu系统中设置SSH端口转发的技巧和注意事项,希望对您有所帮助。