米家设备非标准域名导致设备离线无法控制,xray有解决方案,v2raya没有找到配置方式 #1361
Replies: 17 comments
-
@yvvw 目前可以用core钩子改写配置,文档里有 |
Beta Was this translation helpful? Give feedback.
-
TL;DR 参考此配置 感谢,已经ok了,贴出代码供其他小伙伴使用 因为我的openwrt预装了node,所以直接用js,参考 https://v2raya.org/docs/manual/hook/ 创建 #!/usr/bin/node
const Stage = {
PreStart: "pre-start",
PostStart: "post-start",
PostStop: "pre-stop",
PostStop: "post-stop",
};
main(process.argv);
// entry point
function main(argv) {
const { stage, transparentType, v2rayaConfdir } = parseArgs(argv);
if (stage === Stage.PreStart) {
preStartHook(stage, transparentType, v2rayaConfdir);
}
}
// pre-start hook
function preStartHook(stage, transparentType, v2rayaConfdir) {
console.log(`executing ${stage}`);
const configPath = `${v2rayaConfdir}/config.json`;
let config = require(configPath);
// 注意这里是dokodemo-door所有流量接管入口的inbound
const idx = config.inbounds.findIndex((it) => it.tag === "transparent");
if (idx === -1) {
console.warn(`未发现transparent inbounds, 请更新脚本`);
} else {
config.inbounds[idx] = {
...config.inbounds[idx],
sniffing: {
...config.inbounds[idx].sniffing,
domainsExcluded: ["mijia cloud"],
},
};
config.api.services = [...config.api.services, "HandlerService"];
require("fs").writeFileSync(configPath, JSON.stringify(config));
}
}
function parseArgs(argv) {
argv = argv.slice(2);
let stage;
let transparentType;
let v2rayaConfdir;
argv.forEach((arg) => {
const [key, val] = arg.split("=");
if (key === "--stage") stage = val;
else if (key === "--transparent-type") transparentType = val;
else if (key === "--v2raya-confdir") v2rayaConfdir = val;
else {
console.error(`unknow option key ${key} value ${val}`);
}
});
return { stage, transparentType, v2rayaConfdir };
} 编辑 ...
start_service() {
config_load "$CONF"
is_enabled "config" "enabled" || exit 1
procd_open_instance "$CONF"
procd_set_param command "$PROG"
procd_set_param env XDG_DATA_HOME="/usr/share"
# 此处添加 core-hook 参数配置,我使用的 luci v2raya 有直接能用的方法,其它情况请自行配置
# 自定义hook
append_env_arg "config" "core_hook" "/etc/v2raya/core-hook.js"
append_env_arg "config" "address" "0.0.0.0:2017"
append_env_arg "config" "config" "/etc/v2raya"
append_env_arg "config" "ipv6_support" "auto"
... 执行 |
Beta Was this translation helpful? Give feedback.
-
@mzz2017 不好意思,还要麻烦您一下,虽然hook生效,配置文件也发生了变化,但是xray没有读取修改后的config.json文件,我将v2raya停止,手动使用xray命令行加修改后的配置文件就没有问题 调试过程如下: 我在修改config后加了1s延迟 v2raya log里显示 2022/11/11 09:16:48.558 [A] [main.go:27] V2Ray binary is /usr/bin/xray
2022/11/11 09:16:48.558 [A] [main.go:27] V2Ray asset directory is /run/user/0/v2raya
2022/11/11 09:16:48.558 [A] [main.go:27] v2rayA working directory is /
2022/11/11 09:16:48.558 [A] [main.go:27] v2rayA configuration directory is /etc/v2raya
2022/11/11 09:16:48.558 [A] [main.go:27] Golang: go1.18.4
2022/11/11 09:16:48.558 [A] [main.go:27] OS: linux
2022/11/11 09:16:48.558 [A] [main.go:27] Arch: arm64
2022/11/11 09:16:48.558 [A] [main.go:27] Lite: false
2022/11/11 09:16:48.558 [A] [main.go:27] Version: 1.5.9.1698.1
2022/11/11 09:16:48.558 [A] [main.go:27] Starting...
2022/11/11 09:16:48.638 [T] [socks5.go:83] [socks5] listening TCP on 127.0.0.1:33065
2022/11/11 09:16:48.649 [I] [processManager.go:245] Execute the core pre start hook: /etc/v2raya/core-hook.js
2022/11/11 09:16:49.278 [I] [asm_arm64.s:1263] [AutoUpdate] Subscriptions: Complete updating subscription -- ID: 0,Address: xxx
2022/11/11 09:16:50.740 [I] [processManager.go:245] Executing the core pre start hook:
Stage pre-start
Transparent Type unknow
Config Directory /etc/v2raya
executing pre-start
executed pre-start
2022/11/11 09:16:50.740 [D] [process.go:99] /usr/bin/xray run --config=/etc/v2raya/config.json
2022/11/11 09:16:50.762 [I] [io.go:428] Xray 1.6.3 (Xray, Penetrates Everything.) OpenWrt (go1.19.2 linux/arm64)
2022/11/11 09:16:50.762 [I] [io.go:428] A unified platform for anti-censorship.
2022/11/11 09:16:50.762 [I] [io.go:428] [Info] infra/conf/serial: Reading config: /etc/v2raya/config.json 可以看到日志里没有同步等待hook执行完成再启动xray,我推测xray和修改配置执行先后顺序不确定,我测试下来一直都是没有读取正确配置 我不太确定是不是log模块是批量flush导致时间显示并非真实时间 翻看了执行代码 v2rayA/service/core/v2ray/process.go Line 95 in 96c8ffd 看起来好像是同步执行的,不是很懂,请问哪里有问题哪 |
Beta Was this translation helpful? Give feedback.
-
根据日志, 有可能是数据还在文件系统的写缓冲区没有写到硬盘(根据不同的文件系统,可能甚至不会标脏),尝试将下列函数封装成 async func: fs.open(filename, "w",(err, fd) => {
// Write our data
fs.writeFile(fd, data, (err) => {
// Force the file to be flushed
fs.fdatasync(fd /*, optional callback here */);
});
}); |
Beta Was this translation helpful? Give feedback.
-
感谢您的耐心指导,我试了下仍然不行,过程如下 首先我再次确认这个配置是有效的,我用v2raya启动生成配置后,关闭服务,使用命令行xray加此配置文件启动,在断开无线让所有设备离线后开启无线功能,xray一直运行没有断开,当网络恢复后,设备都成功在线,说明配置是有效的。 在此基础上,我分别用同步写入并flush,异步写入并flush操作修改配置文件,进行如上同样的断开重连操作,结果都不行 v2raya启动日志 2022/11/11 10:31:00.089 [I] [processManager.go:245] Execute the core pre start hook: /etc/v2raya/core-hook.js
2022/11/11 10:31:00.841 [I] [asm_arm64.s:1263] [AutoUpdate] Subscriptions: Complete updating subscription -- ID: 0,Address: xxx
2022/11/11 10:31:01.162 [I] [processManager.go:245] Executing the core pre start hook:
Stage pre-start
Transparent Type unknow
Config Directory /etc/v2raya
executing pre-start
sync write and flush
2022/11/11 10:31:01.162 [D] [process.go:99] /usr/bin/xray run --config=/etc/v2raya/config.json
2022/11/11 10:31:01.181 [I] [io.go:428] Xray 1.6.3 (Xray, Penetrates Everything.) OpenWrt (go1.19.2 linux/arm64)
2022/11/11 10:31:01.181 [I] [io.go:428] A unified platform for anti-censorship.
2022/11/11 10:31:01.182 [I] [io.go:428] [Info] infra/conf/serial: Reading config: /etc/v2raya/config.json dns错误解析日志,此部分在有效配置情况下是看不到的 2022/11/11 10:35:46.398 [I] [io.go:428] [Info] [793047945] app/dispatcher: sniffed domain: Mijia Cloud
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] app/dns: failed to lookup ip for domain Mijia Cloud at server UDP:127.0.0.1:6553 > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] features/routing/dns: resolve ip for Mijia Cloud > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] app/dns: failed to lookup ip for domain Mijia Cloud at server UDP:127.0.0.1:6553 > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] features/routing/dns: resolve ip for Mijia Cloud > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] [793047945] app/dispatcher: taking detour [proxy] for [tcp:Mijia Cloud:443] |
Beta Was this translation helpful? Give feedback.
-
感谢您的耐心指导,我试了下仍然不行,过程如下 首先我再次确认这个配置是有效的,我用v2raya启动生成配置后,关闭服务,使用命令行xray加此配置文件启动,在断开无线让所有设备离线后开启无线功能,xray一直运行没有断开,当网络恢复后,设备都成功在线,说明配置是有效的。 在此基础上,我分别用同步写入并flush,异步写入并flush操作修改配置文件,进行如上同样的断开重连操作,结果都不行 v2raya启动日志 2022/11/11 10:31:00.089 [I] [processManager.go:245] Execute the core pre start hook: /etc/v2raya/core-hook.js
2022/11/11 10:31:00.841 [I] [asm_arm64.s:1263] [AutoUpdate] Subscriptions: Complete updating subscription -- ID: 0,Address: xxx
2022/11/11 10:31:01.162 [I] [processManager.go:245] Executing the core pre start hook:
Stage pre-start
Transparent Type unknow
Config Directory /etc/v2raya
executing pre-start
sync write and flush
2022/11/11 10:31:01.162 [D] [process.go:99] /usr/bin/xray run --config=/etc/v2raya/config.json
2022/11/11 10:31:01.181 [I] [io.go:428] Xray 1.6.3 (Xray, Penetrates Everything.) OpenWrt (go1.19.2 linux/arm64)
2022/11/11 10:31:01.181 [I] [io.go:428] A unified platform for anti-censorship.
2022/11/11 10:31:01.182 [I] [io.go:428] [Info] infra/conf/serial: Reading config: /etc/v2raya/config.json dns错误解析日志,此部分在有效配置情况下是看不到的 2022/11/11 10:35:46.398 [I] [io.go:428] [Info] [793047945] app/dispatcher: sniffed domain: Mijia Cloud
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] app/dns: failed to lookup ip for domain Mijia Cloud at server UDP:127.0.0.1:6553 > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] features/routing/dns: resolve ip for Mijia Cloud > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] app/dns: failed to lookup ip for domain Mijia Cloud at server UDP:127.0.0.1:6553 > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] features/routing/dns: resolve ip for Mijia Cloud > rcode: 3
2022/11/11 10:35:46.399 [I] [io.go:428] [Info] [793047945] app/dispatcher: taking detour [proxy] for [tcp:Mijia Cloud:443] |
Beta Was this translation helpful? Give feedback.
-
@yvvw 嗯确实是个奇怪的事情,你试一下手动 node hook.js; cat xxx.json 呢 |
Beta Was this translation helpful? Give feedback.
-
好像不是这个原因,我用下面这个做hook入口,打印内容都是对的,不过dns仍然有问题 #!/bin/bash
node /etc/v2raya/core-hook.js $@ && cat /etc/v2raya/config.json 2022/11/11 11:10:56.536 [I] [processManager.go:245] Executing the core pre start hook:
Stage pre-start
Transparent Type unknow
Config Directory /etc/v2raya
executing pre-start
{..."sniffing":{"enabled":false,"metadataOnly":false,"domainsExcluded":["mijia cloud"]},"settings":{"network":"udp","address":"2.0.1.7","port":53}...
2022/11/11 11:10:56.537 [D] [process.go:99] /usr/bin/xray run --config=/etc/v2raya/config.json
2022/11/11 11:10:56.562 [I] [io.go:428] Xray 1.6.3 (Xray, Penetrates Everything.) OpenWrt (go1.19.2 linux/arm64)
2022/11/11 11:10:56.562 [I] [io.go:428] A unified platform for anti-censorship.
2022/11/11 11:10:56.562 [I] [io.go:428] [Info] infra/conf/serial: Reading config: /etc/v2raya/config.json 我搜索发现xray能动态添加删除inbound配置https://xtls.github.io/en/document/command.html#xray-api 我想在启动后删除旧的添加新的inbound,因为该命令操作需要HandlerService权限https://xtls.github.io/en/config/api.html#handlerservice 看了下 v2raya 生成的配置中不包含此权限,抱着试一试的态度,重新用hook添加,发现用hook生成的配置竟然是有效的,命令行判断HandlerService权限添加成功了 那就说明之前推测xray没有正确读取config.json文件的想法是错的 在此基础上,我用xray api命令行删除再创建inbound发现仍然出现dns问题。因为xray没法查看运行状态下所有配置详情,那么默认认为配置过程没问题,测试方式是删除inbound发现dns功能失效,重新添加后恢复 所以我感觉有没有可能通过 v2raya 创建的 xray 进程由于某种权限原因导致嗅探功能失效?
{
"inbounds": [
{
"port": 53,
"protocol": "dokodemo-door",
"listen": "0.0.0.0",
"sniffing": {
"enabled": false,
"metadataOnly": false,
"domainsExcluded": ["mijia cloud"]
},
"settings": { "network": "udp", "address": "2.0.1.7", "port": 53 },
"streamSettings": null,
"tag": "dns-in"
}
]
} |
Beta Was this translation helpful? Give feedback.
-
等等……你不要把excluded加到dns-in,应该加到以transparent开头的tag去 |
Beta Was this translation helpful? Give feedback.
-
谢谢您,已经好了,应该是nat配置把所有流量包括53端口都转发到dokodemo-door的原因吧 |
Beta Was this translation helpful? Give feedback.
-
@yvvw 不是的,是因为嗅探不是对 dns,是对 tls/http |
Beta Was this translation helpful? Give feedback.
-
不过我有一事不明,在配置到dns-in的情况下,用xray直接启动也是正常的,这是为什么那 |
Beta Was this translation helpful? Give feedback.
-
@yvvw xray启动没有开透明代理? |
Beta Was this translation helpful? Give feedback.
-
哦哦,对的,用v2raya启动xray后,应该有路由表配置,感谢 |
Beta Was this translation helpful? Give feedback.
-
@yvvw 感谢!您的脚本帮助了我!我的情况是:2个米家设备连不上网络,一个智米电暖器,一个绘睡水暖毯。其他米家设备都是好的。在研究在你的脚本后,按照你的步骤修改V2RayA的配置,重启V2rayA后米家设备就全正常了。 吐槽一下:
我想吐槽的点是:技术工种真是让人又恨又爱。 最后再说声谢谢,这个问题困扰了我一两年,从用上OpenWRT做旁路由以后就有,一直忍着,今天终于花了好几个小时全搞定了。 |
Beta Was this translation helpful? Give feedback.
-
@mzz2017 另外有个小建议,在国内使用米家设备的人很多,其中用了V2RayA的用户估计也不少,还是有些数量的。能不能在V2rayA的界面上增加一个选项,对domainsExcluded进行配置,或者直接提供一个开关选项,比如叫:米家设备高兼容性。V2rayA如果能提供原生选项就更方便了。 |
Beta Was this translation helpful? Give feedback.
-
今天我也遇到这个问题了,但是node实在安装不下,就用bash脚本实现了一个 使用这个脚本需要安装依赖jq,直接opkg install就可以了,其他配置和这个issues里面一样
|
Beta Was this translation helpful? Give feedback.
-
版本、安装方式、系统
你在使用什么版本的v2rayA 1.5.9.1698.1
Xray 1.6.3 (Xray, Penetrates Everything.) OpenWrt (go1.19.2 linux/arm64)
你通过什么方式安装v2rayA opkg
你所使用的操作系统 openwrt 22.03.2
描述问题:
米家设备(yeelight台灯,除湿机,插头等)使用非标准域名(Mijia Cloud)导致dns查询失败,结果设备离线无法控制,xray有解决方案,但v2raya没有找到配置方式,我使用的redirect模式
XTLS/Xray-core#293 有解决方案
v2raya生成
/etc/v2raya/config.json
文件后,在dns-in inbound sniffing 选项下添加"domainsExcluded": ["mijia cloud"]
参数即可。修改生成后的配置文件用xray启动测试成功,不过没找到方法在v2raya中配置,
v2ray-confdir
这个选项感觉可以用,不过没弄明白,求大神帮忙v2rayA运行日志(Optional):
Beta Was this translation helpful? Give feedback.
All reactions