# Mac hostname showing as 'localhost'

**URL:** <https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878>\
**Category:** Beats\
**Created:** [May 1, 2016, 2:50am UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878 "2016-05-01T02:50:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DPattee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpattee/32/37772_2.png) [@DPattee](https://discuss.elastic.co/u/DPattee)\
**Post date:** [May 1, 2016, 2:50am UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/1 "2016-05-01T02:50:18Z")

</div>

Two Mac OS X machines set up to report statistics via TopBeat 1.2.1 (amd64).  
One of those machines is the one that Elastic runs on.

Same topbeat config file on both machines.  
The elastic search: hosts: line is set to the ip address ([http://nn.nn.nn.nn:9200](http://nn.nn.nn.nn:9200)), neither is using the default "localhost" option.  
The shipper: name: line is left commented out so that each machine should automatically report the hostname.

One machine, the remote one running OS X 10.11.4, correctly reports the beat.hostname and [beat.name](http://beat.name) as "Foo.local"

The other machine, the one where Elastic is running under OS X 10.10.5, incorrectly reports both of those as "localhost"

Running the hostname command on both machines correctly prints out their names. (i.e. Foo.local and Bar.local)

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [May 2, 2016, 1:45pm UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/2 "2016-05-02T13:45:08Z")

</div>

On OSX (and all BSD platforms), Golang reports the hostname using the `sysctl kern.hostname` value. So check the output of that command.

Reference: [https://golang.org/src/os/sys\_bsd.go](https://golang.org/src/os/sys_bsd.go)

---

<div class="post-metadata">

**Author:** ![DPattee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpattee/32/37772_2.png) [@DPattee](https://discuss.elastic.co/u/DPattee)\
**Post date:** [May 3, 2016, 2:44am UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/3 "2016-05-03T02:44:31Z")

</div>

Just verified - that command also shows the correct information on both the 10.11 and 10.10 systems.

( the same data as bin/hostname -f, i.e. Foo.local, and Bar.local)

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [May 3, 2016, 4:17am UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/4 "2016-05-03T04:17:02Z")

</div>

Maybe you could so a simple test with just Golang on your machine. I can't come up with a reason why `beat.hostname == localhost`.

```auto
macbook13:tmp akroh$ go version
go version go1.6.2 darwin/amd64
macbook13:tmp akroh$ sysctl kern.hostname
kern.hostname: macbook13.company.com
macbook13:tmp akroh$ cat main.go
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println(os.Hostname())
}
macbook13:tmp akroh$ go run main.go
macbook13.company.com <nil>

```

As you can see on this [line](https://github.com/elastic/beats/blob/57477cf12ef53f0fcdc33757197fa7243bdd2584/libbeat/publisher/publish.go#L283-L283) the publisher.hostname is being set to the value of `os.Hostname()`.

---

<div class="post-metadata">

**Author:** ![DPattee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dpattee/32/37772_2.png) [@DPattee](https://discuss.elastic.co/u/DPattee)\
**Post date:** [May 5, 2016, 3:57am UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/5 "2016-05-05T03:57:14Z")

</div>

It seems the problem is a bit more insidious than I expected.

hostname, sysctl kern.hostname, and the Go function os.Hostname all return the correct results when run from the command line. Running it just as the logged in user or via sudo.

Topbeat also post the correct beat.hostname when run from the command line.

Run topbeat as a daemon at startup as root with the same command line parameters / config file? You start getting the 'localhost' results.

Until... you ssh in to the box, sudo kill and allow launchd to automatically restart the process (have KeepAlive in your plist) at which point it starts reporting the correct machine name.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 9:52pm UTC](https://discuss.elastic.co/t/mac-hostname-showing-as-localhost/48878/6 "2017-07-05T21:52:21Z")

</div>


