# Logstash CIDR Plugin not working

**URL:** <https://discuss.elastic.co/t/logstash-cidr-plugin-not-working/286267>\
**Category:** Logstash\
**Created:** [October 8, 2021, 4:57pm UTC](https://discuss.elastic.co/t/logstash-cidr-plugin-not-working/286267 "2021-10-08T16:57:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrodriguez](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@mrodriguez](https://discuss.elastic.co/u/mrodriguez)\
**Post date:** [October 8, 2021, 4:57pm UTC](https://discuss.elastic.co/t/logstash-cidr-plugin-not-working/286267/1 "2021-10-08T16:57:51Z")

</div>

Hi, I need to filter events by IP addresses. I would like to use CIDR plugin but it is not working for me.

This is my code:

```auto
filter {
	    
if [type] == "mytype" {
 kv{}
	 cidr{
	  address => ["%{srcip}"]
	  network => ["10.1.0.0/16"]
	  add_tag => ["mytag"]
    }
	if "mytag" not in [tags]{
	drop {}
}
}
}
output{
if [type] == "mytype"{
udp {
                host => "1.1.1.1"
                port => 514
		codec => line { format => "%{message}" }
		id => "myid"
        } 
}
}

```

This is a piece of a log:

`eventtime=165646546546 tz=\"+0200\" srcip=10.1.139.27 srcport=10000`

Unfortunally It looks like there is not a match in the filter and anything is sent to the output.

Can you help me?

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [October 18, 2021, 2:25pm UTC](https://discuss.elastic.co/t/logstash-cidr-plugin-not-working/286267/2 "2021-10-18T14:25:28Z")

</div>

I recommend removing all conditional statements

> if [type] == "mytype" {

and

> if "mytag" not in [tags]{

and send everything to a log file using the `stdout{}` output filter.  
Break it down piece by piece and see where the problems comes up.

---

<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 15, 2021, 2:25pm UTC](https://discuss.elastic.co/t/logstash-cidr-plugin-not-working/286267/3 "2021-11-15T14:25:42Z")

</div>

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