xjasonlyu / tun2socks

tun2socks - powered by gVisor TCP/IP stack
https://github.com/xjasonlyu/tun2socks/wiki
GNU General Public License v3.0
2.85k stars 405 forks source link

[Bug] Cannot get it to work on macOS #195

Closed smukee closed 1 year ago

smukee commented 1 year ago

Verify steps

Version

tun2socks-2.4.1

What OS are you seeing the problem on?

macOS

Description

Here's what I do:

  1. I start my SOCKS5 on port 1080
  2. Start tun2socks via sudo tun2socks -device utun123 -proxy socks5://127.0.0.1:1080 -interface en1
  3. Bring it up via sudo ifconfig utun123 198.18.0.1 198.18.0.1 up
  4. Delete default route sudo route delete default and add the new sudo route add default 198.18.0.1

After this nothing goes in and out.

CLI or Config

No response

Logs

Here's what I get from tun2socks;seems like UDP issue:

INFO[0000] [DIALER] bind to interface: en1              
INFO[0000] [STACK] tun://utun123 <-> socks5://127.0.0.1:1080 

INFO[0147] [UDP] 198.18.0.1:50798 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:51285 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:53679 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:57722 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:62176 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:59040 <-> 91.239.100.100:53 
INFO[0147] [UDP] 198.18.0.1:56361 <-> 91.239.100.100:53 
INFO[0147] [TCP] 198.18.0.1:50231 <-> 141.95.144.66:993 
INFO[0148] [UDP] 198.18.0.1:55118 <-> 9.9.9.9:53        
INFO[0149] [UDP] 198.18.0.1:137 <-> 198.18.0.255:137    
INFO[0150] [UDP] 198.18.0.1:62176 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:51285 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:50798 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:59040 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:57722 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:56361 <-> 9.9.9.9:53        
INFO[0150] [UDP] 198.18.0.1:53679 <-> 9.9.9.9:53        
INFO[0150] [TCP] 198.18.0.1:50242 <-> 104.18.115.97:80  
INFO[0152] [UDP] 198.18.0.1:55017 <-> 9.9.9.9:53        
INFO[0152] [UDP] 198.18.0.1:49883 <-> 9.9.9.9:53        
INFO[0153] [UDP] 198.18.0.1:59040 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:57722 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:53679 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:62176 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:50798 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:56361 <-> 89.233.43.71:53   
INFO[0153] [UDP] 198.18.0.1:51285 <-> 89.233.43.71:53   
INFO[0154] [UDP] 198.18.0.1:60173 <-> 9.9.9.9:53        
INFO[0155] [UDP] 198.18.0.1:55017 <-> 89.233.43.71:53   
INFO[0156] [UDP] 198.18.0.1:57722 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:51285 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:62176 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:50798 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:53679 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:56361 <-> 1.1.1.1:53        
INFO[0156] [UDP] 198.18.0.1:59040 <-> 1.1.1.1:53        
INFO[0158] [UDP] 198.18.0.1:55017 <-> 1.1.1.1:53        
INFO[0161] [UDP] 198.18.0.1:55017 <-> 91.239.100.100:53 
INFO[0161] [UDP] 198.18.0.1:50222 <-> 91.239.100.100:53 
INFO[0161] [TCP] 198.18.0.1:50265 <-> 140.82.113.25:443 
INFO[0161] [TCP] 198.18.0.1:50267 <-> 140.82.113.25:443 
INFO[0164] [UDP] 198.18.0.1:50222 <-> 9.9.9.9:53        
INFO[0167] [UDP] 198.18.0.1:50222 <-> 89.233.43.71:53   
INFO[0170] [UDP] 198.18.0.1:50222 <-> 1.1.1.1:53        
INFO[0173] [UDP] 198.18.0.1:54920 <-> 1.1.1.1:53        
INFO[0176] [UDP] 198.18.0.1:54920 <-> 89.233.43.71:53

How to Reproduce

No response

xjasonlyu commented 1 year ago

What’s your proxy server?

Did you make sure that your local proxy server bind to a specific interface so that it can avoid route loop too?

Also, please make sure your en1 interface is your primary interface.

smukee commented 1 year ago

The proxy server is a Trojan running as SOCKS5 and bound to exactly 127.0.0.1:1080. en1 is my primary and only active device, yes.

xjasonlyu commented 1 year ago

Then I guess the problem is you didn’t bind your trojan server to the interface, so it gets into a route looping.

smukee commented 1 year ago

I'm sorry I don't get it, Socks is running on 127.0.0.1:1080 so tun2socks knows where to communicate to!

xjasonlyu commented 1 year ago

Yep, but when the trojan server tries to establish connections, the connections receive by tun2socks and tun2socks sends them back to the trojan server, which causes an infinite loop.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days