Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "override local DNS" #905

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand All @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-config.dump.gold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-env-config.dump.gold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-env-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/config.dump.gold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down