Skip to content

Latest commit

 

History

History
131 lines (101 loc) · 3.94 KB

README.zh.md

File metadata and controls

131 lines (101 loc) · 3.94 KB

NPM version build status Test coverage Gittip David deps node version npm download

tcp-tunnel

  • 快速建立TCP隧道,方便将服务器上的端口映射到内网主机
  • 支持多客户端及密码认证
  • 客户端只需要配置连接密码即可,端口映射关系由服务器管理
  • 服务器支持热更新配置

安装

要求系统已安装Node.js v4.0或以上版本

$ npm install tcp-tunnel -g

原理

  • 服务器端启动,监听配置的端口列表
  • 客户端连接到服务器,校验密码,建立控制连接通道
  • 服务器端监听到连接请求,生成session_id并发送给相应的客户端
  • 客户端收到session_id后,连接服务器端,并发送此session_id验证
  • 建立反向连接成功,服务器将接收到的数据发送给客户端,并将客户端发送过来的数据发送出去

配置

服务器端配置文件server.conf

# 服务器配置
:value
port = 5000

# 客户端名称及密码
# 名称:密码
:client
A:123456
B:123456

# 转发规则
# 本地端口 -> 客户端:端口
:rule
2022 -> A:22
3306 -> A:3306
6379 -> B:6379

客户端配置文件client.conf

:value
name = A
password = 123456
server = 192.168.9.10
serverPort = 5000

# 本地端口映射
# 原端口 -> 目标地址:端口
:rule
3306 -> 192.168.99.100:3306
6379 -> 192.168.99.100:6379

启动客户端

$ ttclient -c client.conf

启动服务端

$ ttserver -c server.conf

如果更改了配置项中的:client:rule部分,可在执行时添加-r选项重新加载配置(热更新,服务进程不重启):

$ ttserver -c server.conf -r

License

The MIT License (MIT)

Copyright (c) 2016 Zongmin Lei (老雷) <leizongmin@gmail.com>
http://ucdok.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.