From 5b8edbaeada58c5d5fdc1059f12fd42ae052b2d2 Mon Sep 17 00:00:00 2001
From: Tunglies <77394545+Tunglies@users.noreply.github.com>
Date: Sun, 25 Oct 2026 16:03:07 +0800
Subject: [PATCH] feat(tun): expose mihomo tun dns-mode in TUN settings
Support the dns-mode field introduced in mihomo v1.19.33. A
button group below the stack selector offers
Auto/Disabled/Native/Hijack; Auto writes an empty string, which
the core treats as the legacy behavior. Adding dns-mode to
GUI_KEYS makes the value GUI-authoritative once saved, matching
the other TUN dialog fields.
---
Changelog.md | 1 +
src-tauri/src/constants.rs | 1 +
.../setting/mods/dns-mode-switch.tsx | 43 +++++++++++++++++++
src/components/setting/mods/tun-viewer.tsx | 25 +++++++++++
src/locales/ar/settings.json | 2 +
src/locales/de/settings.json | 2 +
src/locales/en/settings.json | 2 +
src/locales/es/settings.json | 2 +
src/locales/fa/settings.json | 2 +
src/locales/id/settings.json | 2 +
src/locales/jp/settings.json | 2 +
src/locales/ko/settings.json | 2 +
src/locales/pt/settings.json | 2 +
src/locales/ru/settings.json | 2 +
src/locales/tr/settings.json | 2 +
src/locales/tt/settings.json | 2 +
src/locales/zh/settings.json | 2 +
src/locales/zhtw/settings.json | 2 +
src/types/generated/i18n-keys.ts | 2 +
src/types/generated/i18n-resources.ts | 2 +
src/types/global.d.ts | 1 +
21 files changed, 103 insertions(+)
create mode 100644 src/components/setting/mods/dns-mode-switch.tsx
diff --git a/Changelog.md b/Changelog.md
index 0110ee42a..87adb73ee 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -17,6 +17,7 @@
✨ 新增功能
+- 新增虚拟网卡设置的「DNS 模式」选项,支持配置 mihomo 系统 DNS 行为
diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs
index 4dc70de31..da67ce13e 100644
--- a/src-tauri/src/constants.rs
+++ b/src-tauri/src/constants.rs
@@ -75,6 +75,7 @@ pub mod tun {
"auto-redirect",
"auto-detect-interface",
"dns-hijack",
+ "dns-mode",
"strict-route",
"mtu",
];
diff --git a/src/components/setting/mods/dns-mode-switch.tsx b/src/components/setting/mods/dns-mode-switch.tsx
new file mode 100644
index 000000000..9927ca525
--- /dev/null
+++ b/src/components/setting/mods/dns-mode-switch.tsx
@@ -0,0 +1,43 @@
+import { Button, ButtonGroup } from '@mui/material'
+
+interface Props {
+ value?: string
+ onChange?: (value: string) => void
+}
+
+export const DnsModeSwitch = (props: Props) => {
+ const { value, onChange } = props
+
+ return (
+
+
+
+
+
+
+ )
+}
diff --git a/src/components/setting/mods/tun-viewer.tsx b/src/components/setting/mods/tun-viewer.tsx
index b00355162..41071b723 100644
--- a/src/components/setting/mods/tun-viewer.tsx
+++ b/src/components/setting/mods/tun-viewer.tsx
@@ -26,6 +26,7 @@ import { showNotice } from '@/services/notice-service'
import getSystem from '@/utils/get-system'
import { areValidIpCidrs } from '@/utils/network'
+import { DnsModeSwitch } from './dns-mode-switch'
import { StackModeSwitch } from './stack-mode-switch'
const OS = getSystem()
@@ -52,6 +53,7 @@ export function TunViewer({ ref }: { ref?: Ref }) {
dnsHijack: ['any:53'],
strictRoute: false,
mtu: 1500,
+ dnsMode: '',
})
const routeExcludeAddressItems = splitRouteExcludeAddress(
@@ -84,6 +86,7 @@ export function TunViewer({ ref }: { ref?: Ref }) {
dnsHijack: clash?.tun['dns-hijack'] ?? ['any:53'],
strictRoute: clash?.tun['strict-route'] ?? false,
mtu: clash?.tun.mtu ?? 1500,
+ dnsMode: clash?.tun['dns-mode'] ?? '',
})
},
close: () => setOpen(false),
@@ -117,6 +120,7 @@ export function TunViewer({ ref }: { ref?: Ref }) {
: {}),
'auto-detect-interface': values.autoDetectInterface,
'dns-hijack': values.dnsHijack[0] === '' ? [] : values.dnsHijack,
+ 'dns-mode': values.dnsMode,
'strict-route': values.strictRoute,
mtu: values.mtu ?? 1500,
}
@@ -163,6 +167,7 @@ export function TunViewer({ ref }: { ref?: Ref }) {
'auto-detect-interface': true,
'dns-hijack': ['any:53'],
'route-exclude-address': [],
+ 'dns-mode': '',
'strict-route': false,
mtu: 1500,
}
@@ -176,6 +181,7 @@ export function TunViewer({ ref }: { ref?: Ref }) {
dnsHijack: ['any:53'],
strictRoute: false,
mtu: 1500,
+ dnsMode: '',
})
await patchClash({ tun })
await mutateClash(
@@ -212,6 +218,25 @@ export function TunViewer({ ref }: { ref?: Ref }) {
/>
+
+
+
+
+ {
+ setValues((v) => ({ ...v, dnsMode: value }))
+ }}
+ />
+
+
+