eycorsican / go-tun2socks

A tun2socks implementation written in Go.
MIT License
1.3k stars 432 forks source link

Improved version of the tun2socks #154

Open kayrus opened 3 years ago

kayrus commented 3 years ago

I made a couple of improvements in my fork: https://github.com/kayrus/go-tun2socks

@eycorsican I'm not aware about the current project vision and a roadmap, therefore I'd like to get your opinion on whether it is feasible to merge my changes to your branch.

notsure2 commented 3 years ago

@kayrus your version of tun2socks works great on windows 10, but your code doesn't set the DNS server on the tun interface making the tunDns parameter useless. Could you fix it :-)

kayrus commented 3 years ago

I haven't tried the DNS feature yet even in *nix OS. I'm using SSH socks, which, I guess, doesn't support UDP. Can you suggest a Linux SOCKS5 server, which handles UDP?

lizkes commented 3 years ago

I made a couple of improvements in my fork: https://github.com/kayrus/go-tun2socks

* An ability to manage tun routes including automatic hostnames resolving

* Switch to go-wireguard TUN driver for a better windows support

* Support custom MTU setting

@eycorsican I'm not aware about the current project vision and a roadmap, therefore I'd like to get your opinion on whether it is feasible to merge my changes to your branch.

You are my HERO!!! Thanks!

lizkes commented 3 years ago

I haven't tried the DNS feature yet even in *nix OS. I'm using SSH socks, which, I guess, doesn't support UDP. Can you suggest a Linux SOCKS5 server, which handles UDP?

try Xray

steom commented 3 years ago

I made a couple of improvements in my fork: https://github.com/kayrus/go-tun2socks

  • An ability to manage tun routes including automatic hostnames resolving
  • Switch to go-wireguard TUN driver for a better windows support
  • Support custom MTU setting

@eycorsican I'm not aware about the current project vision and a roadmap, therefore I'd like to get your opinion on whether it is feasible to merge my changes to your branch.

@kayrus The -tunDns and -tunGw parameters are not working. Default gateway and DNS servers Is not set on the Windows wintun interface.

kayrus commented 3 years ago

@steom yes, I know. I need more time to fix this.

kayrus commented 3 years ago

I brought back DNS support for windows. It may also work with linux/macos. Please test.

steom commented 3 years ago

the dns is configured now but ip, subnet, and gateway no.

but after manually add the value:

panic: runtime error: slice bounds out of range [:1500] with capacity 1300

goroutine 7 [running]: io.copyBuffer(0x22394fed1d8, 0xc00007d8c0, 0x22394fed1f8, 0xc000006050, 0xc0000d4000, 0x514, 0x514, 0x50d240, 0x0, 0x22394fed1f8) C:/Program Files/Go/src/io/io.go:425 +0x3e5 io.CopyBuffer(0x22394fed1d8, 0xc00007d8c0, 0x22394fed1f8, 0xc000006050, 0xc0000d4000, 0x514, 0x514, 0x0, 0x0, 0x0) C:/Program Files/Go/src/io/io.go:396 +0x89 main.run.func2(0x22394fed1d8, 0xc00007d8c0, 0x559520, 0xc000006050, 0xc000042180) C:/Users/User/go-tun2socks/cmd/tun2socks/main.go:301 +0xf0 created by main.run C:/Users/User/go-tun2socks/cmd/tun2socks/main.go:300 +0xa28

kayrus commented 3 years ago

but ip, subnet, and gateway no

that is weird. in my case IP addresses are configured correctly.

panic: runtime error: slice bounds out of range [:1500] with capacity 1300

which parameters did you use for the CLI? I suppose I forgot to set MTU size inside the core/lwip.go. I need to reuse the MTU argument and bypass it core/lwip.go init function.

steom commented 3 years ago

Command line used: -exclude -proxyserver -tunaddr -tundns -tungw -tunmask In Windows net interface only dns Is set, ip subnet and gateway Is blank

kayrus commented 3 years ago

@steom I made an MTU fix in my fork master branch, can you try to reproduce the panic once again?

steom commented 3 years ago

I Need the new binary

kayrus commented 3 years ago

-exclude -proxyserver -tunaddr -tundns -tungw -tunmask

please provide all arguments, including their values. Usually it is not necessary to specify the tunGw and tunAddr, because they are taken from defaults.

kayrus commented 3 years ago

@steom I'll make a new release soon.

steom commented 3 years ago

proxyserver 10.0.0.100:1080 -tunaddr 192.168.0.2 -tundns 1.1.1.1 -tungw 192.168.0.1 -tunmask 255.255.255.0

kayrus commented 3 years ago

@steom I uploaded a dev binary into the latest release: https://github.com/kayrus/go-tun2socks/releases/download/v1.16.18/tun2socks-dev.exe

kayrus commented 3 years ago

@steom

but ip, subnet, and gateway no proxyserver 10.0.0.100:1080 -tunaddr 192.168.0.2 -tundns 1.1.1.1 -tungw 192.168.0.1 -tunmask 255.255.255.0

just setting the GW won't route all your traffic through the SOCKS. You need to specify the target routes, by default they are empty. If this is confusing for you. You need to set 0.0.0.0/0 route (e.g. default GW) manually via -routes argument (you can list routes using netstat -nr command). When you set 0.0.0.0/0, you must to exclude the socks proxy server as well, otherwise even socks proxy traffic will come through the socks and you'll get an endless loop.

For example, you established an SSH socks proxy with a remote server (ssh -D 1080 -C -N myuser@someserver). Thus you need to exclude someserver from routes: -exclude someserver -routes 0.0.0.0/0

steom commented 3 years ago

Now dont crush. Net adapter settings still blank, only dns Is populated

kayrus commented 3 years ago

Net adapter settings still blank, only dns Is populated

they have to be blank. See my previous message. The routes are set only for particular destinations, which you specify as CLI arguments.

steom commented 3 years ago

The previous version doesn't set the DNS server and the gateway on the Windows tun interface Only set ip address and subnet Mask

Now ,this new version doesn't set anything on the Windows tun interface but the DNS server

The tunaddr tunmask tungw options is useless dont set anything

kayrus commented 3 years ago

@steom

Now ,this new version doesn't set anything on the Windows tun interface but the DNS server The tunaddr tunmask tungw options is useless dont set anything

Screenshot_20210309_214039

See a screenshot. These parameters are not useless.

Gateway is set per route, specified as an argument.

P.S. If you want to route DNS request via 1.1.1.1, you also need to add 1.1.1.1 to -routes argument, unless you specify the default GW 0.0.0.0/0 route and exclude the SOCKS server from routes.

kayrus commented 3 years ago

@steom you should refer to ifconfig /all, TUN details and netstat -nr only, not to the tun properties edit window. Edit window don't respect fine grained IP configuration.

steom commented 3 years ago

its possibile to have also a win32 binary?

kayrus commented 3 years ago

@steom unfortunately I don't have environment to build the 32bit binary. You can build it yourself if you download go and run: go build -ldflags='-w -s' -tags socks .\cmd\tun2socks\

steom commented 3 years ago

after browse the internet for a while...:

panic: runtime error: slice bounds out of range [:1500] with capacity 1300

goroutine 7 [running]: io.copyBuffer(0x2415916a158, 0xc000096120, 0x2415916a178, 0xc000006098, 0xc0000cc000, 0x514, 0x514, 0x6ce240, 0x0, 0x2415916a178) C:/Program Files/Go/src/io/io.go:425 +0x3e5 io.CopyBuffer(0x2415916a158, 0xc000096120, 0x2415916a178, 0xc000006098, 0xc0000cc000, 0x514, 0x514, 0x0, 0x0, 0x0) C:/Program Files/Go/src/io/io.go:396 +0x89 main.run.func2(0x2415916a158, 0xc000096120, 0x71b140, 0xc000006098, 0xc000042180) C:/Users/User/go-tun2socks/cmd/tun2socks/main.go:307 +0xf0 created by main.run C:/Users/User/go-tun2socks/cmd/tun2socks/main.go:306 +0xa28

solvable i think with -maxMTU 1500 but a user message instead of a crash would be better

kayrus commented 3 years ago

@steom I found an issues in underlying wintun driver. A workaround is to set the MTU in windows console:

netsh interface ipv4 set interface tun2socks mtu=1300

you can do it once.

steom commented 3 years ago

using -maxMTU 1500 solve the problem, much more convenient

kayrus commented 3 years ago

@steom sometimes underlying layer doesn't allow to set MTU 1500, and this causes broken connections. That is why a new MTU option was added. I'll try to find a proper solution for wintun driver.

kayrus commented 3 years ago

@steom I made a release with fixed MTU. Please test https://github.com/kayrus/go-tun2socks/releases/tag/v1.16.19

steom commented 3 years ago

the fix works fine everything goes smoothly setup a VM and go compile a win32 version! ;)