diff --git a/client/internal/dns/file_linux.go b/client/internal/dns/file_linux.go index 45ac18886..817c5a9b5 100644 --- a/client/internal/dns/file_linux.go +++ b/client/internal/dns/file_linux.go @@ -32,6 +32,10 @@ func newFileConfigurator() (hostManager, error) { return &fileConfigurator{}, nil } +func (f *fileConfigurator) supportCustomPort() bool { + return false +} + func (f *fileConfigurator) applyDNSConfig(config hostDNSConfig) error { backupFileExist := false _, err := os.Stat(fileDefaultResolvConfBackupLocation) diff --git a/client/internal/dns/host.go b/client/internal/dns/host.go index 756f0a515..743ececdc 100644 --- a/client/internal/dns/host.go +++ b/client/internal/dns/host.go @@ -10,6 +10,7 @@ import ( type hostManager interface { applyDNSConfig(config hostDNSConfig) error restoreHostDNS() error + supportCustomPort() bool } type hostDNSConfig struct { @@ -26,8 +27,9 @@ type domainConfig struct { } type mockHostConfigurator struct { - applyDNSConfigFunc func(config hostDNSConfig) error - restoreHostDNSFunc func() error + applyDNSConfigFunc func(config hostDNSConfig) error + restoreHostDNSFunc func() error + supportCustomPortFunc func() bool } func (m *mockHostConfigurator) applyDNSConfig(config hostDNSConfig) error { @@ -44,10 +46,18 @@ func (m *mockHostConfigurator) restoreHostDNS() error { return fmt.Errorf("method restoreHostDNS is not implemented") } +func (m *mockHostConfigurator) supportCustomPort() bool { + if m.supportCustomPortFunc != nil { + return m.supportCustomPortFunc() + } + return false +} + func newNoopHostMocker() hostManager { return &mockHostConfigurator{ - applyDNSConfigFunc: func(config hostDNSConfig) error { return nil }, - restoreHostDNSFunc: func() error { return nil }, + applyDNSConfigFunc: func(config hostDNSConfig) error { return nil }, + restoreHostDNSFunc: func() error { return nil }, + supportCustomPortFunc: func() bool { return true }, } } diff --git a/client/internal/dns/host_darwin.go b/client/internal/dns/host_darwin.go index 9ced1fe48..677efaef4 100644 --- a/client/internal/dns/host_darwin.go +++ b/client/internal/dns/host_darwin.go @@ -8,8 +8,9 @@ import ( "strconv" "strings" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/iface" ) const ( @@ -39,6 +40,10 @@ func newHostManager(_ *iface.WGIface) (hostManager, error) { }, nil } +func (s *systemConfigurator) supportCustomPort() bool { + return true +} + func (s *systemConfigurator) applyDNSConfig(config hostDNSConfig) error { var err error diff --git a/client/internal/dns/host_windows.go b/client/internal/dns/host_windows.go index 3c241a6c1..7d609ec04 100644 --- a/client/internal/dns/host_windows.go +++ b/client/internal/dns/host_windows.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" "golang.org/x/sys/windows/registry" + + "github.com/netbirdio/netbird/iface" ) const ( @@ -42,6 +43,10 @@ func newHostManager(wgInterface *iface.WGIface) (hostManager, error) { }, nil } +func (s *registryConfigurator) supportCustomPort() bool { + return false +} + func (r *registryConfigurator) applyDNSConfig(config hostDNSConfig) error { var err error if config.routeAll { diff --git a/client/internal/dns/network_manager_linux.go b/client/internal/dns/network_manager_linux.go index 78ea6fb7e..1867f9f50 100644 --- a/client/internal/dns/network_manager_linux.go +++ b/client/internal/dns/network_manager_linux.go @@ -11,8 +11,9 @@ import ( "github.com/godbus/dbus/v5" "github.com/hashicorp/go-version" "github.com/miekg/dns" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/iface" ) const ( @@ -88,6 +89,10 @@ func newNetworkManagerDbusConfigurator(wgInterface *iface.WGIface) (hostManager, }, nil } +func (n *networkManagerDbusConfigurator) supportCustomPort() bool { + return false +} + func (n *networkManagerDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { connSettings, configVersion, err := n.getAppliedConnectionSettings() if err != nil { diff --git a/client/internal/dns/resolvconf_linux.go b/client/internal/dns/resolvconf_linux.go index 44e68c725..374882ec2 100644 --- a/client/internal/dns/resolvconf_linux.go +++ b/client/internal/dns/resolvconf_linux.go @@ -5,8 +5,9 @@ import ( "os/exec" "strings" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/iface" ) const resolvconfCommand = "resolvconf" @@ -21,6 +22,10 @@ func newResolvConfConfigurator(wgInterface *iface.WGIface) (hostManager, error) }, nil } +func (r *resolvconf) supportCustomPort() bool { + return false +} + func (r *resolvconf) applyDNSConfig(config hostDNSConfig) error { var err error if !config.routeAll { diff --git a/client/internal/dns/server_nonandroid.go b/client/internal/dns/server_nonandroid.go index 55ba28f01..d1bf5c970 100644 --- a/client/internal/dns/server_nonandroid.go +++ b/client/internal/dns/server_nonandroid.go @@ -13,9 +13,10 @@ import ( "github.com/miekg/dns" "github.com/mitchellh/hashstructure/v2" + log "github.com/sirupsen/logrus" + nbdns "github.com/netbirdio/netbird/dns" "github.com/netbirdio/netbird/iface" - log "github.com/sirupsen/logrus" ) const ( @@ -254,7 +255,14 @@ func (s *DefaultServer) applyConfiguration(update nbdns.Config) error { s.updateLocalResolver(localRecords) s.currentConfig = dnsConfigToHostDNSConfig(update, s.runtimeIP, s.runtimePort) - if err = s.hostManager.applyDNSConfig(s.currentConfig); err != nil { + hostUpdate := s.currentConfig + if s.runtimePort != defaultPort && !s.hostManager.supportCustomPort() { + log.Warnf("the DNS manager of this peer doesn't support custom port. Disabling primary DNS setup. " + + "Learn more at: https://netbird.io/docs/how-to-guides/nameservers#local-resolver") + hostUpdate.routeAll = false + } + + if err = s.hostManager.applyDNSConfig(hostUpdate); err != nil { log.Error(err) } diff --git a/client/internal/dns/systemd_linux.go b/client/internal/dns/systemd_linux.go index 235b6c504..19776eacb 100644 --- a/client/internal/dns/systemd_linux.go +++ b/client/internal/dns/systemd_linux.go @@ -9,10 +9,11 @@ import ( "github.com/godbus/dbus/v5" "github.com/miekg/dns" - nbdns "github.com/netbirdio/netbird/dns" - "github.com/netbirdio/netbird/iface" log "github.com/sirupsen/logrus" "golang.org/x/sys/unix" + + nbdns "github.com/netbirdio/netbird/dns" + "github.com/netbirdio/netbird/iface" ) const ( @@ -75,6 +76,10 @@ func newSystemdDbusConfigurator(wgInterface *iface.WGIface) (hostManager, error) }, nil } +func (s *systemdDbusConfigurator) supportCustomPort() bool { + return true +} + func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { parsedIP, err := netip.ParseAddr(config.serverIP) if err != nil {