Code Monkey home page Code Monkey logo

vnt's Introduction

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中的aes_ecb算法
openssl-vendored 从源码编译openssl
ring-cipher 使用ring中的aes_gcm算法
aes_cbc 支持aes_cbc加密
aes_ecb 支持aes_ecb加密
aes_gcm 支持aes_gcm加密
sm4_cbc 支持sm4_cbc加密
server_encrypt 支持服务端加密
ip_proxy 内置ip代理

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
    • Arch Linux yay -Syu vnt
  • Windows
    • 默认使用tun网卡 依赖wintun.dll(win-tun)(将dll放到同目录下,建议使用版本0.14.1)
    • 使用tap网卡 依赖tap-windows(win-tap)(建议使用版本9.24.7)
  • Android

特性

  • 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位以内字符串

交流群

QQ: 1034868233

其他

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

  1. -s vnt.8443.eu.org:29871

参与贡献

vnt's People

Contributors

droid-max avatar lbl8603 avatar taotieren avatar ziyouwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vnt's Issues

win10是否可以运行

win10是否可以运行?看着帮助没玩起来,能不能出个简单的操作流程

Cannot read YAML File Properly

Hi,

I've been tested the vnt-cli for couple days now. I realized that if I use the yaml file to configure the vnt client, the client does not read server address correctly.

Here is my yaml file:

token: $someTokenHere name: $HostnameHere password: $SomePasswordHere server: $ServerHostName:Port ip: $AssignedIPHere mtu: 1250 parallel: 16 no-proxy: true first-latency: true

When I use the yaml file above, the vnt-cli will give me invalid ip error. Once I removed the server, I will get successful message like
version 1.2.8 ====== Connect Successfully ====== virtual_gateway:10.26.0.1 virtual_ip:10.26.0.2 ====== Create Network Interface Successfully ====== name:vnt-tun version: ====== Start Successfully ======
However, the server I run does not on the 10.26.0.1/24 virtual ip CIDR.

If I run the client by using command arguments, it works correctly.

Here is the result with command line:
version 1.2.8 ====== Connect Successfully ====== virtual_gateway:100.x.x.x virtual_ip:100.x.x.x ====== Create Network Interface Successfully ====== name:vnt-tun version: ====== Start Successfully ======

win10操作系统启动报错

C:\Users\Administrator\Desktop\vnt>vnt-cli.exe -k 123456
version 1.2.3
====== Connect Successfully ======
virtual_gateway:10.26.0.1
virtual_ip:10.26.0.5
thread 'main' panicked at 'called Result::unwrap() on an Err value: Custom { kind: Other, error: "Custom { kind: Other, error: "Failed to crate adapter" }" }', vnt-cli\src\main.rs:346:47
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

非正常断开连接会提示IP已存在?

# vnt-cli -f  /var/etc/vnt/conf.yaml
version 1.2.7
ip already exists

token: xxxxxxx
name: home
in_ips:
  - 192.168.10.0/24,10.26.0.231
out_ips:
  - 192.168.222.0/24
password: xxxxxx
ip: 10.26.0.230
punch_model: ipv4

--list 提示 not started

进程有在

root@opmain:~# ps |grep vnt
 5352 root     11172 S    /usr/bin/vnts --port 65534 --gateway 10.26.0.1 --netmask 255.255.255.0
15302 root     16928 S    /usr/bin/vnt-cli -f /var/etc/vnt/conf.yaml
15577 root      1228 S    grep vnt
root@opmain:~# /usr/bin/vnt-cli --list
cmd: Custom { kind: Other, error: "not started" }

新增功能请求

vnt-cli客户端能否增加一个--json的参数,这样可以方便其他程序调用返回参数。

在只读文件系统上提示错误,但是使用其他类似软件可以临时创建一个虚拟网卡,vnt则不行

1、直接执行
root@imx8mqevk:/opt/ycx-bak/vnt# ./vnt-cli -k 123456
thread 'main' panicked at vnt-cli/src/config/mod.rs:170:42:
called Result::unwrap() on an Err value: Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" }
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Aborted
2、增加-d参数
root@imx8mqevk:/opt/ycx-bak/vnt# ./vnt-cli -k 123456 -d test
version 1.2.8
====== Connect Successfully ======
virtual_gateway:10.26.0.1
virtual_ip:10.26.0.12
====== Create Network Interface Successfully ======
name:vnt-tun
version:
====== Start Successfully ======
command error :Read-only file system (os error 30)

aarch64-apple-darwin

在今年 WWDC23 上,最后一款使用英特尔芯片的 Mac Pro 产品转变搭载 M2 Ultra 芯片,虽然比设想中的要迟了一年,但苹果依然是彻底告别了英特尔芯片时代。
只有历史版本的mac机器使用x86_64-apple-darwin架构
新机器将是aarch64-apple-darwin架构

能帮我Releases一个aarch64-apple-darwin吗

Server端考虑开源吗?

会Server端开源或者提供Server端执行程序吗?这样就可以搭建自己的服务而不是使用公共服务

后台运行 会导致segment fault

nohup ./vnt-cli xxxx & 会导致segment fault

具体是,执行几分钟之后,就会崩溃,ps -ef 显示segment fault.
环境是ubuntu 20.04
前台运行不会崩溃。

-W参数运行不久后报错

1.2.4 :-W参数说明里面并没有,已尝试-W和-W xxxxx方式,结果都一样。现象是执行一会儿后用vnt-cli --list会报错:
cmd: Resource temporarily unavailable (os error 11)
应该执行任何命令都会报错。

另外,在其中一台linux上用非root用户执行vnt-cli,会创建3个进程,都执行的同样的命令,sudo执行也一样,用root则不会

Service

Please consider to run the Windows binary without the need to install service.

windows 11 , wintun启动不成功

用wintun的x86的dll

C:\Users\admin\Downloads\vnt-cli-i686-pc-windows-msvc-1.2.3.tar>vnt-cli.exe  -k kkkkktest
version 1.2.3
 ====== Connect Successfully ======
virtual_gateway:10.26.0.1
virtual_ip:10.26.0.3

然后程序就自动退出来,没有继续打印,在别的设备用--list能看到这个windows设备短暂online,然后offline

用wintun的amd64的dll,github 的release下载的是32位的吧

C:\Users\admin\Downloads\vnt-cli-i686-pc-windows-msvc-1.2.3.tar>vnt-cli.exe  -k kkkkktest
version 1.2.3
 ====== Connect Successfully ======
virtual_gateway:10.26.0.1
virtual_ip:10.26.0.3
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "wintun.dll not found LoadLibraryExW { source: Os { code: 193, kind: Uncategorized, message: \"%1 不是有效的 Win32 应用程序。\" } }" }', vnt-cli\src\main.rs:346:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

ssh连上就断线

比如家里有openwrt路由器和unraid,都开了ssh服务。
在公司用vnt打洞回家成功后,使用xshell ssh连openwrt和unraid,连上半分钟内必定会自动断开

root@OpenWrt:~# 
root@OpenWrt:~# Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.6.1) at 16:11:20.

别的隧道方式都不会出现这种情况。

Edge agent support

Some devices cannot run third-party programs. But I can add a server next to it as a proxy server. And want to support one to many. Or it can be configured in the router.

subnet

please consider to add a subnets parameter

switch-desktop.exe start --subnets 172.11.64.0/22,192.168.1.1/32

so other enabled peers can access the client subnets remote network

Proxy support

please consider adding
http (connect) proxy and socks5 proxy support
to be able to connect to switchserver when you are behind one of these

不指定DNS

不指定DNS, 默认用114.114.114.114, 有时运营商会干扰,用了第三方的反而会不稳。
没有指定DNS的时候,默认还是用网卡获取到的DNS吧

linux run with error

➜ sudo RUST_BACKTRACE=1 /tmp/switch/target/debug/switch-desktop  --token xxx
starting...
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 19, kind: Uncategorized, message: "No such device" })', switch/src/tun_device/linux.rs:31:40
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1113:23
   4: switch::tun_device::linux::create_tun
             at ./switch/src/tun_device/linux.rs:31:19
   5: switch::Switch::start_::{{closure}}
             at ./switch/src/lib.rs:145:13
   6: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/park.rs:283:63
   7: tokio::runtime::coop::with_budget
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/coop.rs:102:5
   8: tokio::runtime::coop::budget
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/coop.rs:68:5
   9: tokio::runtime::park::CachedParkThread::block_on
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/park.rs:283:31
  10: tokio::runtime::context::BlockingRegionGuard::block_on
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/context.rs:315:13
  11: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/scheduler/multi_thread/mod.rs:66:9
  12: tokio::runtime::runtime::Runtime::block_on
             at /home/zhijia/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/runtime.rs:284:45
  13: switch::Switch::start
             at ./switch/src/lib.rs:48:22
  14: switch_desktop::main
             at ./switch-desktop/src/main.rs:78:18
  15: core::ops::function::FnOnce::call_once
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.