diff --git a/CHANGELOG.md b/CHANGELOG.md index cb90e95..aa993fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Add config flag to allow Headscale to start if OIDC provider is down [#829](https://github.com/juanfont/headscale/pull/829) - Random node DNS suffix only applied if names collide in namespace. [#766](https://github.com/juanfont/headscale/issues/766) - Remove `ip_prefix` configuration option and warning [#899](https://github.com/juanfont/headscale/pull/899) +- Add `dns_config.override_local_dns` option [#905](https://github.com/juanfont/headscale/pull/905) - Fix some DNS config issues [#660](https://github.com/juanfont/headscale/issues/660) ## 0.16.4 (2022-08-21) diff --git a/config-example.yaml b/config-example.yaml index 5dec535..c23c742 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -192,6 +192,9 @@ acl_policy_path: "" # - https://tailscale.com/blog/2021-09-private-dns-with-magicdns/ # dns_config: + # Whether to prefer using Headscale provided DNS or use local. + override_local_dns: true + # List of DNS servers to expose to clients. nameservers: - 1.1.1.1 diff --git a/config.go b/config.go index 056d93f..e38a9f2 100644 --- a/config.go +++ b/config.go @@ -160,6 +160,7 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("log.format", TextLogFormat) viper.SetDefault("dns_config", nil) + viper.SetDefault("dns_config.override_local_dns", true) viper.SetDefault("derp.server.enabled", false) viper.SetDefault("derp.server.stun.enabled", true) @@ -377,6 +378,8 @@ func GetDNSConfig() (*tailcfg.DNSConfig, string) { if viper.IsSet("dns_config") { dnsConfig := &tailcfg.DNSConfig{} + overrideLocalDNS := viper.GetBool("dns_config.override_local_dns") + if viper.IsSet("dns_config.nameservers") { nameserversStr := viper.GetStringSlice("dns_config.nameservers") @@ -399,7 +402,12 @@ func GetDNSConfig() (*tailcfg.DNSConfig, string) { } dnsConfig.Nameservers = nameservers - dnsConfig.Resolvers = resolvers + + if overrideLocalDNS { + dnsConfig.Resolvers = resolvers + } else { + dnsConfig.FallbackResolvers = resolvers + } } if viper.IsSet("dns_config.restricted_nameservers") { diff --git a/integration_test/etc/alt-config.dump.gold.yaml b/integration_test/etc/alt-config.dump.gold.yaml index 9df870f..c30b1ae 100644 --- a/integration_test/etc/alt-config.dump.gold.yaml +++ b/integration_test/etc/alt-config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/alt-config.yaml b/integration_test/etc/alt-config.yaml index 837ba6c..df776ea 100644 --- a/integration_test/etc/alt-config.yaml +++ b/integration_test/etc/alt-config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: [] diff --git a/integration_test/etc/alt-env-config.dump.gold.yaml b/integration_test/etc/alt-env-config.dump.gold.yaml index 2fa8ef4..5b9297a 100644 --- a/integration_test/etc/alt-env-config.dump.gold.yaml +++ b/integration_test/etc/alt-env-config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/alt-env-config.yaml b/integration_test/etc/alt-env-config.yaml index 3856048..392be6a 100644 --- a/integration_test/etc/alt-env-config.yaml +++ b/integration_test/etc/alt-env-config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: [] diff --git a/integration_test/etc/config.dump.gold.yaml b/integration_test/etc/config.dump.gold.yaml index 7bdd2c3..3370ad9 100644 --- a/integration_test/etc/config.dump.gold.yaml +++ b/integration_test/etc/config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/config.yaml b/integration_test/etc/config.yaml index 8b4d7db..efe75fe 100644 --- a/integration_test/etc/config.yaml +++ b/integration_test/etc/config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: []