diff --git a/v2rayN/ServiceLib/Common/JsonUtils.cs b/v2rayN/ServiceLib/Common/JsonUtils.cs
index 773ba79c..6954e124 100644
--- a/v2rayN/ServiceLib/Common/JsonUtils.cs
+++ b/v2rayN/ServiceLib/Common/JsonUtils.cs
@@ -128,5 +128,8 @@ public class JsonUtils
///
///
///
- public static JsonNode? SerializeToNode(object? obj) => JsonSerializer.SerializeToNode(obj);
+ public static JsonNode? SerializeToNode(object? obj, JsonSerializerOptions? options = null)
+ {
+ return JsonSerializer.SerializeToNode(obj, options);
+ }
}
diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs
index 4888ab6a..11acde71 100644
--- a/v2rayN/ServiceLib/Global.cs
+++ b/v2rayN/ServiceLib/Global.cs
@@ -76,6 +76,13 @@ public class Global
public const int SpeedTestPageSize = 1000;
public const string LinuxBash = "/bin/bash";
+ public const string SingboxDirectDNSTag = "direct_dns";
+ public const string SingboxRemoteDNSTag = "remote_dns";
+ public const string SingboxOutboundResolverTag = "outbound_resolver";
+ public const string SingboxFinalResolverTag = "final_resolver";
+ public const string SingboxHostsDNSTag = "hosts_dns";
+ public const string SingboxFakeDNSTag = "fake_dns";
+
public static readonly List IEProxyProtocols =
[
"{ip}:{http_port}",
@@ -351,25 +358,42 @@ public class Global
public static readonly List SingboxDomainStrategy4Out =
[
- "ipv4_only",
+ "",
+ "ipv4_only",
"prefer_ipv4",
"prefer_ipv6",
- "ipv6_only",
- ""
+ "ipv6_only"
];
- public static readonly List DomainDNSAddress =
+ public static readonly List DomainDirectDNSAddress =
[
- "223.5.5.5",
- "223.6.6.6",
+ "https://dns.alidns.com/dns-query",
+ "https://doh.pub/dns-query",
+ "223.5.5.5",
+ "119.29.29.29",
"localhost"
];
- public static readonly List SingboxDomainDNSAddress =
+ public static readonly List DomainRemoteDNSAddress =
+ [
+ "https://cloudflare-dns.com/dns-query",
+ "https://dns.cloudflare.com/dns-query",
+ "https://dns.google/dns-query",
+ "https://doh.dns.sb/dns-query",
+ "https://doh.opendns.com/dns-query",
+ "https://common.dot.dns.yandex.net",
+ "8.8.8.8",
+ "1.1.1.1",
+ "185.222.222.222",
+ "208.67.222.222",
+ "77.88.8.8"
+ ];
+
+ public static readonly List DomainPureIPDNSAddress =
[
"223.5.5.5",
- "223.6.6.6",
- "dhcp://auto"
+ "119.29.29.29",
+ "localhost"
];
public static readonly List Languages =
@@ -539,5 +563,30 @@ public class Global
BlockTag
];
+ public static readonly Dictionary> PredefinedHosts = new()
+ {
+ { "dns.google", new List { "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844" } },
+ { "dns.alidns.com", new List { "223.5.5.5", "223.6.6.6", "2400:3200::1", "2400:3200:baba::1" } },
+ { "one.one.one.one", new List { "1.1.1.1", "1.0.0.1", "2606:4700:4700::1111", "2606:4700:4700::1001" } },
+ { "1dot1dot1dot1.cloudflare-dns.com", new List { "1.1.1.1", "1.0.0.1", "2606:4700:4700::1111", "2606:4700:4700::1001" } },
+ { "cloudflare-dns.com", new List { "104.16.249.249", "104.16.248.249", "2606:4700::6810:f8f9", "2606:4700::6810:f9f9" } },
+ { "dns.cloudflare.com", new List { "104.16.132.229", "104.16.133.229", "2606:4700::6810:84e5", "2606:4700::6810:85e5" } },
+ { "dot.pub", new List { "1.12.12.12", "120.53.53.53" } },
+ { "dns.quad9.net", new List { "9.9.9.9", "149.112.112.112", "2620:fe::fe", "2620:fe::9" } },
+ { "dns.yandex.net", new List { "77.88.8.8", "77.88.8.1", "2a02:6b8::feed:0ff", "2a02:6b8:0:1::feed:0ff" } },
+ { "dns.sb", new List { "185.222.222.222", "2a09::" } },
+ { "dns.umbrella.com", new List { "208.67.220.220", "208.67.222.222", "2620:119:35::35", "2620:119:53::53" } },
+ { "dns.sse.cisco.com", new List { "208.67.220.220", "208.67.222.222", "2620:119:35::35", "2620:119:53::53" } },
+ { "engage.cloudflareclient.com", new List { "162.159.192.1", "2606:4700:d0::a29f:c001" } }
+ };
+
+ public static readonly List ExpectedIPs =
+ [
+ "geoip:cn",
+ "geoip:ir",
+ "geoip:ru",
+ ""
+ ];
+
#endregion const
}
diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
index 6c93d868..998c2427 100644
--- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs
+++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
@@ -112,6 +112,11 @@ public class ConfigHandler
config.ConstItem ??= new ConstItem();
+ if (config.SimpleDNSItem == null)
+ {
+ InitBuiltinSimpleDNS(config);
+ }
+
config.SpeedTestItem ??= new();
if (config.SpeedTestItem.SpeedTestTimeout < 10)
{
@@ -2094,18 +2099,38 @@ public class ConfigHandler
///
/// Initialize built-in DNS configurations
/// Creates default DNS items for V2Ray and sing-box
+ /// Also checks existing DNS items and disables those with empty NormalDNS
///
/// Current configuration
/// 0 if successful
public static async Task InitBuiltinDNS(Config config)
{
var items = await AppHandler.Instance.DNSItems();
+
+ // Check existing DNS items and disable those with empty NormalDNS
+ var needsUpdate = false;
+ foreach (var existingItem in items)
+ {
+ if (existingItem.NormalDNS.IsNullOrEmpty() && existingItem.Enabled)
+ {
+ existingItem.Enabled = false;
+ needsUpdate = true;
+ }
+ }
+
+ // Update items if any changes were made
+ if (needsUpdate)
+ {
+ await SQLiteHelper.Instance.UpdateAllAsync(items);
+ }
+
if (items.Count <= 0)
{
var item = new DNSItem()
{
Remarks = "V2ray",
CoreType = ECoreType.Xray,
+ Enabled = false,
};
await SaveDNSItems(config, item);
@@ -2113,6 +2138,7 @@ public class ConfigHandler
{
Remarks = "sing-box",
CoreType = ECoreType.sing_box,
+ Enabled = false,
};
await SaveDNSItems(config, item2);
}
@@ -2184,6 +2210,38 @@ public class ConfigHandler
#endregion DNS
+ #region Simple DNS
+
+ public static int InitBuiltinSimpleDNS(Config config)
+ {
+ config.SimpleDNSItem = new SimpleDNSItem()
+ {
+ UseSystemHosts = false,
+ AddCommonHosts = true,
+ FakeIP = false,
+ BlockBindingQuery = true,
+ DirectDNS = Global.DomainDirectDNSAddress.FirstOrDefault(),
+ RemoteDNS = Global.DomainRemoteDNSAddress.FirstOrDefault(),
+ SingboxOutboundsResolveDNS = Global.DomainDirectDNSAddress.FirstOrDefault(),
+ SingboxFinalResolveDNS = Global.DomainPureIPDNSAddress.FirstOrDefault()
+ };
+ return 0;
+ }
+
+ public static async Task GetExternalSimpleDNSItem(string url)
+ {
+ var downloadHandle = new DownloadService();
+ var templateContent = await downloadHandle.TryDownloadString(url, true, "");
+ if (templateContent.IsNullOrEmpty())
+ return null;
+ var template = JsonUtils.Deserialize(templateContent);
+ if (template == null)
+ return null;
+ return template;
+ }
+
+ #endregion Simple DNS
+
#region Regional Presets
///
@@ -2205,6 +2263,8 @@ public class ConfigHandler
await SQLiteHelper.Instance.DeleteAllAsync();
await InitBuiltinDNS(config);
+ InitBuiltinSimpleDNS(config);
+
return true;
case EPresetType.Russia:
@@ -2215,6 +2275,8 @@ public class ConfigHandler
await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.Xray, Global.DNSTemplateSources[1] + "v2ray.json"));
await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.sing_box, Global.DNSTemplateSources[1] + "sing_box.json"));
+ config.SimpleDNSItem = await GetExternalSimpleDNSItem(Global.DNSTemplateSources[1] + "simple_dns.json");
+
return true;
case EPresetType.Iran:
@@ -2225,6 +2287,8 @@ public class ConfigHandler
await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.Xray, Global.DNSTemplateSources[2] + "v2ray.json"));
await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.sing_box, Global.DNSTemplateSources[2] + "sing_box.json"));
+ config.SimpleDNSItem = await GetExternalSimpleDNSItem(Global.DNSTemplateSources[2] + "simple_dns.json");
+
return true;
}
diff --git a/v2rayN/ServiceLib/Models/Config.cs b/v2rayN/ServiceLib/Models/Config.cs
index 15996608..91b49b29 100644
--- a/v2rayN/ServiceLib/Models/Config.cs
+++ b/v2rayN/ServiceLib/Models/Config.cs
@@ -48,6 +48,7 @@ public class Config
public List Inbound { get; set; }
public List GlobalHotkeys { get; set; }
public List CoreTypeItem { get; set; }
+ public SimpleDNSItem SimpleDNSItem { get; set; }
#endregion other entities
}
diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs
index c6254b9f..998b49f1 100644
--- a/v2rayN/ServiceLib/Models/ConfigItems.cs
+++ b/v2rayN/ServiceLib/Models/ConfigItems.cs
@@ -253,3 +253,21 @@ public class WindowSizeItem
public int Width { get; set; }
public int Height { get; set; }
}
+
+[Serializable]
+public class SimpleDNSItem
+{
+ public bool? UseSystemHosts { get; set; }
+ public bool? AddCommonHosts { get; set; }
+ public bool? FakeIP { get; set; }
+ public bool? BlockBindingQuery { get; set; }
+ public string? DirectDNS { get; set; }
+ public string? RemoteDNS { get; set; }
+ public string? SingboxOutboundsResolveDNS { get; set; }
+ public string? SingboxFinalResolveDNS { get; set; }
+ public string? RayStrategy4Freedom { get; set; }
+ public string? SingboxStrategy4Direct { get; set; }
+ public string? SingboxStrategy4Proxy { get; set; }
+ public string? Hosts { get; set; }
+ public string? DirectExpectedIPs { get; set; }
+}
diff --git a/v2rayN/ServiceLib/Models/DNSItem.cs b/v2rayN/ServiceLib/Models/DNSItem.cs
index 59ab9c9b..9474d906 100644
--- a/v2rayN/ServiceLib/Models/DNSItem.cs
+++ b/v2rayN/ServiceLib/Models/DNSItem.cs
@@ -9,7 +9,7 @@ public class DNSItem
public string Id { get; set; }
public string Remarks { get; set; }
- public bool Enabled { get; set; } = true;
+ public bool Enabled { get; set; } = false;
public ECoreType CoreType { get; set; }
public bool UseSystemHosts { get; set; }
public string? NormalDNS { get; set; }
diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs
index c63acc4a..cbaf77e6 100644
--- a/v2rayN/ServiceLib/Models/SingboxConfig.cs
+++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs
@@ -36,6 +36,7 @@ public class Dns4Sbox
public class Route4Sbox
{
+ public Rule4Sbox? default_domain_resolver { get; set; } // or string
public bool? auto_detect_interface { get; set; }
public List rules { get; set; }
public List? rule_set { get; set; }
@@ -75,7 +76,7 @@ public class Rule4Sbox
public string? strategy { get; set; }
public List? sniffer { get; set; }
public string? rcode { get; set; }
- public List