GithubHelp home page GithubHelp logo

xjasonlyu / tun2socks Goto Github PK

View Code? Open in Web Editor NEW
2.7K 33.0 384.0 6.14 MB

tun2socks - powered by gVisor TCP/IP stack

Home Page: https://github.com/xjasonlyu/tun2socks/wiki

License: GNU General Public License v3.0

Go 95.44% Dockerfile 0.43% Makefile 2.92% Shell 1.20%
golang tun2socks socks5 gvisor tcpip-stack shadowsocks go tunnel network tun-device wireguard udp socks4 nat tor proxy gfw ssh-tunnel http-proxy proxifier-alternative

tun2socks's Introduction

tun2socks

GitHub Workflow Go Version Go Report Maintainability GitHub License Docker Pulls Releases

English | 简体中文

Features

  • Proxy Everything: Handle all network traffic of any internet programs sent by the device through a proxy.
  • Proxy Protocols: HTTP/Socks4/Socks5/Shadowsocks with authentication support for remote connections.
  • Run Everywhere: Linux/macOS/Windows/FreeBSD/OpenBSD multi-platform support with specific optimization.
  • Gateway Mode: Act as a layer three gateway to handle network traffic from other devices in the same network.
  • Full IPv6 Support: All functions work in IPv6, tunnel IPv4 connections through IPv6 proxy and vice versa.
  • Network Stack: Powered by user-space TCP/IP stack from Google container application kernel gVisor.

Benchmarks

For all scenarios of usage, tun2socks performs best. See here for more details.

benchmark

Documentation

Full documentation and technical guides can be found at Wiki.

Community

Welcome and feel free to ask any questions at Discussions.

Credits

License

GPL-3.0

FOSSA Status

Star History

Star History Chart

tun2socks's People

Contributors

amaindex avatar cty123 avatar ghostiam avatar jackarain avatar linfan avatar myloft avatar nange avatar niconorsk avatar xjasonlyu avatar yawning 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tun2socks's Issues

udp not working

i m trying v2.1.0 linux amd64 with command ./tun2socks-linux-amd64 -device tun://tun0 -proxy socks5://127.0.0.1:1080

I m routing all traffic from another linux on the network to the tun interface.

Tcp is working great but udp is not working at all.

i ve got this

WARN[7446] [UDP] write to 1.1.1.1:53 error: write udp [::]:40930->127.0.0.1:0: sendto: invalid argument
INFO[7446] [UDP] 192.168.0.35:34418 --> 1.1.1.1:53

found packages sync

root@yy:/home/tun2socks# go get  -d github.com/xjasonlyu/tun2socks
found packages tcp (accept.go) and rcv (rcv_test.go) in /home/gopkg/src/gvisor.dev/gvisor/pkg/tcpip/transport/tcp
root@yy:/home/tun2socks# /home/gopkg/src/github.com/xjasonlyu/tun2socksc^C
root@yy:/home/tun2socks# cd /home/gopkg/src/github.com/xjasonlyu/tun2socks
root@yy:/home/gopkg/src/github.com/xjasonlyu/tun2socks# ls
assets  Dockerfile  go.sum    LICENSE  Makefile  README.md
docker  go.mod      internal  main.go  pkg       scripts
root@yy:/home/gopkg/src/github.com/xjasonlyu/tun2socks# go build
../../../gvisor.dev/gvisor/pkg/tcpip/tcpip.go:41:2: found packages sync (aliases.go) and template (atomicptr_unsafe.go) in /home/gopkg/src/gvisor.dev/gvisor/pkg/sync
../../../gvisor.dev/gvisor/pkg/tcpip/adapters/gonet/gonet.go:29:2: found packages tcp (accept.go) and rcv (rcv_test.go) in /home/gopkg/src/gvisor.dev/gvisor/pkg/tcpip/transport/tcp

socks5 connect ipv6

./tun2socks-linux-amd64 --loglevel WARN --device tun://tun0 --proxy socks5://[::1]:1080 --interface eth0

不可用

./tun2socks-linux-amd64 --loglevel WARN --device tun://tun0 --proxy socks5://127.0.0.1:1080 --interface eth0

正常。

Problem with dns

Hi
I'm using go-tun2socks and my attached router can resolve dns requests through that. Commands that i'm using:
go-tun2socks -proxyServer "ip:1080" -tunName tun2
ip addr add dev tun2 10.255.0.2
*ip link set dev tun2 up
ip route add socks-server-ip via default-gw-ip
ip route add 0/1 dev tun2
ip route add 128/1 dev tun2
Both socks server and client support udp and everything works but with a bit latency.
Yesterday, i switched to your project with this commands:
tun2socks-linux-amd64 --device tun://tun2 --proxy socks5://ip:1080 --interface wlan0 # my local machine gets internet via wlan0
ip addr add dev tun2 198.18.0.1/15
And other cmds are like upper *
But then could not use any dns request to public resolvers like 8.8.8.8 or 9.9.9.9
Do i need to do any further action? With fake dns function (--dns dns://:53) i can browse internet but there is issue with torrent download!
Thank you

编译报错,求大佬指点一番

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: 找不到 -lpthread
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: 找不到 -lc
collect2: error: ld returned 1 exit status

use v2.2.1, get panic: unaligned 64-bit atomic operation

run tun2socks-linux-mipsle-softfloat-v2.2.1, get panic.

panic: unaligned 64-bit atomic operation

goroutine 7 [running]:
runtime/internal/atomic.panicUnaligned(...)
        runtime/internal/atomic/unaligned.go:8
runtime/internal/atomic.lockAndCheck(...)
        runtime/internal/atomic/atomic_mipsx.go:37
runtime/internal/atomic.Store64(0x11ec41c, 0x100000, 0x0)
        runtime/internal/atomic/atomic_mipsx.go:103 +0x94
gvisor.dev/gvisor/pkg/atomicbitops.(*AlignedAtomicInt64).Store(...)
        gvisor.dev/[email protected]/pkg/atomicbitops/aligned_64bit.go:39
gvisor.dev/gvisor/pkg/tcpip.(*SocketOptions).SetSendBufferSize(0x11ec3b0, 0x100000, 0x0, 0x72c900)
        gvisor.dev/[email protected]/pkg/tcpip/socketops.go:626 +0x19c
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.newEndpoint(0x1115180, 0x800, 0x11e20c0, 0x4)
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/endpoint.go:840 +0x208
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).createConnectingEndpoint(0x1222000, 0x1282000, 0x11b3f74, 0x11e20c0, 0x1018150, 0x4, 0x521ba4)
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:216 +0xcc
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).startHandshake(0x1222000, 0x1282000, 0x11b3f74, 0x11e20c0, 0x0, 0x0, 0x0, 0x0, 0x0)
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:251 +0xe4
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).performHandshake(0x1222000, 0x1282000, 0x11b3f74, 0x11e20c0, 0x0, 0x0, 0x18, 0x77f17790, 0x18)
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:327 +0x68
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*ForwarderRequest).CreateEndpoint(0x1014120, 0x11e20c0, 0x0, 0x0, 0x0, 0x0)
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/forwarder.go:155 +0x12c
github.com/xjasonlyu/tun2socks/core/stack.withTCPHandler.func1.1(0x1014120)
        github.com/xjasonlyu/tun2socks/core/stack/tcp.go:40 +0xf8
created by gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*Forwarder).HandlePacket
        gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/forwarder.go:94 +0x334

windows 10 下 ipv6 udp 不通

.\tun2socks-windows-amd64.exe -device tun://tun0 -proxy socks5://uuu:[email protected]:9911
netsh interface ipv6 add address "tun0" 2001:608:8001::1
netsh interface ipv6 add route ::/0 interface="tun0" 2001:608:8002::1 metric=3 store=active
C:\Users\11\Desktop\curl>curl.exe http://[2606:4700:4700::1111]/cdn-cgi/trace
fl=12f388
h=[2606:4700:4700::1111]
ip=2001:19f0:6001:3211:5400:3ff:fe2e:ba3b
ts=1618292478.368
visit_scheme=http
uag=curl/7.75.0
colo=LAX
http=http/1.1
loc=US
tls=off
sni=off
warp=off
gateway=off

测试通过代理服务器访问ipv6节点tcp是没问题的,

.\tun2socks-windows-amd64.exe -device tun://tun0 -proxy socks5://uuu:[email protected]:9911
netsh interface ipv6 add address "tun0" 2001:608:8001::1
netsh interface ipv6 add route ::/0 interface="tun0" 2001:608:8002::1 metric=3 store=active
C:\Users\11\Desktop\curl>nslookup -vc www.qq.com 2606:4700:4700::1111
服务器:  one.one.one.one
Address:  2606:4700:4700::1111

非权威应答:
名称:    e6156.dscf.akamaiedge.net
Addresses:  2600:1406:3c:483::180c
          2600:1406:3c:49f::180c
          23.15.137.25
Aliases:  www.qq.com
          news.qq.com.edgekey.net


C:\Users\11\Desktop\curl>nslookup www.qq.com 2606:4700:4700::1111
DNS request timed out.
    timeout was 2 seconds.
服务器:  UnKnown
Address:  2606:4700:4700::1111

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
*** 请求 UnKnown 超时

ipv6 udp 不通,tcp是好的。

[TCP] dial 17.56.9.23:585 error: connect to 98.185.94.76:4145: dial tcp4 98.185.94.76:4145: connect: network is unreachable

os: macOS 11.1 (Big Sur)
version: v2.0.1

steps:

# sudo ./tun2socks-darwin-amd64 --loglevel info --device tun://utun123 --proxy socks5://98.185.94.76:4145 --interface en0
# sudo ifconfig utun123 198.18.0.1 netmask 255.255.255.255 198.18.0.1 up
# sudo route delete default
# sudo route add default 198.18.0.1
# sudo route add 98.185.94.76 198.18.0.1

routes:

# netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Netif Expire
default            198.18.0.1         UGSc       utun123
98.185.94.76       198.18.0.1         UGHS       utun123
127                127.0.0.1          UCS            lo0
127.0.0.1          127.0.0.1          UH             lo0
169.254            link#6             UCS            en0      !
192.168.0          link#6             UCS            en0      !
192.168.0.1/32     link#6             UCS            en0      !
192.168.0.1        66:c4:b4:70:cc:7d  UHLWIir        en0   1166
192.168.0.193/32   link#6             UCS            en0      !
198.18.0.1         198.18.0.1         UHr        utun123
224.0.0/4          link#6             UmCS           en0      !
224.0.0.251        1:0:5e:0:0:fb      UHmLWI         en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI         en0
255.255.255.255/32 link#6             UCS            en0      !

Shadowsocks proxy - tun2socks panics

Hey there!

I ❤️ tun2socks, it is incredibly convenient whenever I need to pass all TCP+UDP traffic through a SOCKS5 server, amazing job 🏆!

Out of curiosity, today I tried to use a Shadowsocks server as proxy and tun2socks crashed, I'm using the latest git version (also reproducible in the latest non-git release):

$ tun2socks -version
tun2socks-2.1.5
linux/amd64, go1.16.3, 3f7fdc1

This is the command that produces the panic along with the panic dump:

$ sudo tun2socks -device tun://tun0 -proxy ss://127.0.0.1:9090

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/xjasonlyu/tun2socks/engine.parseShadowsocks(0xc0001b0000, 0x886e7e, 0x2, 0x1, 0x0, 0x2b0d250cf91f9f9f, 0x4a0000c0000a36c0, 0x2b0000000085fd80, 0xc000093ca0, 0x2b0d250cf91f9f9f, ...)
        github.com/xjasonlyu/tun2socks/engine/parse.go:77 +0x3db
github.com/xjasonlyu/tun2socks/engine.parseProxy(0x7ffe123fe717, 0x16, 0x793b5d, 0x8874f6, 0x4, 0x3)
        github.com/xjasonlyu/tun2socks/engine/parse.go:54 +0x1e5
github.com/xjasonlyu/tun2socks/engine.(*engine).setProxy(0xb67600, 0x0, 0x0)
        github.com/xjasonlyu/tun2socks/engine/engine.go:141 +0x4a
github.com/xjasonlyu/tun2socks/engine.(*engine).start(0xb67600, 0x40d32a, 0x1)
        github.com/xjasonlyu/tun2socks/engine/engine.go:74 +0x1c6
github.com/xjasonlyu/tun2socks/engine.Start(0x0, 0x0)
        github.com/xjasonlyu/tun2socks/engine/engine.go:20 +0x2d
main.main.func1(0x88a504, 0xc, 0x8a66b0)
        github.com/xjasonlyu/tun2socks/main.go:33 +0x2e
main.main()
        github.com/xjasonlyu/tun2socks/main.go:38 +0x83

The panic doesn't happen neither in socks5 nor direct proxy mode. Hope you can take a look 🔍

route k2 tun2socks pthread_create failed: Resource temporarily unavailable

我在k2 padavan上移植了tun2socks跟trojan
ulimit -a
-f: file size (blocks) unlimited
-t: cpu time (seconds) unlimited
-d: data seg size (kb) unlimited
-s: stack size (kb) 8192
-c: core file size (blocks) 0
-m: resident set size (kb) unlimited
-l: locked memory (kb) 64
-p: processes 482
-n: file descriptors 1024
-v: address space (kb) unlimited
-w: locks unlimited
-e: scheduling priority 0
-r: real-time priority 0
错误提示:
`runtime/cgo: pthread_create failed: Resource temporarily unavailable
SIGABRT: abort
PC=0x77900180 m=8 sigcode=4294967290
signal arrived during cgo execution

goroutine 8 [chan receive, locked to thread]:
Segmentation fault`

我需要做些什么?才能让他正常?

关于ICMP/ICMP6代理

您好,我想将ICMP封装到UDP中通过代理出去,看了一遍代码也没明白该从何处下手修改获取ICMP,您能否提供一些参考建议?

Quick start guide / examples?

Could you consider adding more information to your project and example quick start guides?

I'm struggling to setup and verify this is working - I am not using your docker image, I compiled the binary and try to run on it on the machine and the tun0 interface on linux debian 10 is not being created.

If there was a quickstart guide with some minimum requirements (or possibly binary downloads) I could quickly run some tests - right now I am trying to tunnel all ICMP/UDP/TCP traffic thru a shadowsocksr server (VPS) and my local machine/client (debian 10) is where I am trying to do iperf3 tests via the tun0 interface of tun2socks.

Trying to compare tun2socks performance with udp2raw and others. Right now I couldn't find some examples in english or more information and when I run the binary all I see is this

root@gw:~# ./tun2socks-linux-amd64  -device tun://tun0 -proxy socks5://127.0.0.1:1080
INFO[0000] [STACK] tun://tun0 <-> socks5://127.0.0.1:1080

There is no tun0 interface created and shown via 'ifconfig' nor an error... so I am unsure if this is even working. I did try to run this script but nothing happens. https://github.com/xjasonlyu/tun2socks/wiki/Load-tun-module - I am unclear if there are more steps needed to make this work. The first page of the wiki says running command 'tun2socks-linux-amd64 -device tun://tun0 -proxy socks5://127.0.0.1:1080' should be enough to bring up the tunnel.

thanks

使用报错,老哥

2020/09/15 13:36:44 TAP device component ID: {7055EF57-3B25-4945-A08C-6E94B67D72C9}
2020/09/15 13:36:44 TAP device name: SSTAP
2020/09/15 13:36:44 Set SSTAP with net/mask: 10.0.236.2/255.255.255.0 through DHCP
2020/09/15 13:36:44 Set SSTAP with DNS: 114.114.114.114,8.8.8.8 through DHCP
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x15bd83a]

goroutine 1 [running]:
main.main()
        /home/xxxxxxx/Desktop/tun2socks/cmd/main.go:145 +0x4da

编译命令

export GOOS=windows
export GOARCH=amd64
export CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
export CGO_ENABLED=1
go build xxx

Macos amd64 resource busy

Download tun2socks-darwin-amd64 from release then run ,i got this:

➜  Downloads sudo ./tun2socks-darwin-amd64 -device tun://utun0 -proxy socks5://127.0.0.1:2080
FATA[0000] Failed to start engine: create tun: resource busy

ld: library not found for -lcrt0.o

mac os

GOBUILD=go build -trimpath -ldflags '-s -w -extldflags "-static" -X "github.com/xjasonlyu/tun2socks/constant.Version=$(VERSION)"'

去掉 Makefile 中的 -extldflags "-static" 就好了?

GOBUILD=go build -trimpath -ldflags '-s -w -X "github.com/xjasonlyu/tun2socks/constant.Version=$(VERSION)"'

tun2socks panic: unaligned 64-bit atomic operation

root@p722:/online # ./tun2socks -device tun://tun0 -mtu 1500 -proxy socks5://127.0.0.1:10808

INFO[0000] [STACK] tun://tun0 <-> socks5://127.0.0.1:10808
panic: unaligned 64-bit atomic operation

goroutine 19 [running]:
runtime/internal/atomic.panicUnaligned()
runtime/internal/atomic/unaligned.go:8 +0x24
runtime/internal/atomic.Store64(0x86ed1c, 0x100000, 0x0)
runtime/internal/atomic/asm_arm.s:278 +0x14
gvisor.dev/gvisor/pkg/tcpip.(*SocketOptions).SetSendBufferSize(0x86ecb0, 0x100000, 0x0, 0x6b387200)
gvisor.dev/[email protected]/pkg/tcpip/socketops.go:607 +0x17c
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.newEndpoint(0x85d500, 0x800, 0x80b2a0, 0x4)
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/endpoint.go:890 +0x1d0
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).createConnectingEndpoint(0x8de000, 0x894280, 0x6284333a, 0xb4a08e89, 0x91df74, 0x80b2a0, 0x841f1789, 0x6284333a, 0x0)
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:214 +0xac
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).startHandshake(0x8de000, 0x894280, 0x91df74, 0x80b2a0, 0x0, 0x0, 0x0, 0x0, 0x0)
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:249 +0x84
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*listenContext).performHandshake(0x8de000, 0x894280, 0x91df74, 0x80b2a0, 0x0, 0x0, 0x18, 0xb6f80088, 0x18)
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/accept.go:317 +0x48
gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*ForwarderRequest).CreateEndpoint(0x8463f0, 0x80b2a0, 0x0, 0x0, 0x0, 0x0)
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/forwarder.go:155 +0xe8
github.com/xjasonlyu/tun2socks/core/stack.withTCPHandler.func1.1(0x8463f0)
github.com/xjasonlyu/tun2socks/core/stack/tcp.go:40 +0x8c
created by gvisor.dev/gvisor/pkg/tcpip/transport/tcp.(*Forwarder).HandlePacket
gvisor.dev/[email protected]/pkg/tcpip/transport/tcp/forwarder.go:94 +0x204

busybox uname -a
Linux localhost 3.10.100+ #1 PREEMPT Wed Nov 29 12:49:06 CST 2017 armv7l GNU/Linux

im using armv7 from latest release

how to use tun2socks?

win10 x64,wintun.dll installed.

I have a v2ray client listen socks prot 0.0.0.0:2999 .

Do as quickstart

.\tun2socks.exe -device tun://tun0 -proxy socks5://127.0.0.1:2999
It seems not effect?Nothing proxyd to 127.0.0.1:2999

DNS over HTTPS?

Is it possible to use DNS over HTTPS with tun2socks? I see some code is there, but not sure how I'm supposed to set the upstream DNS server.

var addr, dnsNetType string
switch u.Scheme {
case "udp":
addr, err = hostWithDefaultPort(u.Host, "53")
dnsNetType = "" // UDP
case "tcp":
addr, err = hostWithDefaultPort(u.Host, "53")
dnsNetType = "tcp" // TCP
case "tls":
addr, err = hostWithDefaultPort(u.Host, "853")
dnsNetType = "tcp-tls" // DNS over TLS
case "https":
clearURL := url.URL{Scheme: "https", Host: u.Host, Path: u.Path}
addr = clearURL.String()
dnsNetType = "https" // DNS over HTTPS
default:
return nil, fmt.Errorf("DNS NameServer[%d] unsupport scheme: %s", idx, u.Scheme)
}

dave@xps:~/tun2socks/bin$ ./tun2socks-linux-amd64 --loglevel debug --device tun://tun0 --proxy socks5://127.0.0.1:8080 --dns https://1.1.1.1
FATA[0000] Failed to start: start DNS server https://1.1.1.1: unsupported scheme 

Thanks!

提供一种电脑做网关的思路

可以的
https://github.com/FlowerWrong/tun2socks
https://github.com/xjasonlyu/tun2socks
这两个已经实现fake dns
surge增强模式也是这样
有两种方式
google.com -> 192.18.0.1
google.com.hk -> 192.18.0.2

google.com -> 192.18.0.1:1111
google.com.hk -> 192.18.0.2:1112

通过这种关联即可

个人系统192.168.1.2开启
net.inet.ip.forwarding=1
开启tun2socks
sudo route add 198.18.0.2/24 240.0.0.1(tun网关)

手机设置网关192.168.1.2
所有流量走192.168.1.2了吧
192.168.1.2开启fake dns
手机dns服务器也设置为1.2
手机访问google.com 得到ip 192.18.0.1
手机连接192.18.0.1经过192.168.1.2
192.18.0.1走tun接口
tun2socks检测到访问192.18.0.1->google.com

此时tun2socks->v2ray inbounds
由v2ray来识别国外国内 google facebook twitter等域名

假如手机访问baidu,v2ray直接识别为geosite:cn ip 流量直接国内走

tun2socks只需要提供fake dns和代理功能
分流交给v2ray来做
这样

[Feature request] direct模式下port forwarding模式

可以設置一系列類似這樣的規則,

1314->192.168.11.2:1314/udp 
8080->192.168.22.3:80/tcp
8443->192.168.22.3:443/tcp

就會在主機listen udp 1314 等等port,forwarding到tun端對應ip:port

udp無狀態比較好弄些,tcp感覺上比較麻煩。

只有udp也好,加上這個功能也是挺實用的

程序太快了

我的V2RAY客户端配置如下:

{
  "inbounds": [
    {
      "port": 1080,
      "protocol": "socks",
      "settings": {
        "auth": "noauth"
      }
    },
    {
      "port": 1000,
      "protocol": "http",
      "settings": {}
    }
  ],
  "outbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "xxx.com",  #省略
            "port": 443,
            "users": [
              {
                "id": "xxx",   #省略
                "alterId": 0,
                "security": "auto"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "security": "tls"
      },
      "mux": {
        "enabled": true
      }
    },
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    }
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "type": "field",
        "outboundTag": "direct",
        "domain": [
          "geosite:cn"
        ]
      },
      {
        "type": "field",
        "outboundTag": "direct",
        "ip": [
          "geoip:cn",
          "geoip:private"
        ]
      }
    ]
  }
}

请帮我看看是什么地方参数设置不对

FakeDNS Option

Would it be possible to include the FakeDNS option which would allow for remote DNS use in socks 5 proxies. Thanks

Forward TCP and UDP separately

Hi
Is it possible that forward TCP traffic to for example socks1:1080 and UDP to socks2:1081?
Because some proxies do not support udp but have good speed for tcp forwarding.
Thanks

Reverse socks2tun implementation

I'm looking for reverse implementation converting many vpn/wireguard interfaces to socks5 proxy.
For now I have plenty of hacks running lots of different socks servers via different users, then marking and properly routing traffic using iptables. All this stuff is very unstable.

Can you give me advise how network interfaces can be converted into socks5 proxy in easiest way?
Thanks!

error on FreeBSD 12.1

root@freebsd:/usr/local/tun2socks # ./tun2socks-freebsd-amd64 -d tun://tun0 -p socks5://127.0.0.1:1080
FATA[0000] Failed to start: open device tun://tun0: failed to set MTU on tun0

cannot make curl request for tun0

hi, i tried from Debian 10 and Ubuntu 20.04
step to reproduce:
./tun2socks -device tun://tun0 -proxy socks5://127.0.0.1:9050
curl --interface tun0 https://api.myip.com
curl: (7) Couldn't connect to server
question: how to check if tun0 working? i started tor as proxy to check but not working
ip a:
14: tun0: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 500
link/none
i cannot make to work tun0 driver
i tried in rasberry (armv7) and AMD64 (Debian 10)
In windows tun2socks works!.

image

udp cannot be used

C:\Users\kuyer>nslookup -vc www.qq.com 8.8.8.8
服务器:  dns.google
Address:  8.8.8.8

非权威应答:
名称:    e6156.dscf.akamaiedge.net
Addresses:  2600:1406:1400:3a6::180c
          2600:1406:1400:386::180c
          184.31.186.46
Aliases:  www.qq.com
          news.qq.com.edgekey.net


C:\Users\kuyer>nslookup www.qq.com 8.8.8.8
DNS request timed out.
    timeout was 2 seconds.
服务器:  UnKnown
Address:  8.8.8.8

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
*** 请求 UnKnown 超时

C:\Users\kuyer>

socks5 server

https://github.com/ginuerzh/gost

gost -L=socks5://:1080

关于代码编译的问题

首先非常感谢您提供了这么优秀的程序供我们学习、使用。这段时间我在试着编译您的V1版的tun2socks。我的编译方法如下:
在MinGW的编译环境下,进入go-tun2socks源代码的根目录,执行make命令进行编译。由于原版代码缺少了跟加密有关的几个库“函数的声明”,所以在core/c/custom/sys_arch.c文件里加入了个头文件声明#include <Wincrypt.h>,另外为了支持MinGW编译,在原来_WIN32宏定义的基础上加了__MINGW32__宏。这样,就可以编译出原版的可执行文件。
程序是编译出来了,但是编译出的EXE文件体积有3MB多。这倒是没关系。关键程序执行效率经测试远远没有您提供的编译版本v1.18.3高,几乎就没法用。请问是否我的编译过程不对?

Support custom routes, exclude routes, DNS and MTU for Windows

Hi, I'm working on a similar project fork (https://github.com/eycorsican/go-tun2socks). I implemented some features I missed, but the upstream project is based on LwIP stack, which I don't like.

I'd happy to switch to your project, but it doesn't support features listed below:

  • MTU set for Windows
  • Custom routes (CLI arg)
  • Exclude routes (CLI arg)
  • DNS setting

I prepared a package to support this stuff: https://github.com/kayrus/tuncfg
It would be nice if you embed it into your project

windows 下怎么用呀?

.\tun2socks-windows-amd64.exe -device tun://tun0 -proxy socks5://uuu:[email protected]:9911
ipv6

netsh interface ipv6 add address "tun0" 2001:608:8001::1
netsh interface ipv6 add route ::/0 interface="tun0" 2001:608:8002::1 metric=3 store=active

ipv4

netsh interface ip set address "tun0" static 10.10.10.2 255.255.255.0
route add 0.0.0.0 mask 0.0.0.0 10.10.10.2 if 7 metric 1
netsh interface ip set dns "tun0" static 8.8.8.8

UDP delayed when session is enabled

First UDP packets from source would be delayed several milliseconds if session is enabled.
It's a problem of lsof, it would take about 30 ms - 60 ms (depends on os) to inspect source address information.

程序在WIN7x32系统下无法运行

经测试,在WIN7x86系统下,由于wintun.dll的原因,无法运行,也无法安装虚拟网卡,如下文字:
Error loading wintun.dll DLL: Unable to load library: The parameter is incorrect.
意思是wintun.dll版本好像不对。但是我去wintun官网下载了最新版本的wintun.dll,版本0.10.2。官方提供的x86的DLL,包括压缩包里的其他DLL我都试了一遍,全部都出现这个错误提示

ipv6支持

fake dns 解析aaaa直接去backendDNS查询
考虑支持ipv6 fake dns吗

客户端直接访问ipv6地址时 程序也并没有处理?

sudo sysctl -w net.inet6.ip6.forwarding=1

客户端添加ipv6 dns,设置ipv6路由后 ,没有ipv6 fake dns也没用啊😂

Socks4 support

Hi , thanks for this great tool.
How we can use socks4 proxies via this tool ?
can any support be added ?

thanks again.

为何go get失败?

yudeMacBook-Air:gopath brite$ go get -u -v github.com/xjasonlyu/tun2socks/cmd/
github.com/xjasonlyu/tun2socks (download)

cd .; git clone -- https://github.com/xjasonlyu/tun2socks /Users/brite/go1.13/go/gopath/src/github.com/xjasonlyu/tun2socks

Cloning into '/Users/brite/go1.13/go/gopath/src/github.com/xjasonlyu/tun2socks'...
fatal: unable to access 'https://github.com/xjasonlyu/tun2socks/': Server aborted the SSL handshake
package github.com/xjasonlyu/tun2socks/cmd: exit status 128
yudeMacBook-Air:gopath brite$

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.