Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Improved version of the tun2socks #154

Open
kayrus opened this issue Dec 18, 2020 · 30 comments
Open

Improved version of the tun2socks #154

kayrus opened this issue Dec 18, 2020 · 30 comments

Comments

@kayrus
Copy link

kayrus commented Dec 18, 2020

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.

@notsure2
Copy link

@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
Copy link
Author

kayrus commented Jan 12, 2021

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
Copy link

lizkes commented Jan 13, 2021

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
Copy link

lizkes commented Jan 13, 2021

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
Copy link

steom commented Feb 6, 2021

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
Copy link
Author

kayrus commented Feb 7, 2021

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

@kayrus
Copy link
Author

kayrus commented Mar 6, 2021

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

@steom
Copy link

steom commented Mar 9, 2021

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
Copy link
Author

kayrus commented Mar 9, 2021

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
Copy link

steom commented Mar 9, 2021

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

@kayrus
Copy link
Author

kayrus commented Mar 9, 2021

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

@steom
Copy link

steom commented Mar 9, 2021

I Need the new binary

@kayrus
Copy link
Author

kayrus commented Mar 9, 2021

-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
Copy link
Author

kayrus commented Mar 9, 2021

@steom I'll make a new release soon.

@steom
Copy link

steom commented Mar 9, 2021

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
Copy link
Author

kayrus commented Mar 9, 2021

@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
Copy link
Author

kayrus commented Mar 9, 2021

@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
Copy link

steom commented Mar 9, 2021

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

@kayrus
Copy link
Author

kayrus commented Mar 9, 2021

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
Copy link

steom commented Mar 9, 2021

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
Copy link
Author

kayrus commented Mar 9, 2021

@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
Copy link
Author

kayrus commented Mar 9, 2021

@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
Copy link

steom commented Mar 9, 2021

its possibile to have also a win32 binary?

@kayrus
Copy link
Author

kayrus commented Mar 10, 2021

@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
Copy link

steom commented Mar 10, 2021

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
Copy link
Author

kayrus commented Mar 10, 2021

@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
Copy link

steom commented Mar 10, 2021

using -maxMTU 1500 solve the problem, much more convenient

@kayrus
Copy link
Author

kayrus commented Mar 10, 2021

@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
Copy link
Author

kayrus commented Mar 10, 2021

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

@steom
Copy link

steom commented Mar 10, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants