# DNS filter, how to save IP to a separate field

**URL:** <https://discuss.elastic.co/t/dns-filter-how-to-save-ip-to-a-separate-field/286391>\
**Category:** Logstash\
**Created:** [October 11, 2021, 4:31pm UTC](https://discuss.elastic.co/t/dns-filter-how-to-save-ip-to-a-separate-field/286391 "2021-10-11T16:31:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohsin106](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohsin106/32/65203_2.png) [@mohsin106](https://discuss.elastic.co/u/mohsin106)\
**Post date:** [October 11, 2021, 4:31pm UTC](https://discuss.elastic.co/t/dns-filter-how-to-save-ip-to-a-separate-field/286391/1 "2021-10-11T16:31:28Z")

</div>

Hi,

I'm using the DNS filter in my Logstash conf and I would like to store the IP address that the filter is resolving to a separate field. I tried using the add\_field parameter but its not working. I end up storing the FQDN, IP in both the device and IP fields. Using `action => "replace"` has same effect.

```auto
 dns {
        resolve => ["device"]
        add_field => { "ip" => "%{device}"}
    }

```

---

<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:** [October 11, 2021, 5:06pm UTC](https://discuss.elastic.co/t/dns-filter-how-to-save-ip-to-a-separate-field/286391/2 "2021-10-11T17:06:28Z")

</div>

The dns filter unconditionally modifies the source field by either replacing it (action =\> replace) or converting it to an array and appending to it (action =\> append).

If you want the result in a separate field then you can do it using

```
add_field => { "ip" => "%{[device][1]}" }

```

then a separate mutate to remove the second entry from the array

```
mutate { replace => { "device" => "%{[device][0]}" } }
```

---

<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:** [November 8, 2021, 5:06pm UTC](https://discuss.elastic.co/t/dns-filter-how-to-save-ip-to-a-separate-field/286391/3 "2021-11-08T17:06:32Z")

</div>

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