Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义hosts的功能 #2150

Closed
ayanamist opened this issue Mar 7, 2019 · 13 comments · Fixed by #2162

Comments

@ayanamist
Copy link
Contributor

commented Mar 7, 2019

我知道这是一个已经存在的问题 #544 但3年前的实现和现在ss-android的实现有些不同。
我用的购买的ss服务,因此没有ss服务端的权限,ss服务端设了超时比较短,60秒没数据就断开连接,于是fcm就频繁的断开连接。我自己用golang写了一个fcm的中转代理,在国内和国外的vps上都搭了一个针对5228端口的转发,速度不快,但可以满足fcm push的稳定性需要。
以前是通过magisk的systemless hosts功能来修改hosts,把fcm涉及的多个域名全部指向我的服务器来提供服务的。
但更换了华为P20后,无法解锁也没有root能力,无法修改hosts,这条路走不通了。
看了现在的ss-android的方案,之前用的overture是可以指定hosts文件的但也是写死的,最新的用kotlin重写的dns server没有这个能力。
我想加入这个功能但不提供界面,通过targetApi>=19时尝试读取Context.getExternalFilesDir()下的hosts文件来提供这个能力(不存在或无权限则忽略),这样也不需要额外申请权限。
不知道做出这个功能后是否有可能合入?

@madeye madeye added the enhancement label Mar 8, 2019
@madeye

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

I think it's doable.

What do you think? @Mygod

@madeye

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

BTW, setup a private DNS server can also solve your problem:

  1. Set up a DNS server on your private FCM server.
  2. Modify the /etc/hosts on your FCM server.
  3. Modify the "Remote DNS" to your private FCM server.
  4. Done.

On Android 9, you can even setup a system-wide private DNS, (Both EMUI and MIUI support this)

@ayanamist

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

@madeye 主要问题在于直接暴露个dns server在公网上,安全攻击面太大。

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

Sounds like pain. I would set up a DNS forwarder on the remote and put "127.0.0.1:" in remote DNS instead. This should work since 4.7.1.

@ayanamist

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

@Mygod 背景在issue描述里也写了,用的ss是买的,因为线路很好能跑到10MB/s,自己的服务器只能50KB/s自己也买不起那么好线路的服务器。所以用了这个方案。如果能接触到ss服务端,确实可以有很多手段来解决这个问题。
如果两位没问题,我就尝试开干了。

@madeye

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

Hmm, I think the problem here is the user is using a public shadowsocks server and a private FCM server.

Yeah, it makes things complicated. Otherwise, a local DNS resolver running on the shadowsocks server is quite straightforward.

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

In that case, please provide nice user interface instead of this hidden gotcha. Also I do not intend to include storage permission. I'm imagining using a hosts EditTextPreference as a global setting instead. Something like this would be nice: https://github.com/shadowsocks/v2ray-plugin-android/blob/70cc6094aba7fcef187282975bc44a511d0b24c5/app/src/main/java/com/github/shadowsocks/plugin/v2ray/CertificatePreferenceDialogFragment.kt

@ayanamist

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

抱歉,我对Android ui体系完全不熟悉。要求有ui才能合入,我还是fork吧。
多说一句,hosts本身对os来说就是你所谓的"hidden gotcha"

@ayanamist ayanamist closed this Mar 8, 2019
@CzBiX

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

这个功能十分有用,我之前为了研究 #2138 的具体问题时也改了个简单的版本出来。
我觉得完全可以先实现一个尽管简陋但能用的版本,然后再迭代完善界面等。

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

多说一句,hosts本身对os来说就是你所谓的"hidden gotcha"

Linux documents stuff using manual.

$ man 5 hosts

You can do the changes without UI and open a pull request that allows for modification.

@ayanamist

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

fine

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2019

Have you tried system-wide /system/etc/hosts?

@ayanamist

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

@Mygod 我正文中有写

以前是通过magisk的systemless hosts功能来修改hosts,把fcm涉及的多个域名全部指向我的服务器来提供服务的。
但更换了华为P20后,无法解锁也没有root能力,无法修改hosts,这条路走不通了。

magisk就是替换/system/etc/hosts这个文件的mount bind的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.