# Mask the IP address using custom grok pattern

**URL:** <https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293>\
**Category:** Logstash\
**Created:** [December 18, 2018, 9:43am UTC](https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293 "2018-12-18T09:43:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manjushree\_Gokhale](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Manjushree\_Gokhale](https://discuss.elastic.co/u/Manjushree_Gokhale)\
**Post date:** [December 18, 2018, 9:43am UTC](https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293/1 "2018-12-18T09:43:13Z")

</div>

Hi,

I am new to Logstash and grok and want to mask/ change first octets of ip addresses in my logs for security purpose. but unable to create a grok pattern which will work for the situation. I am getting IP from logs message but i am not able to think forward.

---

<div class="post-metadata">

**Author:** ![bigphil](https://avatars.discourse-cdn.com/v4/letter/b/65b543/32.png) [@bigphil](https://discuss.elastic.co/u/bigphil)\
**Post date:** [December 18, 2018, 3:54pm UTC](https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293/2 "2018-12-18T15:54:53Z")

</div>

After you've parsed the message with grok, use the [Mutate gsub](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-gsub) filter to replace the first octet.

---

<div class="post-metadata">

**Author:** ![Manjushree\_Gokhale](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Manjushree\_Gokhale](https://discuss.elastic.co/u/Manjushree_Gokhale)\
**Post date:** [December 20, 2018, 5:53am UTC](https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293/3 "2018-12-20T05:53:10Z")

</div>

Hi,

I tried the same it works for one ip but when i want the same for whole message which contains 2, 3 ips i am unable to generate a regex which will help.

right now i have generated below mentioned regex for gsub which is working fine for one ip.  
gsub =\> ["client\_ip", "(.\d+){1}$", ".XXX"]

---

<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 17, 2019, 5:53am UTC](https://discuss.elastic.co/t/mask-the-ip-address-using-custom-grok-pattern/161293/4 "2019-01-17T05:53:15Z")

</div>

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