# How to match IP address to hostname (dns filter)

**URL:** <https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988>\
**Category:** Logstash\
**Created:** [August 31, 2020, 4:53pm UTC](https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988 "2020-08-31T16:53:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lilyyy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lilyyy/32/51129_2.png) [@lilyyy](https://discuss.elastic.co/u/lilyyy)\
**Post date:** [August 31, 2020, 4:53pm UTC](https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988/1 "2020-08-31T16:53:38Z")

</div>

Hi all,  
I'm trying to match the IP address to hostname.  
Data is json file and it is originally pcap file.

I used dns filter in logstash.conf file.

```
 mutate {
  add_field => { "src_hostname" => "%{[layers][ip][ip_ip_src]}" }
  add_field => { "dst_hostname" => "%{[layers][ip][ip_ip_dst]}" }
  }
 dns {
  reverse => ["src_hostname","dst_hostname"]
  action => "replace"
  add_tag => ["dns_lookup"]
   }

```

As a result, fields(src\_hostname, dst\_hostname) are created but the values are just ip address.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/2/e20b573d316527787de3ca154c1941b61fe21eda.png)

How can I match the IP address to host name?

Thanks.

---

<div class="post-metadata">

**Author:** ![kavierkoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kavierkoo/32/86555_2.png) [@kavierkoo](https://discuss.elastic.co/u/kavierkoo)\
**Post date:** [September 21, 2020, 4:00pm UTC](https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988/2 "2020-09-21T16:00:53Z")

</div>

Hi,

I have the same issue too,  
after using nslookup to find dhcp/dns server,  
I managed to solve mine by specifying nameserver.

```auto
 mutate {
     add_field => { "Hostname" => "%{Client}" }
 }

dns {
  nameserver => {
       address => ["10.0.0.3"]
     }     
   reverse => ["Hostname"]
   action => "replace"
}

```

Hope this helps your issue.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 21, 2020, 4:26pm UTC](https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988/3 "2020-09-21T16:26:30Z")

</div>

A dns filter will return as soon as an element in the array fails to resolve. An [issue](https://github.com/logstash-plugins/logstash-filter-dns/issues/5) about that has been open for years. That means that if src\_hostname fails to resolve (perhaps because it is a reserved address) it will never attempt to resolve dst\_hostname.

If you split the dns filter into two dns filters does dst\_hostname resolve?

---

<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:** [October 19, 2020, 4:26pm UTC](https://discuss.elastic.co/t/how-to-match-ip-address-to-hostname-dns-filter/246988/4 "2020-10-19T16:26:38Z")

</div>

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