SSH tunneling examples

本文介绍了如何使用SSH进行本地和远程隧道配置,包括Localtunneling和Remotetunneling的具体命令示例,以及如何设置autossh以实现SSH隧道的自动重启。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Local tunneling

Run the command below on your local PC.

ssh -Nf -L 9000:www.google.com:80 server_user@your_ssh_server.com
In your browser go to

http://localhost:9000.


2. Remote tunneling

Run the command below on PC you want to access.

ssh -Nf -R 9922:127.0.0.1:22 server_user@your_ssh_server.com
Run the command below on PC you are using outside.

ssh local_user@your_ssh_server.com -p 9922


3. Autossh

$ cat /etc/init/autossh.conf
description "autossh tunnel"

start on (local-filesystems and net-device-up IFACE=eth0 and net-device-up IFACE=eth1) # assuming we have multiple interfaces
stop on runlevel [016]
        
respawn
respawn limit 5 60
        
exec autossh -M 0 -N -R 6607:127.0.0.1:22 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "StrictHostKeyChecking=no" -o "BatchMode=yes" -i /home/bignet/.ssh/id_rsa test@110.119.122.2

$ sudo service autossh status
autossh start/running, process 24254

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值