Skip to content

Commit 0dade75

Browse files
committed
Disable local DNS in proxy mode to prevent Android port 53 permission crash and allow SOCKS5 startup
1 parent b57c95e commit 0dade75

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

android/app/src/main/java/com/masterdns/vpn/service/MasterDnsVpnService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class MasterDnsVpnService : VpnService() {
127127
profile = runtimeProfile,
128128
listenPort = socksPort,
129129
listenIpOverride = listenIpOverride,
130-
protocolOverride = protocolOverride
130+
protocolOverride = protocolOverride,
131+
localDnsEnabledOverride = if (proxyMode) false else null
131132
)
132133
)
133134
if (profile.resolvers.isNotBlank()) {

android/app/src/main/java/com/masterdns/vpn/util/ConfigGenerator.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ object ConfigGenerator {
1919
profile: ProfileEntity,
2020
listenPort: Int = 18000,
2121
listenIpOverride: String? = null,
22-
protocolOverride: String? = null
22+
protocolOverride: String? = null,
23+
localDnsEnabledOverride: Boolean? = null,
24+
localDnsIpOverride: String? = null,
25+
localDnsPortOverride: Int? = null
2326
): String {
2427
val domains = parseDomains(profile.domains)
2528
val domainsStr = domains.joinToString(", ") { "\"$it\"" }
@@ -30,6 +33,10 @@ object ConfigGenerator {
3033
return if (value.isNullOrEmpty()) fallback else value
3134
}
3235

36+
fun cfgInt(key: String, fallback: String): Int {
37+
return cfg(key, fallback).toIntOrNull() ?: fallback.toIntOrNull() ?: 0
38+
}
39+
3340
return buildString {
3441
appendLine("# MasterDnsVPN Client Configuration")
3542
appendLine("# Auto-generated by MasterDnsVPN Android")
@@ -51,7 +58,11 @@ object ConfigGenerator {
5158
appendLine()
5259

5360
// Section 3: Local DNS Service
54-
appendLine("LOCAL_DNS_ENABLED = ${cfg("LOCAL_DNS_ENABLED", "false")}")
61+
appendLine(
62+
"LOCAL_DNS_ENABLED = ${localDnsEnabledOverride?.let { it.toString() } ?: cfg("LOCAL_DNS_ENABLED", "false")}"
63+
)
64+
appendLine("LOCAL_DNS_IP = \"${escapeToml(localDnsIpOverride ?: cfg("LOCAL_DNS_IP", "127.0.0.1"))}\"")
65+
appendLine("LOCAL_DNS_PORT = ${localDnsPortOverride ?: cfgInt("LOCAL_DNS_PORT", "53")}")
5566
appendLine()
5667

5768
// Section 4: Resolver Selection

0 commit comments

Comments
 (0)