diff --git a/component/resolver/host.go b/component/resolver/host.go index 4a4296290..7e299a099 100644 --- a/component/resolver/host.go +++ b/component/resolver/host.go @@ -13,7 +13,10 @@ import ( "github.com/zhangyunhao116/fastrand" ) -var DisableSystemHosts, _ = strconv.ParseBool(os.Getenv("DISABLE_SYSTEM_HOSTS")) +var ( + DisableSystemHosts, _ = strconv.ParseBool(os.Getenv("DISABLE_SYSTEM_HOSTS")) + UseSystemHosts bool +) type Hosts struct { *trie.DomainTrie[HostValue] @@ -51,7 +54,8 @@ func (h *Hosts) Search(domain string, isDomain bool) (*HostValue, bool) { return &hostValue, false } - if !isDomain && !DisableSystemHosts { + + if !isDomain && !DisableSystemHosts && UseSystemHosts { addr, _ := lookupStaticHost(domain) if hostValue, err := NewHostValue(addr); err == nil { return &hostValue, true diff --git a/config/config.go b/config/config.go index f425092ac..b76c40ff8 100644 --- a/config/config.go +++ b/config/config.go @@ -114,6 +114,7 @@ type DNS struct { PreferH3 bool `yaml:"prefer-h3"` IPv6 bool `yaml:"ipv6"` IPv6Timeout uint `yaml:"ipv6-timeout"` + UseSystemHosts bool `yaml:"use-system-hosts"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` FallbackFilter FallbackFilter `yaml:"fallback-filter"` @@ -209,6 +210,7 @@ type RawDNS struct { IPv6 bool `yaml:"ipv6" json:"ipv6"` IPv6Timeout uint `yaml:"ipv6-timeout" json:"ipv6-timeout"` UseHosts bool `yaml:"use-hosts" json:"use-hosts"` + UseSystemHosts bool `yaml:"use-system-hosts" json:"use-system-hosts"` NameServer []string `yaml:"nameserver" json:"nameserver"` Fallback []string `yaml:"fallback" json:"fallback"` FallbackFilter RawFallbackFilter `yaml:"fallback-filter" json:"fallback-filter"` @@ -456,12 +458,13 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { Interval: 30, }, DNS: RawDNS{ - Enable: false, - IPv6: false, - UseHosts: true, - IPv6Timeout: 100, - EnhancedMode: C.DNSMapping, - FakeIPRange: "198.18.0.1/16", + Enable: false, + IPv6: false, + UseHosts: true, + UseSystemHosts: true, + IPv6Timeout: 100, + EnhancedMode: C.DNSMapping, + FakeIPRange: "198.18.0.1/16", FallbackFilter: RawFallbackFilter{ GeoIP: true, GeoIPCode: "CN", @@ -1285,12 +1288,13 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[resolver.HostValue], rul } dnsCfg := &DNS{ - Enable: cfg.Enable, - Listen: cfg.Listen, - PreferH3: cfg.PreferH3, - IPv6Timeout: cfg.IPv6Timeout, - IPv6: cfg.IPv6, - EnhancedMode: cfg.EnhancedMode, + Enable: cfg.Enable, + Listen: cfg.Listen, + PreferH3: cfg.PreferH3, + IPv6Timeout: cfg.IPv6Timeout, + IPv6: cfg.IPv6, + UseSystemHosts: cfg.UseSystemHosts, + EnhancedMode: cfg.EnhancedMode, FallbackFilter: FallbackFilter{ IPCIDR: []netip.Prefix{}, GeoSite: []router.DomainMatcher{}, diff --git a/hub/executor/executor.go b/hub/executor/executor.go index c23eb9f3b..56e716326 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -253,6 +253,7 @@ func updateDNS(c *config.DNS, ruleProvider map[string]provider.RuleProvider, gen resolver.DefaultResolver = r resolver.DefaultHostMapper = m resolver.DefaultLocalServer = dns.NewLocalServer(r, m) + resolver.UseSystemHosts = c.UseSystemHosts if pr.Invalid() { resolver.ProxyServerHostResolver = pr