FlowerWrong / tun2socks

Redirect tun flow to socks 5 in golang, support tcp and udp.
419 stars 108 forks source link

udp not forwarding #71

Open inpos opened 3 years ago

inpos commented 3 years ago

Hi. DNS set to fake mode. When I try to host ya.ru 127.0.0.1 I get:

2020/07/02 19:23:03 udp2socks5.go:167: [error] write to UDP tunnel failed write udp 192.168.49.199:58837->[::]:43754: address ::: non-IPv4 address

Full runtime log:

2020/07/02 19:22:29 main.go:37: [app] config file path is /opt/tun2socks.cfg
2020/07/02 19:22:29 proxies.go:62: [proxies] default proxy: "A"
2020/07/02 19:22:29 tun_linux.go:29: [tun] interface name is tun0
2020/07/02 19:22:29 cmd.go:14: [command] ifconfig tun0 10.111.111.1 netmask 255.255.255.0
2020/07/02 19:22:29 cmd.go:14: [command] route add -net 0.0.0.0/0 dev tun0
2020/07/02 19:22:29 main.go:95: [app] run tun2socks(0.50) success
2020/07/02 19:22:29 cmd.go:36: [shell] run shell command failed exit status 127
2020/07/02 19:22:29 cmd.go:38: [shell] output 
2020/07/02 19:22:29 dns.go:12: [dns] listen on 0.0.0.0:53
2020/07/02 19:22:58 udp2socks5.go:167: [error] write to UDP tunnel failed write udp 192.168.49.199:39277->[::]:52408: address ::: non-IPv4 address
2020/07/02 19:22:58 udp2socks5.go:174: [error] only part pkt had been write to socks5 0 23
2020/07/02 19:22:59 udp2socks5.go:167: [error] write to UDP tunnel failed write udp 192.168.49.199:56809->[::]:36905: address ::: non-IPv4 address
2020/07/02 19:22:59 udp2socks5.go:174: [error] only part pkt had been write to socks5 0 23
2020/07/02 19:23:03 fake.go:50: [dns] resolve ya.ru. on 77.88.8.1:53 failed: read udp 10.111.111.1:60397->77.88.8.1:53: i/o timeout
2020/07/02 19:23:03 fake.go:87: [dns] query ya.ru. failed
2020/07/02 19:23:03 udp2socks5.go:167: [error] write to UDP tunnel failed write udp 192.168.49.199:58837->[::]:43754: address ::: non-IPv4 address
2020/07/02 19:23:03 udp2socks5.go:174: [error] only part pkt had been write to socks5 0 23
2020/07/02 19:23:04 fake.go:50: [dns] resolve ya.ru. on 77.88.8.1:53 failed: read udp 10.111.111.1:52469->77.88.8.1:53: i/o timeout
2020/07/02 19:23:04 fake.go:87: [dns] query ya.ru. failed
2020/07/02 19:23:08 fake.go:50: [dns] resolve ya.ru. on 77.88.8.1:53 failed: read udp 10.111.111.1:57003->77.88.8.1:53: i/o timeout
2020/07/02 19:23:08 fake.go:87: [dns] query ya.ru. failed

Same error when I try to send UDP-packet by netcat

inpos commented 3 years ago

I don't understand why destination is [::]:43754?

inpos commented 3 years ago

Here is tcpdump of tun0:

19:29:08.492200 ip: 10.111.111.1.37227 > 77.88.8.1.53: 4393+ A? ya.ru. (23)
19:29:09.492305 ip: 10.111.111.1.44246 > 77.88.8.1.53: 4393+ A? ya.ru. (23)
19:29:13.493251 ip: 10.111.111.1.41469 > 77.88.8.1.53: 4393+ A? ya.ru. (23)
inpos commented 3 years ago

TCP and ICMP (ping) is working fine.

inpos commented 3 years ago

Here is my config:

[general]
# inet addr/mask
# DEFAULT VALUE: 198.18.0.0/15
# network = 198.18.0.0/15
network = 10.111.111.1/24

# DEFAULT VALUE: 1500
# mtu = 1500

# DEFAULT auto config, This is used for auto set and reset dns server on windows,
# if you have multi interface, the auto config may be not work. eg: eth0, Ethernet0, `Apple USB Ethernet Adapter`.
# interface = Ethernet0

[pprof]
# enabled = false
# prof-host = 127.0.0.1
# prof-port = 6060

[dns]
# dns mode: fake or udp_relay_via_socks5, default fake, fake means google.com -> 10.192.10.126
# dns-mode = udp_relay_via_socks5
#dns-mode = udp_relay_via_socks5

# DEFAULT VALUE: 53
# dns-port = 53

# backend dns
# DEFAULT VALUE: 119.29.29.29:53, 223.5.5.5:53, 8.8.8.8:53
# nameserver = 119.29.29.29:53
# nameserver = 223.5.5.5:53
nameserver = 77.88.8.1:53

# dns-ttl = 600
# dns-packet-size = 4096
# dns-read-timeout = 5
# dns-write-timeout = 5

auto-config-system-dns = true

[route]
# eg: sudo ip route add 91.108.4.0/22 dev tun0
# If you have large route tables, please add it with route batch mode by yourself,
# or it will take a long time.
# batch mode:
#   linux -> `ip -batch`
#   osx -> @see https://github.com/FlowerWrong/ip2socks/blob/master/scripts/darwin_setup_utun.sh#L14-L16
v = 0.0.0.0/0
#v = 91.108.4.0/22
#v = 91.108.56.0/22
#v = 109.239.140.0/24
#v = 149.154.160.0/20
#v = 149.154.167.0/24
#v = 8.8.8.8
#v = 4.4.4.4

[tcp]
# default 1 minutes
# timeout = 60

[udp]
# Enable udp relay or not, default true
# enabled = true

# default 5 minutes
# timeout = 300

# This proxy is used to relay udp data via socks5, so it must be socks5 with udp support.
# If dns-mode is udp_relay_via_socks5, tun2socks will use this proxy to relay.
# If dns-mode is fake, tun2socks will use the fake domain matched proxy, also || this one.
proxy = A

## socks5://[user:password@]host[:port]
# define a proxy named "A"
[proxy "A"]
url = socks5://192.168.49.1:1080
default = yes

# define a proxy named "B"
#[proxy "B"]
#url = socks5://127.0.0.1:1080
# use this proxy as default
#default = yes