128M RAM 的小鸡只能当玩具,没别的用处?其实不是。只要它还有一个公网 IP ,那就可以让你远程访问家里的电脑,或者远程桌面,或者是让你在树莓派上建的站能在公网访问。
什么是 otunnel ?
otunnel 是一个开源的点对点隧道工具。简单地说,它可以把设备的一个本地端口与 VPS 上的一个远程端口相连接。访问 VPS 的远程端口,相当于访问本地端口。可用于MC服务器
或树莓派
等
Github项目地址
当然,上面说的是反向代理, otunnel 还可以正向工作,把远程端口与本地端口相连接,让访问本地端口相当于访问远程端口。
最简单的实例
我的电脑上的 9999 端口运行有网页服务器 nginx 。但是我处在内网,没有公网 IP ,因此网页也只能在局域网内访问。但是好在我有一个 VPS ,我想把 VPS 的 80 端口与本地的 9999 端口相连接,这样访问 VPS 的 80 端口,就可以在公网访问我局域网内的网站了。
- 假设 server 的地址为 example.com
- 从 client 能连接 server (client 与 server 无需在同一个网络)otunnel 程序可以作为 server 和 client 两种角色(运行参数不同)
第一步,设置服务器
通过SSH连线到VPS。下载适用于服务器的otunnel。
第一步,设置服务器
通过SSH连线到VPS。下载适用于服务器的otunnel。
# Linux 64位使用:
wget https://dl.ooclab.com/otunnel/1.2.3/otunnel_linux_amd64 && chmod +x otunnel_linux_amd64
# Linux 32位使用:
wget https://dl.ooclab.com/otunnel/1.2.3/otunnel_linux_386 && chmod +x otunnel_linux_386
# Linux ARM架构使用:
wget https://dl.ooclab.com/otunnel/1.2.3/otunnel_linux_arm && chmod +x otunnel_linux_arm
接着运行服务端程序。
# Linux 64位使用:
./otunnel_linux_amd64 listen :10000 -s [自定义密钥] >> otunnel.log 2>&1 &
# Linux 32位使用:
./otunnel_linux_386 listen :10000 -s [自定义密钥] >> otunnel.log 2>&1 &
# Linux ARM架构使用:
./otunnel_linux_arm listen :10000 -s [自定义密钥] >> otunnel.log 2>&1 &
第二步,客户端连线
从 https://dl.ooclab.com/otunnel/1.2.3/ 上下载适合自己系统的程序。打开终端切换到下载的程序所在目录,执行:
./otunnel_*** connect [VPS的IP]:10000 -s [刚才指定的密钥] -t 'r:192.168.1.101:9999::666'
最后一部分的格式:
代理类型:本地地址:本地端口:远程地址:远程端口
本地地址
或 远程地址
如果为空,表示所有网口
otunnel 命令行可以包含多个 -t
选项,同时指定多条隧道规则
本实例使用反向代理,本地地址为192.168.1.101,端口为9999,要连接的远程端口为666。