From 7a80c03028199d52852818321e0c9c151c8322d9 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Mon, 16 Mar 2026 11:19:04 +0800 Subject: [PATCH] fix: kill NetworkManager's dnsmasq before starting our own NetworkManager auto-starts its own dnsmasq when creating a hotspot, which conflicts with our DNS-hijacking dnsmasq on the same interface. Now kill ALL dnsmasq instances before starting ours. Made-with: Cursor --- .commitmsg | 7 ++++--- lib/dns-hijack.js | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.commitmsg b/.commitmsg index f92650c..b07c924 100644 --- a/.commitmsg +++ b/.commitmsg @@ -1,4 +1,5 @@ -fix: set AP hotspot password to fixed WPA2 PSK "12345678" +fix: kill NetworkManager's dnsmasq before starting our own -Open network was not viable as nmcli generates random password by default. -Use a simple fixed password since the AP is only for short-lived provisioning. +NetworkManager auto-starts its own dnsmasq when creating a hotspot, +which conflicts with our DNS-hijacking dnsmasq on the same interface. +Now kill ALL dnsmasq instances before starting ours. diff --git a/lib/dns-hijack.js b/lib/dns-hijack.js index f805be9..a663f78 100644 --- a/lib/dns-hijack.js +++ b/lib/dns-hijack.js @@ -61,8 +61,10 @@ class DnsHijack { fs.writeFileSync(DNSMASQ_CONF, conf, 'utf8'); log.info('dns', `dnsmasq 配置已写入: ${DNSMASQ_CONF}`); - // 终止系统可能残留的 dnsmasq - try { execSync('pkill -f "dnsmasq.*clawd"', { timeout: 3000 }); } catch (_) {} + // 终止所有 dnsmasq(包括 NetworkManager 自动启动的) + try { execSync('pkill -9 dnsmasq', { timeout: 3000 }); } catch (_) {} + // 等待端口释放 + try { execSync('sleep 1'); } catch (_) {} // 查找 dnsmasq 二进制(/usr/sbin 可能不在普通用户 PATH 中) const dnsmasqBin = findBin('dnsmasq'); @@ -90,7 +92,7 @@ class DnsHijack { this._watchdog.stop(); this._watchdog = null; } - try { execSync('pkill -f "dnsmasq.*clawd"', { timeout: 3000 }); } catch (_) {} + try { execSync('pkill -9 dnsmasq', { timeout: 3000 }); } catch (_) {} try { fs.unlinkSync(DNSMASQ_CONF); } catch (_) {} } }