1 Star 2 Fork 0

OpenVNT/vnt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Vnt

A virtual network tool (VPN)

将不同网络下的多个设备虚拟到一个局域网下

vnt-cli参数详解 参数说明

快速使用:

  1. 指定一个token,在多台设备上运行该程序,例如:

      # linux上
      root@DESKTOP-0BCHNIO:/opt# ./vnt-cli -k 123456
      # 在另一台linux上使用nohup后台运行
      root@izj6cemne76ykdzkataftfz vnt# nohup ./vnt-cli -k 123456 &
      # windows上
      D:\vnt\bin_v1>vnt-cli.exe -k 123456
  2. 可以执行info命令查看当前设备的虚拟ip

     root@DESKTOP-0BCHNIO:/opt# ./vnt-cli --info
     Name: Ubuntu 18.04 (bionic) [64-bit]
     Virtual ip: 10.26.0.2
     Virtual gateway: 10.26.0.1
     Virtual netmask: 255.255.255.0
     Connection status: Connected
     NAT type: Cone
     Relay server: 43.139.56.10:29871
     Public ips: 120.228.76.75
     Local ip: 172.25.165.58
  3. 也可以执行list命令查看其他设备的虚拟ip

     root@DESKTOP-0BCHNIO:/opt# ./vnt-cli --list
     Name                                                       Virtual Ip      P2P/Relay      Rt      Status
     Windows 10.0.22621 (Windows 11 Professional) [64-bit]      10.26.0.3       p2p            2       Online
     CentOS 7.9.2009 (Core) [64-bit]                            10.26.0.4       p2p            35      Online
  4. 最后可以用虚拟ip实现设备间相互访问

    ssh
  5. 帮助,使用-h命令查看

更多玩法

  1. 和远程桌面(如mstsc)搭配,超低延迟的体验
  2. 安装samba服务,共享磁盘
  3. 搭配公网服务器nginx反向代理,在公网访问内网文件或服务
  4. 点对网,访问内网其他机器、IP代理(结合启动参数'-i'和'-o')

使用须知

  • token的作用是标识一个虚拟局域网,当使用公共服务器时,建议使用一个唯一值当token(比如uuid),否则有可能连接到其他人创建的虚拟局域网中
  • 默认使用公共服务器做注册和中继,目前的配置是2核4G 4Mbps,有需要再扩展~
  • 需要root/管理员权限
  • vnt-cli需要使用命令行运行
  • Mac和Linux下需要加可执行权限(例如:chmod +x ./vnt-cli)
  • 可以自己搭注册和中继服务器(server)
  • vnt使用stun服务器探测网络NAT类型,默认使用谷歌和腾讯的stun服务器,也可自己搭建(-e参数指定)

编译

前提条件:安装rust编译环境(install rust)

到项目根目录下执行 cargo build -p vnt-cli

也可按需编译,将得到更小的二进制文件,使用--no-default-features排除默认features

cargo build -p vnt-cli --no-default-features

features说明

feature 说明 是否默认
openssl 使用openssl中的加密算法
openssl-vendored 从源码编译openssl
ring-cipher 使用ring中的加密算法
aes_cbc 支持aes_cbc加密
aes_ecb 支持aes_ecb加密
aes_gcm 支持aes_gcm加密
sm4_cbc 支持sm4_cbc加密
chacha20_poly1305 支持chacha20和chacha20_poly1305加密
server_encrypt 支持服务端加密
ip_proxy 内置ip代理
port_mapping 端口映射
log 日志
command list、route等命令
file_config yaml配置文件
lz4 lz4压缩
zstd zstd压缩

ip转发/代理

如果编译时去除了内置的ip代理(或使用--no-proxy关闭了代理),则可以使用网卡NAT转发来实现点对网, 一般来说使用网卡NAT转发会比内置的ip代理性能更好

NAT配置可参考如下示例,点击展开

在出口一端做如下配置

注意原有的-i(入口)和-o(出口)的参数不能少

windows

参考 https://learn.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/user-guide/setup-nat-network

#设置nat,名字可以自己取,网段是vnt的网段
New-NetNat -Name vntnat -InternalIPInterfaceAddressPrefix 10.26.0.0/24
#查看设置
Get-NetNat

linux

# 开启ip转发
sudo sysctl -w net.ipv4.ip_forward=1
# 开启nat转发  表示来源10.26.0.0/24的数据通过nat映射后再从vnt-tun以外的其他网卡发出去
sudo iptables -t nat -A POSTROUTING ! -o vnt-tun -s 10.26.0.0/24 -j MASQUERADE
# 或者这样  表示来源10.26.0.0/24的数据通过nat映射后再从eth0网卡发出去
sudo iptables -t nat -A POSTROUTING  -o eth0 -s 10.26.0.0/24 -j MASQUERADE
# 查看设置
iptables -vnL -t nat

Arch Linux

Packaging status

yay -Syu vnt
  • 通过 systemd 设置开机自启及配置
sudo systemctl enable --now vnt-cli@
sudo systemctl status vnt-cli@
  • 启用内置 IPv4 转发规则
sudo sysctl --system
  • 通过内置防火墙文件配置防火墙转发规则
sudo cat /etc/vnt/iptables-vnt.rules >> /etc/iptables/iptables.rules
sudo iptables-restore iptables.rules

macos

# 开启ip转发
sudo sysctl -w net.ipv4.ip_forward=1
# 配置NAT转发规则
# 在/etc/pf.conf文件中添加以下规则,en0是出口网卡,10.26.0.0/24是来源网段
nat on en0 from 10.26.0.0/24 to any -> (en0)
# 加载规则
sudo pfctl -f /etc/pf.conf -e

支持平台

  • Mac
  • Linux
  • Windows
    • 默认使用tun网卡 依赖wintun.dll(win-tun)(将dll放到同目录下,建议使用版本0.14.1)
    • 使用tap网卡 依赖tap-windows(win-tap)(建议使用版本9.24.7)
  • Android

GUI

支持安卓和Windows 下载

特性

  • IP层数据转发
    • tun虚拟网卡
    • tap虚拟网卡
  • NAT穿透
    • 点对点穿透
    • 服务端中继转发
    • 客户端中继转发
  • IP代理
  • p2p组播/广播
  • 客户端数据加密
  • 服务端数据加密

结构

展开
    
   0                                            15                                              31
   0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |e |s |unused| 版本(4)  |      协议(8)        |     上层协议(8)        |初始ttl(4)|生存时间(4)  |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                        源ip地址(32)                                         |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                        目的ip地址(32)                                       |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                          数据体(n)                                          |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                                                                             |
  |                                          指纹(96)                                           |
  |                                                                                             |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  注:
  1. e为是否加密标志,s为服务端通信包标志,unused占两位未使用;
  2. 开启加密时,数据体为加密后的密文(加密方式取决于密码长度和加密模式),
     且会存在指纹,指纹使用sha256生成,用于对数据包完整性和真实性的校验

Todo

  • 桌面UI(测试中)

常见问题

展开

问题1: 设置网络地址失败

可能原因:

vnt默认使用10.26.0.0/24网段,和本地网络适配器的ip冲突

解决方法:
  1. 方法一:找到冲突的IP,将其改成别的
  2. 方法二:自建服务器,指定其他不会冲突的网段
  3. 方法三:增加参数-d ,设置不同的id会让服务端分配不同的IP,从而绕开有冲突的IP

问题2: windows系统上wintun.dll加载失败

可能原因:

没有下载wintun.dll 或者使用的wintun.dll有问题

解决方法:
  1. 下载最新版的wintun.dll 下载链接
  2. 解压后找到对应架构的目录,通常是amd64
  3. 将对应的wintun.dll放到和vnt-cli同目录下(或者放到C盘Windows目录下)
  4. 再次启动vnt-cli

问题3: 丢包严重,或是不能正常组网通信

可能原因:

某些宽带下(比如广电宽带)UDP丢包严重

解决方法:
  1. 使用TCP模式中继转发(vnt-cli增加--tcp参数)
  2. 如果p2p后效果很差,可以选择禁用p2p(vnt-cli增加--use-channel relay 参数)

问题4:重启后虚拟IP发生变化,或指定了IP不能启动

可能原因:

设备重启后程序自动获取的id值改变,导致注册时重新分配了新的IP,或是IP冲突

解决方法:
  1. 命令行启动增加-d参数(使用配置文件启动则在配置文件中增加device_id参数),要保证每个设备的值都不一样,取值可以任意64位以内字符串

交流群

对VNT有任何问题均可以加群联系作者

QQ: 1034868233

赞助

如果VNT对你有帮助,欢迎打赏作者

其他

可使用社区小伙伴搭建的中继服务器

  1. -s vnt.8443.eu.org:29871
  2. -s vnt.wherewego.top:29872

参与贡献

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Rust 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/openVNT/vnt.git
git@gitee.com:openVNT/vnt.git
openVNT
vnt
vnt
main

搜索帮助

Cb406eda 1850385 E526c682 1850385