V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hiplon
V2EX  ›  宽带症候群

OpenWRT 结合 tinc 组自己的 SDLAN(Step by Step)

  •  1
     
  •   hiplon · 2020-03-04 16:41:34 +08:00 · 7602 次点击
    这是一个创建于 1485 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本文主要实现在 OpenWRT 路由器以及不同系统下通过 tinc switch mode 搭建 SDLAN 内网服务器方便远程连接,

    Switch Mode 相对来说配置比较简单,各节点均在同一广播域内,方便调控,tinc 节点本身通过 DNAT+SNAT 可以实现对不同网间端口的调通,

    同时 Switch Mode 中各节点的 hosts 文件只需保证在公网地址的节点中全部拥有维护即可,其他节点只需维护本节点以及公网节点的 hosts 文件

    下面主要分三步:

    ( 1 )公网节点的部署(Master 节点)

    ( 2 )其他节点的部署(Slave 节点)

    ( 3 )节点的 NAT 配置

    本次搭建的拓扑以下为例,两个 Master 节点,若干个 Slave 节点(以 3 个不同操作系统的为例)

    Topo

    ( 0 ) tinc 的安装

    各大 Linux 发行版基本都可以通过包管理对 tinc 进行安装

    sudo yum install tinc
    sudo apt install tinc 
    

    OpenWRT 也可通过opkg安装 tinc

    opkg update
    opkg install tinc
    

    Windows 可在官网下载

    [https://www.tinc-vpn.org/packages/windows/tinc-1.1pre17-install.exe]: https://www.tinc-vpn.org/packages/windows/tinc-1.1pre17-install.exe "windows tinc download link"

    Windows 中自带的 TAP-Windwos 版本比较低,建议可以考虑另外安装版本较新的 TAP-Windows 新建虚拟网卡而不是用 tinc-vpn 安装包中自带的 TAP-Windows

    ( 1 )公网节点的部署(Master 节点)

    需要预先定义定义一个网络名 本次以tincnet为例NETNAME = tincnet

    每个节点均需要以以下目录结构创建好配置文件夹

    /etc/tinc/tincnet

     % ls -la
    total 24
    drwxr-xr-x 3 root root 4096 Mar  4 15:07 .
    drwxr-xr-x 4 root root 4096 Mar  4 15:06 ..
    drwxr-xr-x 2 root root 4096 Mar  4 15:06 hosts
    -rwxr-xr-x 1 root root  198 Mar  4 15:06 tinc.conf
    -rwxr-xr-x 1 root root   72 Mar  4 15:06 tinc-down
    -rwxr-xr-x 1 root root   81 Mar  4 15:06 tinc-up
    
    

    tinc.conf 为 tinc 的配置文件,tinc-down,tinc-up 为启动 tinc 时执行的脚本,一般用作启动网络,hosts 文件夹中存的是各个结点的连接交换信息。

    下面先说其中一个节点Linux_Public_Node(2.2.2.2)

    各个文件配置情况:

    tinc.conf

     % cat tinc.conf 
    Name = Linux_Public_Node #此节点名称为 Linux_Public_Node
    AddressFamily = ipv4 #Internet 走 IPv4 协议
    BindToAddress = * 11001 #监听端口
    Interface = tinctun0 #tincnet 虚拟网卡
    Device = /dev/net/tun 
    #Mode = <router|switch|hub> (router)
    Mode = switch #设置使用 Swtich 模式 默认为 router
    ConnectTo = OpenWRT_Public_Node  #连接另一公网 Master 节点保持双活
    Cipher = aes-128-cbc #对称加密算法
    

    tinc-up tinc 启动脚本,给对应网卡加 IP

     % cat tinc-up
    #!/bin/sh
    ip link set $INTERFACE up
    ip addr add 192.168.212.8/24 dev $INTERFACE
    

    tinc-down tinc 停止脚本,关停对应网卡

     %  cat tinc-down 
    #!/bin/sh
    ip addr del 192.168.212.8/24 dev $INTERFACE
    ip link set $INTERFACE down
    

    hosts 文件夹 主要保存各节点的交换信息,由于是第一次创建,里面应该是空文件夹,需要先创建一个自己节点的链接信息

     cd hosts
     touch Linux_Public_Node
    
     % cat Linux_Public_Node 
    Address = 2.2.2.2 #公网地址
    Subnet = 192.168.212.8/32 #tincnetIP 信息
    Port = 11001 #公网监听端口
    

    创建完成后通过 tincd 生成非对称密钥信息

     % sudo tincd -n tincnet -K
    Generating 2048 bits keys:
    .............+++++ p
    ........................+++++ q
    Done.
    Please enter a file to save private RSA key to [/etc/tinc/tincnet/rsa_key.priv]: 
    Please enter a file to save public RSA key to [/etc/tinc/tincnet/hosts/Linux_Public_Node]: 
    
    

    现在tincnet文件夹中会生成私钥,对应的公钥信息会补全到host/Linux_Public_Node

     % ls /etc/tinc/tincnet                    
    hosts  rsa_key.priv  tinc.conf	tinc-down  tinc-up
    
     % cat /etc/tinc/tincnet/hosts/Linux_Public_Node 
    Address = 2.2.2.2 
    Subnet = 192.168.212.8/32
    Port = 11001
    -----BEGIN RSA PUBLIC KEY-----
    MIIBCgKCAQEAp7F+8s8lukRv0qaE5hzrQmuy2MPb8hlte/G0pcfnBCVjIL5foJ7P
    LZQrTGTsKjRbPzJ9gfZUXiZRkaA+G6Q4DBOVEt41cTceZTgAzL3ief3H6MNXQ0xW
    1Wo8kDNlg6g+QJq8iV5j7adJnEPivrDm4CWl8MRmVOckisnQbseKXeuzIYDhpZLA
    nlIIGMzhk3OZoPn2xpdMbJqbR0K6SrPvYq7sT3eLn0NVUbyo9D1dmtwtOJy8wmaf
    oYdwTvrMdXhNNUmemnswJt8T2j8rAerqnjqz5itN8dk9mZMTKLFZ44CNnJ8jl5pE
    ma8lfUnAA/Qq7i9t74pVEvWcLg8HIry16QIDAQAB
    -----END RSA PUBLIC KEY-----
    

    至此,节点Linux_Public_Node(2.2.2.2)中的配置已经完成,

    下面配置另外一个节点OpenWRT_Public_Node(1.1.1.1)

    主要的配置文件生成过程节点 Linux_Public_Node 类似

    生成后如下:

    ls -la /etc/tinc/tincnet/
    drwxr-xr-x    3 root     root          4096 Mar  4 15:32 .
    drwxr-xr-x    4 root     root          4096 Mar  4 15:29 ..
    drwxr-xr-x    2 root     root          4096 Mar  4 15:32 hosts
    -rw-------    1 root     root          1680 Mar  4 15:32 rsa_key.priv
    -rwxr-xr-x    1 root     root            72 Mar  4 15:30 tinc-down
    -rwxr-xr-x    1 root     root            80 Mar  4 15:30 tinc-up
    -rw-r--r--    1 root     root           218 Mar  4 15:31 tinc.conf
    
    ls -la /etc/tinc/tincnet/hosts
    drwxr-xr-x    2 root     root          4096 Mar  4 15:32 .
    drwxr-xr-x    3 root     root          4096 Mar  4 15:32 ..
    -rw-r--r--    1 root     root           484 Mar  4 15:32 OpenWRT_Public_Node
    
    cat /etc/tinc/tincnet/tinc.conf 
    Name = OpenWRT_Public_Node
    AddressFamily = ipv4
    BindToAddress = * 11001
    Interface = tinctun0
    Device = /dev/net/tun
    #Mode = <router|switch|hub> (router)
    Mode = switch
    ConnectTo = Linux_Public_Node
    Cipher = aes-128-cbc
    
    cat /etc/tinc/tincnet/tinc-up
    #!/bin/sh
    ip link set $INTERFACE up
    ip addr add 192.168.212.6/24 dev $INTERFACE
    
    cat /etc/tinc/tincnet/tinc-down
    ip addr del 192.168.212.6/24 dev $INTERFACE
    ip link set $INTERFACE down
    
    cat /etc/tinc/tincnet/hosts/OpenWRT_Public_Node 
    Address = 1.1.1.1
    Subnet = 192.168.212.6/32
    Port = 11001
    -----BEGIN RSA PUBLIC KEY-----
    MIIBCgKCAQEA6Tzot1eXupi+NRCfr29iKbgiXEMW1Ol327WOrAwRtiwGgQIx8LcL
    iy9m+sZEWVzlfvhMub6RVM4xlZ39ghYn2OFP4x9K4D6O/HTZHbamuLOEG5zRyVGK
    EN+tTStIeEaiHad04QR+6ZFB+UO7WFcBzwVh/rysOL96KaUoU9VeYHVAIkubNsvA
    aNSFbmqGYpl5FrXv+sJjMyGRXjc9Lb3q/FWmPApvo/9FTElHx0xH7wvAZnc7mTCH
    DB6DN62A1McgydGpn7NLnuFFEeVQf3SI9TqvajcA3vXS8P9RWuRoF5HivZIL5Ebn
    FJg0UkyJcWXHUNRczdfTACF6ha0ewk8T9QIDAQAB
    -----END RSA PUBLIC KEY-----
    

    OpenWRT 下需要再对/etc/config/tinc进行以下修改

    cat /etc/config/tinc 
    config tinc-net tincnet
    	option enabled 1
    	option Name OpenWRT_Public_Node
    
    config tinc-host OpenWRT_Public_Node
    	option enabled 1
    	option net tincnet
    

    下面要做的就是先将两个 Master 节点的 hosts 文件夹各自补充对方的节点信息,简单来说就是复制自己那份过去对面,保证两个节点的 hosts 文件夹都有全部节点的 hosts 信息

    % ls -la /etc/tinc/tincnet/hosts 
    total 16
    drwxr-xr-x 2 root root 4096 Mar  4 15:37 .
    drwxr-xr-x 3 root root 4096 Mar  4 15:25 ..
    -rw-r--r-- 1 root root  486 Mar  4 15:25 Linux_Public_Node
    -rw-r--r-- 1 root root  485 Mar  4 15:37 OpenWRT_Public_Node
    
    % cat Linux_Public_Node 
    Address = 2.2.2.2 
    Subnet = 192.168.212.8/32
    Port = 11001
    -----BEGIN RSA PUBLIC KEY-----
    MIIBCgKCAQEAp7F+8s8lukRv0qaE5hzrQmuy2MPb8hlte/G0pcfnBCVjIL5foJ7P
    LZQrTGTsKjRbPzJ9gfZUXiZRkaA+G6Q4DBOVEt41cTceZTgAzL3ief3H6MNXQ0xW
    1Wo8kDNlg6g+QJq8iV5j7adJnEPivrDm4CWl8MRmVOckisnQbseKXeuzIYDhpZLA
    nlIIGMzhk3OZoPn2xpdMbJqbR0K6SrPvYq7sT3eLn0NVUbyo9D1dmtwtOJy8wmaf
    oYdwTvrMdXhNNUmemnswJt8T2j8rAerqnjqz5itN8dk9mZMTKLFZ44CNnJ8jl5pE
    ma8lfUnAA/Qq7i9t74pVEvWcLg8HIry16QIDAQAB
    
    % cat OpenWRT_Public_Node 
    Address = 1.1.1.1
    Subnet = 192.168.212.6/32
    Port = 11001
    -----BEGIN RSA PUBLIC KEY-----
    MIIBCgKCAQEA6Tzot1eXupi+NRCfr29iKbgiXEMW1Ol327WOrAwRtiwGgQIx8LcL
    iy9m+sZEWVzlfvhMub6RVM4xlZ39ghYn2OFP4x9K4D6O/HTZHbamuLOEG5zRyVGK
    EN+tTStIeEaiHad04QR+6ZFB+UO7WFcBzwVh/rysOL96KaUoU9VeYHVAIkubNsvA
    aNSFbmqGYpl5FrXv+sJjMyGRXjc9Lb3q/FWmPApvo/9FTElHx0xH7wvAZnc7mTCH
    DB6DN62A1McgydGpn7NLnuFFEeVQf3SI9TqvajcA3vXS8P9RWuRoF5HivZIL5Ebn
    FJg0UkyJcWXHUNRczdfTACF6ha0ewk8T9QIDAQAB
    -----END RSA PUBLIC KEY-----
    

    最后通过 systemctl,OpenWRT 通过 RC 启动 tinc, 并互 ping 测试一下

    #Linux_Public_Node systemctl
    systemctl start tinc@tincnet
    #OpenWRT_Public_Node rc
    /etc/init.d/tinc start
    

    ping from Linux_Public_Node(192.168.212.8) to OpenWRT_Public_Node(192.168.212.6)

    Topo

    ping from OpenWRT_Public_Node(192.168.212.6) to Linux_Public_Node(192.168.212.8)

    Topo

    ( 2 )其他节点的部署(Slave 节点)

    Linux 系统以节点OpenWRT_Internal_Node(192.168.212.12)为例

    同样,先按照之前的文件夹结构创建好对应目录,并复制两个 Master 节点 hosts 信息到 hosts 文件夹,

    ls -la /etc/tinc/tincnet/
    drwxr-xr-x    3 root     root             0 Mar  4 16:01 .
    drwxr-xr-x    4 root     root             0 Mar  4 15:52 ..
    drwxr-xr-x    2 root     root             0 Mar  4 16:01 hosts
    -rw-------    1 root     root          1676 Mar  4 16:01 rsa_key.priv
    -rwxr-xr-x    1 root     root            74 Mar  4 15:58 tinc-down
    -rwxr-xr-x    1 root     root            82 Mar  4 15:58 tinc-up
    -rw-r--r--    1 root     root           209 Mar  4 16:00 tinc.conf
    
    ls -la /etc/tinc/tincnet/hosts/
    drwxr-xr-x    2 root     root             0 Mar  4 16:01 .
    drwxr-xr-x    3 root     root             0 Mar  4 16:01 ..
    -rw-r--r--    1 root     root             0 Mar  4 15:58 Linux_Public_Node
    -rw-r--r--    1 root     root           454 Mar  4 16:01 OpenWRT_Internal_Node
    -rw-r--r--    1 root     root             0 Mar  4 15:58 OpenWRT_Public_Node
    
    cat /etc/tinc/tincnet/
    hosts/        rsa_key.priv  tinc-down     tinc-up       tinc.conf
    
    cat /etc/tinc/tincnet/tinc.conf 
    Name = OpenWRT_Internal_Node 
    Interface = tinctun0
    Device = /dev/net/tun
    #Mode = <router|switch|hub> (router)
    Mode = switch
    ConnectTo = Linux_Public_Node #此处需要配置链接到两个主节点
    ConnectTo = OpenWRT_Public_Node #此处需要配置链接到两个主节点
    Cipher = aes-128-cbc
    
    cat /etc/tinc/tincnet/tinc-up
    #!/bin/sh
    ip link set $INTERFACE up
    ip addr add 192.168.212.12/24 dev $INTERFACE
    
    cat /etc/tinc/tincnet/tinc-down
    ip addr del 192.168.212.12/24 dev $INTERFACE
    ip link set $INTERFACE down
    
    cat /etc/tinc/tincnet/hosts/OpenWRT_Internal_Node 
    Subnet = 192.168.212.21/32 #只需要配置 Subnet 参数
    
    -----BEGIN RSA PUBLIC KEY-----
    MIIBCgKCAQEAnU1maDEvbyC2XJLC8aiiwixR+einVu9gyJ4Pi1uhNMSJuVHB0HLQ
    s16eOJvoEeJ4q6x0YLwjVJLlcLRW46wUAr1eMLjiovGKcYL8fZCg+Agms3+0y2SM
    MaKi5fgBKjXLhdeBx4pvLaBlgYz4BP7pcVLgI0/NHBR6K1PClUtYDN1xCt5SOpiF
    XIwyIawwIs6mxLknm7M0a68j7e3ovIsBOW7nLVL0GpLXVJBjAbs5z00uNOVaNJkz
    tvttShGgaa+B6o1Xy8gLwB84wKNUXZbmkLobOK7h0qYgEmnQscR8Rhw5G9UJfU8G
    8nrPdRRCZnDR5xRpuy0rRJG7gAzpEJ9kHwIDAQAB
    -----END RSA PUBLIC KEY-----
    
    #以下为 OpenWRT 系统需要配置
    cat /etc/config/tinc 
    config tinc-net tincnet
    	option enabled 1
    	option Name OpenWRT_Internal_Node
    
    config tinc-host OpenWRT_Internal_Node
    	option enabled 1
    	option net tincnet
    

    然后需要复制 hosts 文件夹的本节点信息host\OpenWRT_Internal_Node到 Master 节点的 hosts 文件夹中,重启 tinc 服务即可通,

    ping 192.168.212.8
    PING 192.168.212.8 (192.168.212.8): 56 data bytes
    64 bytes from 192.168.212.8: seq=0 ttl=64 time=25.108 ms
    64 bytes from 192.168.212.8: seq=1 ttl=64 time=8.567 ms
    64 bytes from 192.168.212.8: seq=2 ttl=64 time=8.891 ms
    64 bytes from 192.168.212.8: seq=3 ttl=64 time=8.745 ms
    ^C
    --- 192.168.212.8 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 8.567/12.827/25.108 ms
    
    ping 192.168.212.6
    PING 192.168.212.6 (192.168.212.6): 56 data bytes
    64 bytes from 192.168.212.6: seq=0 ttl=64 time=7.328 ms
    64 bytes from 192.168.212.6: seq=1 ttl=64 time=6.871 ms
    64 bytes from 192.168.212.6: seq=2 ttl=64 time=7.205 ms
    64 bytes from 192.168.212.6: seq=3 ttl=64 time=7.130 ms
    ^C
    --- 192.168.212.6 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 6.871/7.133/7.328 ms
    

    再配置一个 Windows 系统的,

    首先需要新增一个 TAP-Windows 的虚拟网卡,以另外安装的新版本 TAP-Windows 驱动为例,管理员权限运行 CMD

    C:\Users\k>cd C:\Program Files\TAP-Windows\bin
    
    C:\Program Files\TAP-Windows\bin>.\addtap.bat
    
    C:\Program Files\TAP-Windows\bin>rem Add a new TAP virtual ethernet adapter
    
    C:\Program Files\TAP-Windows\bin>"C:\Program Files\TAP-Windows\bin\tapinstall.exe" install "C:\Program Files\TAP-Windows\driver\OemVista.inf" tap0901
    Device node created. Install is complete when drivers are installed...
    Updating drivers for tap0901 from C:\Program Files\TAP-Windows\driver\OemVista.inf.
    Drivers installed successfully.
    
    C:\Program Files\TAP-Windows\bin>pause
    请按任意键继续. . .
    
    

    到网络连接管理中重命名网卡名称并手动配置 IP 地址

    Topo

    Topo

    然后创建好文件目录

    C:\Program Files\tinc\tincnet 的目录
    
    2020/03/04  16:14    <DIR>          .
    2020/03/04  16:14    <DIR>          ..
    2020/03/04  16:16    <DIR>          hosts
    2020/03/04  16:17               167 tinc.conf
                   1 个文件            167 字节
                   3 个目录 144,868,106,240 可用字节
                   
    C:\Program Files\tinc\tincnet\hosts 的目录
    
    2020/03/04  16:16    <DIR>          .
    2020/03/04  16:16    <DIR>          ..
    2020/03/04  16:16               499 Linux_Public_Node
    2020/03/04  16:16               496 OpenWRT_Public_Node
    2020/03/04  16:16                27 Windows_Internal_Node
                   3 个文件          1,022 字节
                   2 个目录 144,864,964,608 可用字节
    

    C:\Program Files\tinc\tincnet\tinc.conf

    Name = Windows_Internal_Node
    Interface = tinctun0
    #Mode = <router|switch|hub> (router)
    Mode = switch
    ConnectTo = OpenWRT_Public_Node
    ConnectTo = Linux_Public_Node
    

    C:\Program Files\tinc\tincnet\hosts\Windows_Internal_Node

    Subnet = 192.168.212.116/32
    

    生成密钥

    C:\Program Files\tinc>.\tinc.exe -n tincnet
    tinc.tincnet> generate-rsa-keys
    Generating 2048 bits keys:
    ...................................................+++ p
    ......................+++ q
    Done.
    Please enter a file to save private RSA key to [C:/Program Files\tinc\tincnet\rsa_key.priv]:
    Please enter a file to save public RSA key to [C:/Program Files\tinc\tincnet\hosts\Windows_Internal_Node]:
    tinc.tincnet> quit
    
    C:\Program Files\tinc>
    

    然后将带公钥信息的 Windows_Internal_Node 复制到两个 Master 节点上面重启节点

    通过 Windows 计算机管理中的服务启动 tinc

    Topo

    PING 其他 Slave 节点测试

    C:\Program Files\tinc>ping 192.168.212.12
    
    正在 Ping 192.168.212.12 具有 32 字节的数据:
    来自 192.168.212.12 的回复: 字节=32 时间=12ms TTL=64
    来自 192.168.212.12 的回复: 字节=32 时间=11ms TTL=64
    来自 192.168.212.12 的回复: 字节=32 时间=12ms TTL=64
    来自 192.168.212.12 的回复: 字节=32 时间=11ms TTL=64
    
    192.168.212.12 的 Ping 统计信息:
        数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
    往返行程的估计时间(以毫秒为单位):
        最短 = 11ms,最长 = 12ms,平均 = 11ms
    
    

    如果还有新增节点,那么只需在节点本地创建好配置文件以及 hosts 信息,然后将本节点的 hosts 信息复制到 Master 节点上面即可。

    ( 3 )节点的 NAT 配置

    这个是补充内容,比如 Slave 节点 OpenWRT_Internal_Node 的 br-lan 网卡有另一网段 192.168.1.0/24 的地址 192.168.1.1,那么如果我想在 Windows_Internal_Node 通过 OpenWRT_Internal_Node 的 tincnet 地址 192.168.212.12:8080 直接访问 OpenWRT_Internal_Node 192.168.1.0/24 网段中的 192.168.1.20:80,那么可以可以通过 NAT 直接实现。

    具体 iptables 配置如下:

    iptables -A input_rule -i tinctun+ -j ACCEPT
    iptables -A forwarding_rule -i tinctun+ -j ACCEPT
    iptables -A forwarding_rule -o tinctun+ -j ACCEPT
    iptables -A output_rule -o tinctun+ -j ACCEPT
    
    iptables -t nat -A PREROUTING -i tinctun0 -p tcp -d 192.168.212.12 --dport 8080 -j DNAT --to-destination 192.168.1.20:80
    iptables -t nat -A POSTROUTING -s 192.168.212.0/24 -o br-lan -j SNAT --to 192.168.1.1
    

    refer: 1.openwrt-tinc

    24 条回复    2023-06-23 23:03:23 +08:00
    flynaj
        1
    flynaj  
       2020-03-04 19:29:04 +08:00 via Android
    zerotier 简单,方便,高速。你这个 11 访问 12 就要经过服务器中转
    hiplon
        2
    hiplon  
    OP
       2020-03-04 20:02:22 +08:00
    @flynaj #1 如果不想中转那么就得要全部节点都维护 hosts 也行,对比 zerotier 就是多一个选择。
    tia
        3
    tia  
       2020-03-05 19:27:41 +08:00
    在用 zerotier,自建 moon 很好用
    tallest
        4
    tallest  
       2020-03-06 12:56:15 +08:00
    @tia 说出来你可能不信,我自建 Moon 节点,在公司永远打不起洞。。
    hiplon
        5
    hiplon  
    OP
       2020-03-06 19:43:49 +08:00
    @tallest #4 可能是公司防火墙没有完全开放全部端口
    abbottcn
        6
    abbottcn  
       2020-03-08 11:01:39 +08:00 via iPhone
    我遇到过类似的问题。关闭防火墙不通,打开防火墙,允许通过,然后就畅通了。没明白为什么。
    sunulin
        7
    sunulin  
       2020-07-21 09:50:03 +08:00
    win10 64 位 装了最新虚拟网卡,名字也改了跟配置一样的 ip 也设置了
    一直提示

    tincd 1.1pre17 (Oct 8 2018 11:03:51) starting, debug level 3
    Warning: both Device and Interface specified, results may not be as expected
    No Windows tap device found!
    Disabling Windows tap device
    Terminating
    no2iam
        8
    no2iam  
       2020-07-31 10:09:36 +08:00
    @flynaj
    @tia
    遇到 ISP 不做人,疯狂 QOS 丢包,有没有办法呢?
    flynaj
        9
    flynaj  
       2020-07-31 11:35:49 +08:00
    @no2iam #8 换软件试试。zerotier ,softether
    no2iam
        10
    no2iam  
       2020-08-02 11:11:51 +08:00
    @flynaj
    说的就是 zerotier 。不支持 tcp 才被 QOS 。2.0 不知啥时候能出。
    目前看来 tinc 的方案完美。
    flynaj
        11
    flynaj  
       2020-08-02 11:27:51 +08:00
    @no2iam #10 udp 慢,有时候是路由器的问题,你不过路由器直接电脑报号看看,不行就上 softether 了!
    ciaoly
        12
    ciaoly  
       2020-10-20 10:27:38 +08:00 via Android
    tinc 1.1 preview 了好多年了,唉🌚是不是废弃了?
    weyou
        13
    weyou  
       2021-07-23 19:21:26 +08:00 via Android
    @flynaj @hiplon
    tinc 两个 slave 之间经过服务器中转?不存在的,那是你们对 tinc 的严重误解
    hiplon
        14
    hiplon  
    OP
       2021-07-23 19:33:30 +08:00
    @weyou 我没看过 tinc 源码,我测试过维护全 hosts 和不维护全 hosts 的测速结果和抓包,只有各节点有维护全 hosts 的情况可以跑满带宽不经 Master 节点,如果你有进一步的看法和源码可以提一下。
    acbot
        15
    acbot  
       2021-07-24 09:20:25 +08:00
    router switch 这两种模式有什么实质区别
    hiplon
        16
    hiplon  
    OP
       2021-07-24 09:28:13 +08:00
    @acbot 用 router 模式节点互通需要加路由,switch 各节点可以配置同网段 IP 直接互通,下面是用 router 模式的实例

    ```bash
    "routera" master-router

    tinc.conf

    Name = routera
    Device=/dev/net/tun
    TCPOnly = on
    PMTU = 1280
    PMTUDiscovery = yes
    Mode = switch
    Interface = vpn6

    tinc-up

    #!/bin/sh
    #Enable tinc
    ip -6 link set vpn6 up mtu 1280 txqueuelen 1000
    ip -6 addr add 2001:db8:beef::1/64 dev vpn6
    ip -6 route add 2001:db8:beef::/48 dev vpn6
    #Static routing table
    ip -6 route add 2001:db8:beef:2::/64 via 2001:db8:beef::2
    ip -6 route add 2001:db8:beef:3::/64 via 2001:db8:beef::3
    ip -6 route add 2001:db8:beef:4::/64 via 2001:db8:beef::4

    tinc-down

    #!/bin/sh
    #Static routing table
    ip -6 route del 2001:db8:beef:2::/64 via 2001:db8:beef:::2
    ip -6 route del 2001:db8:beef:3::/64 via 2001:db8:beef:::3
    ip -6 route del 2001:db8:beef:4::/64 via 2001:db8:beef:::4
    #Disable tinc
    ip -6 route del 2001:db8:beef::/48 dev vpn6
    ip -6 addr del 2001:db8:beef::1/64 dev vpn6
    ip -6 link set vpn6 down

    "routerb" client-router

    tinc.conf

    Name=routerb
    Device=/dev/net/tun
    TCPOnly = yes
    PMTU = 1280
    PMTUDiscovery = yes
    Mode = switch
    Interface = vpn6
    ConnectTo = routera

    tinc-up

    #!/bin/sh
    ip -6 link set vpn6 up mtu 1280
    ip -6 addr add 2001:db8:beef::2/64 dev vpn6
    ip -6 route add default via 2001:db8:beef::1

    tinc-down

    #!/bin/sh
    ip -6 route del default via 2001:db8:beef::1
    ip -6 addr del 2001:db8:beef::2/64 dev vpn6
    ip -6 link set vpn6 down

    ```
    acbot
        17
    acbot  
       2021-07-24 09:48:20 +08:00
    @hiplon 大佬,还有没有更详细的参数级中文资料,分享一下。官方的资料很多说得不清楚。比如 我前面问的问题都没有人深入研究或解释过 另外比如 TCPOnly 设置成 on 但是服务启动得时候还是会监听 UDP,难道说这里指得是 该节点对外连接得时候仅仅使用 TCP ? 等等很多疑问都不好找答案
    hiplon
        18
    hiplon  
    OP
       2021-07-24 10:29:54 +08:00
    @acbot 我也没有深入研究过,仅就停留的使用上😁
    weyou
        19
    weyou  
       2021-07-26 15:50:48 +08:00
    @hiplon

    没有看过源码, 这只是我的经验:
    1. 我有两个 slave 节点, 相互之间都没有对方的 host, 抓包可以看到数据是直接走的
    2. 而我的另外两个 slave 节点有对方 host, 数据反而是是走 master 中转的(准确的说是"有时候").

    所以个人觉得能否点对点直接传输, 跟两个节点是否有对方的 host 没有关系. 可能跟 tinc 的打洞能力有关系. 猜测只有遇到两个节点之间打洞不成功的时候, 才需要经过 public 节点中转.
    weyou
        20
    weyou  
       2021-07-26 16:17:43 +08:00
    @hiplon

    补充一下, 上面我的第 2 点走 master 的情况原因弄清楚了, 是因为有一个 slave 节点用了 TCPOnly 模式, 猜测使得 tinc 不能用 UDP 打洞了. 刚刚改了 UDP 模式, 现在抓包看, 全网 5 个节点相互之间都是直通的.
    hiplon
        21
    hiplon  
    OP
       2021-07-26 20:44:20 +08:00
    @weyou 主要还有点,我之前试过这种情况下 ipref 带宽是跑不满的
    weyou
        22
    weyou  
       2021-07-27 00:23:50 +08:00 via Android
    那就可能不是直连,可以抓包看看是不是直连,我的是 1.0.36 版本,据说 1.1 版本可以用 tinc info 来查看是不是直连,我没有试过,供你参考,来源 https://www.tinc-vpn.org/pipermail/tinc/2016-November/004685.html
    mikaelson
        23
    mikaelson  
       279 天前
    还有在用这个吗?我最近把 server 从阿里迁移到腾讯,碰到了一个很奇葩的问题
    组网成功,都能 ping 通,但是各个 slave 节点互相通信的时候,尤其是 scp 直接跟被拦截一样,一下掉到了 0kb
    mikaelson
        24
    mikaelson  
       279 天前
    @weyou
    23:00:51.968991 IP 10.86.8.1.56706 > 10.86.2.2.22: Flags [.], seq 1072475:1073845, ack 3302, win 291, options [nop,nop,TS val 3734661153 ecr 36807465], length 1370
    23:01:09.728151 IP 10.86.8.1.56706 > 10.86.2.2.22: Flags [.], seq 1072475:1073845, ack 3302, win 291, options [nop,nop,TS val 3734678912 ecr 36807465], length 1370
    23:01:45.311694 IP 10.86.8.1.56706 > 10.86.2.2.22: Flags [.], seq 1072475:1073845, ack 3302, win 291, options [nop,nop,TS val 3734714496 ecr 36807465], length 1370

    我这抓包看过去时直连吧。10.86.8.1 是本机 vip ,10.86.2.2 是对端
    但是不懂为什么总是没速度,跟被拦截了一样。一开始有速度,然后就没了。。。所有节点都这样。真奇怪。草。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1632 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.