shadowsocks-android icon indicating copy to clipboard operation
shadowsocks-android copied to clipboard

安卓客户端的dns查询的一个问题,导致路由器ipset失效,希望有解决方案。

Open yebr opened this issue 10 years ago • 8 comments

ss客户端dns访问一个目标网站时,安卓版会解析成IP去连接,电脑版是以域名去连接。 例如,当我使用电脑版的ss客户端,我要访问www.cn.wsj.com,在SS服务器的日志上会显示:connect to: www.cn.wsj.com:80。 当我使用的是安卓版的ss客户端,在SS服务器的日志上会显示:connect to:111.108.54.9:80,就是相当于安卓客户端已经对www.cn.wsj.com先进行解析,再把连接请求发到ss服务器。 因为SS服务器端所在的环境并不是一个无墙环境,而是通过vpn方式连到被屏蔽的网站,被屏蔽的网站的ip是用dnsmasq根据访问域名时放进ipset的,在ipset列表中的ip通过vpn方式访问外网。 如果是像电脑那种基于域名的话,路由器就能解析该域名放到ipset列表中,但用安卓客户端的话,因为本来已经是ip,无法放进ipset的列表中,这导致了该ip无法通过vpn访问外网。 希望在日后的安卓新版中,能定义设置为不先解析域名为ip,而是直接把域名扔到ss服务器端进行解析处理,谢谢!

yebr avatar Jul 21 '16 08:07 yebr

Shadowsocks-android works as a transparent proxy (or called "user-mode TCP/UDP NAT"). So you won't have remote dns resolve.

madeye avatar Jul 21 '16 08:07 madeye

好的,我能看懂英文,但我英文语法不好,请允许我用中文输入。 请问有方法输出每个连接的ip吗?这样我就能把ip添加到ipset中,或者有没其它识别方法可以让iptables识别到安卓客户端的流量,让这些流量走vpn?

thanks for responding,my english is not good,I typed in chinese,and with simple english :). is there any way to export the "connect to “ ip addresses to ipset? or is there any way to match the shadowsocks flows from iptables? if matched i can set the shadowsocks flows pass throght the vpn network.

yebr avatar Jul 21 '16 09:07 yebr

@yebr 你可以在ss服务器上使用类似iptables -m owner的办法匹配ss服务器产生的流量。

andronoob avatar Jul 21 '16 10:07 andronoob

已解决,当弄清楚了android ss客户端的通信方式后,其实解决方法好简单,客户端打开udp转发,然后路由器把8.8.8.8 DNAT到本地DNS地址,这样就能触发本地DNS设置的ipset规则。

yebr avatar Jul 25 '16 04:07 yebr

@yebr 你服务端用的什么?怎么让安卓端转发udp到服务端的?使用iptables -t nat -A OUTPUT -d 8.8.8.8 -j DNAT --to-destination 192.168.1.1吗?我在服务端(ss-rm-mu)将 192.168.1.1改成服务端的dns内部ip久直接无法上网了,你怎么解决的呢?

junweigu avatar Aug 28 '16 01:08 junweigu

@junweigu 服务器端是shadowsocksr-server,安卓软件钩上“使用UDP转发”,那么所有UDP请求就会转发到路由器。另外,你要理解ss的通信方式、iptables的规则和理解路由的基本知识,感觉你好像有点乱撞的感觉。 好好运用-v看数据,路由器上用tcpdump,就能排除到错误,和理解到ss的通信方式。

我现在用的方法是这个: https://github.com/shadowsocks/shadowsocks-android/issues/96#issuecomment-238138056 是路由器里增加环回ip,不是修改路由器ip。

yebr avatar Aug 29 '16 01:08 yebr

感谢回复,我不是路由器版本,我是服务器后端,可能不一样

2016年8月29日 09:49,"yebr" [email protected]写道:

@junweigu https://github.com/junweigu 服务器端是shadowsocksr-server, 改ip与服务器端的ss软件无关,是在路由器里增加一个环回ip,是增加,不是修改。

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shadowsocks/shadowsocks-android/issues/775#issuecomment-243015332, or mute the thread https://github.com/notifications/unsubscribe-auth/ABbIMFUidhykUxTjnYn5aBwcftxtDBxqks5qkjqTgaJpZM4JRiwY .

junweigu avatar Aug 29 '16 11:08 junweigu

路由器版和linux版基本是一样的,服务器端打开udp转发,只需要加一个参数-u,具体参数如下: root@OpenWrt:~# /usr/bin/ssr-server --help

shadowsocks-libev 2.4.5

maintained by Max Lv [email protected] and Linus Yang [email protected]

usage:

ss-server

   -s <server_host>           Host name or ip address of your remote server.
   -p <server_port>           Port number of your remote server.
   -l <local_port>            Port number of your local server.
   -k <password>              Password of your remote server.
   -m <encrypt_method>        Encrypt method: table, rc4, rc4-md5,
                              aes-128-cfb, aes-192-cfb, aes-256-cfb,
                              bf-cfb, camellia-128-cfb, camellia-192-cfb,
                              camellia-256-cfb, cast5-cfb, des-cfb, idea-cfb,
                              rc2-cfb, seed-cfb, salsa20 and chacha20.

   [-a <user>]                Run as another user.
   [-f <pid_file>]            The file path to store pid.
   [-t <timeout>]             Socket timeout in seconds.
   [-c <config_file>]         The path to config file.
   [-n <number>]              Max number of open files.
   [-i <interface>]           Network interface to bind.

   [-u]                       Enable UDP relay,
   [-U]                       Enable UDP relay and disable TCP relay.
   [-A]                       Enable onetime authentication.
   [-w]                       Enable white list mode (when ACL enabled).

   [-d <addr>]                Name servers for internal DNS resolver.
   [--fast-open]              Enable TCP fast open.
                              with Linux kernel > 3.7.0.
   [--acl <acl_file>]         Path to ACL (Access Control List).
   [--manager-address <addr>] UNIX domain socket address.

   [-v]  

另外你可以先排除是否iptables的默认过滤功能禁止了通信,例如ss服务器使用8765端口建立,就加上: iptables -A INPUT -p tcp --dport 8765 -j ACCEPT iptables -A INPUT -p udp --dport 8765 -j ACCEPT

yebr avatar Aug 31 '16 05:08 yebr