yinghuocho / gotun2socks

A Golang implementation of tun2socks
BSD 2-Clause "Simplified" License
292 stars 103 forks source link

Does gotun2socks work on macOS? #1

Open liudanking opened 8 years ago

liudanking commented 8 years ago

There is a tun_linux.go file in bin directory, but missing tun_darwin.go.

yinghuocho commented 8 years ago

I think the package itself works on macOS, as the code does not rely on OS-specific structs/interfaces. Thought I did't test.

The executable in bin directory only works on Linux. But it should be not hard to make it works on macOS. The only thing missing is a procedure that opens a tun device and returns a os.File object.

liudanking commented 8 years ago

I will have a try, and give my feedback ASAP.

yinghuocho commented 8 years ago

@liudanking gotun2socks works on macOS now. You can have a try. The problem only sets up the utun interface, you need to take care of routing yourself.

FlowerWrong commented 7 years ago

Could you give me a route command example for OSX? I am not familiar with OSX route command. I have try some commands below.

As you see.

Generaly the process includes changing default route to the tun/tap device, and exclude IP addresses of remote servers to go through the original network device so that traffic forwarded from local SOCKS5 proxy to remote servers would not loop back.

Follow command work for me. But I do not know it is corrent or not?

# start shadowsocks server on vps with udp relay
# start shadowsocks client on your computer with udp relay

sudo ./gotun2socks --local-socks-addr 127.0.0.1:1080

sudo route add -net 0.0.0.0 10.0.0.1 -netmask 128.0.0.0
sudo route add -net 128.0.0.0 10.0.0.1 -netmask 128.0.0.0

orig_gw=$(netstat -nr | grep --color=never '^default' | grep -v 'utun' | sed 's/default *\([0-9\.]*\) .*/\1/' | head -1)
sudo route add my_ss_server $origin_gw
yinghuocho commented 7 years ago

@FlowerWrong I think the commands you posted should be sufficient. The 2th and 3th commands change default route to the new utun device. The 4th command extracts previous default gateway. The 5th command specifies your ss_server to go through the previous gateway.

athrunsun commented 6 years ago

@yinghuocho @FlowerWrong

I'm sorry if this is a dumb question - but is sudo ip tuntap add dev tun0 mode tun user foobar posted here only necessary on linux? Because there's no ip command available on osx in the first place.

Or, will sudo gotun2socks --local-socks-addr 127.0.0.1:1080 create tun device automatically on both linux and osx?

FlowerWrong commented 6 years ago

see this comment

athrunsun commented 6 years ago

@FlowerWrong Is -netmask 128.0.0.0 a must? What difference will it make when I set it to 255.255.255.0?