go-tun2socks icon indicating copy to clipboard operation
go-tun2socks copied to clipboard

Improved version of the tun2socks

Open kayrus opened this issue 4 years ago • 30 comments

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 avatar Dec 18 '20 10:12 kayrus

@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 :-)

notsure2 avatar Dec 19 '20 16:12 notsure2

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?

kayrus avatar Jan 12 '21 10:01 kayrus

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 avatar Jan 13 '21 11:01 lizkes

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

lizkes avatar Jan 13 '21 11:01 lizkes

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.

steom avatar Feb 06 '21 20:02 steom

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

kayrus avatar Feb 07 '21 08:02 kayrus

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

kayrus avatar Mar 06 '21 08:03 kayrus

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

steom avatar Mar 09 '21 16:03 steom

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.

kayrus avatar Mar 09 '21 19:03 kayrus

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

steom avatar Mar 09 '21 19:03 steom

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

kayrus avatar Mar 09 '21 19:03 kayrus

I Need the new binary

steom avatar Mar 09 '21 19:03 steom

-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 avatar Mar 09 '21 19:03 kayrus

@steom I'll make a new release soon.

kayrus avatar Mar 09 '21 19:03 kayrus

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

steom avatar Mar 09 '21 19:03 steom

@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 avatar Mar 09 '21 19:03 kayrus

@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

kayrus avatar Mar 09 '21 20:03 kayrus

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

steom avatar Mar 09 '21 20:03 steom

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.

kayrus avatar Mar 09 '21 20:03 kayrus

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

steom avatar Mar 09 '21 20:03 steom

@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 avatar Mar 09 '21 20:03 kayrus

@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.

kayrus avatar Mar 09 '21 21:03 kayrus

its possibile to have also a win32 binary?

steom avatar Mar 09 '21 22:03 steom

@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\

kayrus avatar Mar 10 '21 06:03 kayrus

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

steom avatar Mar 10 '21 10:03 steom

@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.

kayrus avatar Mar 10 '21 12:03 kayrus

using -maxMTU 1500 solve the problem, much more convenient

steom avatar Mar 10 '21 12:03 steom

@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 avatar Mar 10 '21 12:03 kayrus

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

kayrus avatar Mar 10 '21 14:03 kayrus

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

steom avatar Mar 10 '21 15:03 steom