diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 880fc04bc..13efeca21 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -46,6 +46,7 @@ import ( "tailscale.com/types/opt" "tailscale.com/types/persist" "tailscale.com/types/wgkey" + "tailscale.com/util/dnsname" "tailscale.com/util/systemd" "tailscale.com/version" "tailscale.com/wgengine/filter" @@ -179,6 +180,7 @@ var osVersion func() string // non-nil on some platforms func NewHostinfo() *tailcfg.Hostinfo { hostname, _ := os.Hostname() + hostname = dnsname.FirstLabel(hostname) var osv string if osVersion != nil { osv = osVersion() diff --git a/util/dnsname/dnsname.go b/util/dnsname/dnsname.go index 4a0cf8eaa..56ee0baea 100644 --- a/util/dnsname/dnsname.go +++ b/util/dnsname/dnsname.go @@ -223,6 +223,14 @@ func NumLabels(hostname string) int { return strings.Count(hostname, ".") } +// FirstLabel returns the first DNS label of hostname. +func FirstLabel(hostname string) string { + if i := strings.IndexByte(hostname, '.'); i != -1 { + return hostname[:i] + } + return hostname +} + var separators = map[byte]bool{ ' ': true, '.': true,