Skip to content

DNS Upstream TTL troubles #4735

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

Closed
gfw-killer opened this issue May 16, 2025 · 7 comments
Closed

DNS Upstream TTL troubles #4735

gfw-killer opened this issue May 16, 2025 · 7 comments

Comments

@gfw-killer
Copy link

Hello
Some domains like Instagram domains have TTL like 5 seconds, and as after #4526 Xray uses the upstream TTL, it made some Apps like Instagram laggy and the overall Xray client user-experience lower, and also made servers to use more CPU because they must repeatedly resolve domains with low TTL
To fix it we need a min-ttl option to increase TTL when it's lower than N seconds
I know it's possible to use an external DNS resolver for Server, but for Xray Clients we need it
Could you guys help please? @Meo597 @patterniha @Fangliding
Thanks

@Fangliding
Copy link
Member

我记得之前不是有一个最低ttl的吗

@patterniha
Copy link
Contributor

patterniha commented May 16, 2025

TTL changes in a rotating manner:

60, 59, ..., 2, 1, 60, 59, ... , 2, 1, 60, .......

If you saw ttl=5, if you try 5 seconds later, you see ttl=60 this time.

So the average-interval between requests will be at least 60 seconds, and there is no problem.

(Instagram domains ttl is 60 to 1)

@Meo597
Copy link
Contributor

Meo597 commented May 16, 2025

返回真实ttl是为了避免特定场景下因过久的cache导致目标域名解析到了已废弃ip的问题
比如公有云k8s弹性收缩、比如ddns
这是为了让xray行为和网站管理员预期一致

以前是返回给客户端的ttl永远为600,因此你可能十分钟感受到一次卡顿,把问题掩盖住了

但增加CPU负载我表示不太理解,没遇到过,你有数据吗

在“强制改写ttl”出来之前,你可以用这种办法缓解:

  • 如果你是透明代理,改用fakeip

  • 如果你是非透明代理,则:

    1. xray客户端入站出开sniff+overrideDest,把IP改写为域名
    2. 路由domainStrategy=AsIs
      or IPIfNonMatch
      or 把IP规则放前,域名规则放后,设为IPOnDemand

由于你的客户端和服务器之间的连接质量不佳,实际上你应该永远使用这种办法

@gfw-killer
Copy link
Author

gfw-killer commented May 16, 2025

TTL changes in a rotating manner:

60, 59, ..., 2, 1, 60, 59, ... , 2, 1, 60, .......

If you saw ttl=5, if you try 5 seconds later, you see ttl=60 this time.

you are right, so the problem is that Xray server does not adjust ttl based on client request, for example when dns ttl in Xray server cache have 5 seconds to expire and client sends dns request to xray server, xray server will send ttl 5 to the client, and client must 5 seconds later resolve the same domain again to get ttl 60
and no website is going to change IP every minute, if there was such option, i would change the min-ttl of client to 1 min to never get a low ttl, and change server min-rtt to 5 minutes to not get banned by remote DNS servers

@Meo597
Copy link
Contributor

Meo597 commented May 16, 2025

或许可以有个当 PC/Phone 向 Xray 内置的 DNS请求 时检查 TTL < 10
主动刷新缓存
@patterniha

@patterniha
Copy link
Contributor

Maybe there could be a way to check TTL < 10 when the PC/Phone makes a DNS request to Xray's built-in DNS and then actively refresh the cache. @patterniha

There is no difference in practice.

Even if you don't use xray-core, the ttl bevave in rotatating manner.

Xray-core just pass the received ttl.

So even you don't use vpn or xray-core, you may received 5 seconds ttl.

But this is one time, and the average-interval between requests is at least 60 seconds.

///

So Xray-core-dns has no problem and this issue can be closed.

@Fangliding
Copy link
Member

查询一次DNS并没有很大开销 哪怕ttl全是1也只是让xray变成disableCache 把每次dns请求都转发出去而已 所以我并不觉得这是个问题 顶多是有人希望可以refine一下不太想见到的ttl=1

@Fangliding Fangliding closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants