# Display hostname instead of 127.0.0.1

**URL:** <https://discuss.elastic.co/t/display-hostname-instead-of-127-0-0-1/159246>\
**Category:** Logstash\
**Created:** [December 3, 2018, 9:03pm UTC](https://discuss.elastic.co/t/display-hostname-instead-of-127-0-0-1/159246 "2018-12-03T21:03:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![runiter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runiter/32/38392_2.png) [@runiter](https://discuss.elastic.co/u/runiter)\
**Post date:** [December 3, 2018, 9:03pm UTC](https://discuss.elastic.co/t/display-hostname-instead-of-127-0-0-1/159246/1 "2018-12-03T21:03:29Z")

</div>

Currently the "host" field in our logs always is "127.0.0.1". We want it to be either the "hostname" or the actual ip of the current machine. How can I achieve that?

---

<div class="post-metadata">

**Author:** ![runiter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runiter/32/38392_2.png) [@runiter](https://discuss.elastic.co/u/runiter)\
**Post date:** [December 4, 2018, 9:49pm UTC](https://discuss.elastic.co/t/display-hostname-instead-of-127-0-0-1/159246/2 "2018-12-04T21:49:05Z")

</div>

Found the solution. The only way I could get it to work was by using ruby.  
It's quite easy actually. Just add the following code as a filter:

```
filter {
  ruby {
    init => "require 'socket'"
    code => "event.set('host', Socket.gethostname)"
  }
}
```

---

<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:** [January 1, 2019, 9:49pm UTC](https://discuss.elastic.co/t/display-hostname-instead-of-127-0-0-1/159246/3 "2019-01-01T21:49:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
