xjasonlyu / tun2socks

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

"route: writing to routing socket: Network is unreachable" #89

Closed DUOLabs333 closed 2 years ago

DUOLabs333 commented 2 years ago

Environment

Log Paste the tun2socks log below with the log level set to DEBUG.

INFO[0000] [DIALER] use interface: en0
INFO[0000] [STACK] tun://utun3 <-> socks5://10.200.200.1:2015

Describe the bug I turned on tun2socks, but when trying to add a route, it fails with "route: writing to routing socket: Network is unreachable"

To Reproduce Steps to reproduce the behavior:

  1. Run Wireguard, and expose your SOCKS proxy through it.
  2. Run sudo ./tun2socks* -device tun://utun3 -proxy socks5://10.200.200.1:2015 -interface en0
  3. Try to add route with sudo route -q -n add -inet 127.0.0.1/32 -interface utun3
  4. route: writing to routing socket: Network is unreachable
    add net 127.0.0.1: gateway utun3: Network is unreachable

    Expected behavior No errors, and all 127.0.0.1 requests should be tunneled to the socks proxy.

Additional context Add any other context about the problem here.

xjasonlyu commented 2 years ago

Can you share your route table? It's very unusual someone try to route their loopback address.

DUOLabs333 commented 2 years ago
Routing tables

Internet:
Destination        Gateway            Flags        Netif Expire
0/1                utun2              UScg         utun2
default            192.168.1.1        UGScg          en0
10.200.200.3       10.200.200.3       UH           utun2
127                127.0.0.1          UCS            lo0
127.0.0.1          127.0.0.1          UH             lo0
128.0/1            utun2              USc          utun2
169.254            link#11            UCS            en0      !
192.168.1          link#11            UCS            en0      !
192.168.1.1/32     link#11            UCS            en0      !
192.168.1.1        20:c0:47:f2:b5:8e  UHLWIir        en0   1195
192.168.1.51       192.168.1.1        UGHS           en0
192.168.1.51       52:54:0:c9:18:27   UHLWIi         en0   1172
192.168.1.175/32   link#11            UCS            en0      !
192.168.1.203      bc:a5:11:9e:d5:3f  UHLWI          en0    550
192.168.1.255      ff:ff:ff:ff:ff:ff  UHLWbI         en0      !
224.0.0/4          link#11            UmCS           en0      !
224.0.0.251        1:0:5e:0:0:fb      UHmLWI         en0
255.255.255.255/32 link#11            UCS            en0      !

Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun0                    UGcIg         utun0
default                                 fe80::%utun1                    UGcIg         utun1
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%anpi1/64                         link#4                          UCI           anpi1
fe80::1c00:23ff:fe21:f85a%anpi1         1e:0:23:21:f8:5a                UHLI            lo0
fe80::%anpi0/64                         link#5                          UCI           anpi0
fe80::1c00:23ff:fe21:f859%anpi0         1e:0:23:21:f8:59                UHLI            lo0
fe80::%awdl0/64                         link#13                         UCI           awdl0
fe80::38ac:36ff:febc:d94f%awdl0         3a:ac:36:bc:d9:4f               UHLI            lo0
fe80::%llw0/64                          link#14                         UCI            llw0
fe80::38ac:36ff:febc:d94f%llw0          3a:ac:36:bc:d9:4f               UHLI            lo0
fe80::%utun0/64                         fe80::7ddc:7359:55a9:44ed%utun0 UcI           utun0
fe80::7ddc:7359:55a9:44ed%utun0         link#15                         UHLI            lo0
fe80::%utun1/64                         fe80::5e4c:eda4:9d30:b44d%utun1 UcI           utun1
fe80::5e4c:eda4:9d30:b44d%utun1         link#16                         UHLI            lo0
ff00::/8                                ::1                             UmCI            lo0
ff00::/8                                link#4                          UmCI          anpi1
ff00::/8                                link#5                          UmCI          anpi0
ff00::/8                                link#13                         UmCI          awdl0
ff00::/8                                link#14                         UmCI           llw0
ff00::/8                                fe80::7ddc:7359:55a9:44ed%utun0 UmCI          utun0
ff00::/8                                fe80::5e4c:eda4:9d30:b44d%utun1 UmCI          utun1
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%anpi1/32                         link#4                          UmCI          anpi1
ff01::%anpi0/32                         link#5                          UmCI          anpi0
ff01::%awdl0/32                         link#13                         UmCI          awdl0
ff01::%llw0/32                          link#14                         UmCI           llw0
ff01::%utun0/32                         fe80::7ddc:7359:55a9:44ed%utun0 UmCI          utun0
ff01::%utun1/32                         fe80::5e4c:eda4:9d30:b44d%utun1 UmCI          utun1
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%anpi1/32                         link#4                          UmCI          anpi1
ff02::%anpi0/32                         link#5                          UmCI          anpi0
ff02::%awdl0/32                         link#13                         UmCI          awdl0
ff02::%llw0/32                          link#14                         UmCI           llw0
ff02::%utun0/32                         fe80::7ddc:7359:55a9:44ed%utun0 UmCI          utun0
ff02::%utun1/32                         fe80::5e4c:eda4:9d30:b44d%utun1 UmCI          utun1
xjasonlyu commented 2 years ago

Where is your utun3 interface?

DUOLabs333 commented 2 years ago

sudo ./tun2socks* -device tun://utun3 -proxy socks5://10.200.200.1:2015 -interface en0

xjasonlyu commented 2 years ago

Try adding another routes to see if it works.

DUOLabs333 commented 2 years ago

Like what? sudo route -q -n add -inet 0.0.0.0/1 -interface utun3 doesn't work either.

DUOLabs333 commented 2 years ago

Do you have to create the utun ahead of time?

xjasonlyu commented 2 years ago

Do you have to create the utun ahead of time?

That's... of course

DUOLabs333 commented 2 years ago

I though tun2socks created it for you?