走在路上需要访问家里的电脑?回家了还要访问公司内网加班?身在校外还想内网抢课?内网建站公网无法访问?只要你有一个拥有公网IP的VPS,加上otunnel,只需两步,一切变迎刃而解。
什么是 otunnel ?
otunnel 是一个开源的点对点隧道工具。简单地说,它可以把设备的一个本地端口与VPS上的一个远程端口相连接。访问VPS的远程端口,相当于访问本地端口。
当然,上面说的是反向代理,otunnel还可以正向工作,把远程端口与本地端口相连接,让访问本地端口相当于访问远程端口。
otunnel采用AES加密,连线时可以制定密钥,保证连线安全。
在Github上查看otunnel:https://github.com/ooclab/otunnel
最简单的实例
我的电脑上的9927端口运行有网页服务器nginx。但是我处在内网,没有公网IP,因此网页也只能在局域网内访问。但是好在我有一个VPS,我想把VPS的666端口与本地的9927端口相连接,这样访问VPS的666端口,就可以在公网访问我局域网内的网站了。
第一步,设置服务器
通过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:9927::666'
最后一部分的格式:
代理类型:本地地址:本地端口:远程地址:远程端口
本实例使用反向代理,本地地址为192.168.1.101,端口为9927,要连接的远程端口为666。
详细说明请参见otunnel的文档:https://github.com/ooclab/otunnel/wiki/USAGE.zh_CN