---
schema_version: "1"
id: 4758b88a7e493485ed69121cbcdae3cc296b101653693b2a0d301b90ee0d020c
title: Filter IP Addresses
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.8/policies-pdk-configure-features-ip-filter.md
canonical_url: https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features-ip-filter
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a1c93a09ac15c56f71513b6b4ff1d3029e4fa8bff9aa3766d1a69be584d3fa35
description: MuleSoft Documentation Site
release: "1.8"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.8
---

# Filter IP Addresses

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Use the Omni Gateway Policy Development Kit (PDK) IP Filter to filter requests based on IP
addresses. Create allowlists or blocklists using IPv4/IPv6 addresses and CIDR ranges to evaluate
incoming requests IPs.

Import `IpFilter` from the `pdk` crate, then create an IP filter to either allow or block specific
IPs:

```Rust
use pdk::ip_filter::IpFilter;

// Create an allowlist filter (only specified IPs are permitted)
let ip_filter = IpFilter::allow(&["192.168.1.0/24", "10.0.0.1"])?;

// Create a blocklist filter (specified IPs are denied)
let ip_filter = IpFilter::block(&["192.168.1.0/24", "10.0.0.1"])?;
```

The `IpFilter` accepts an array of strings and supports:

- Both IPv4 and IPv6 addresses.

- Individual IPs, for example: `10.0.0.1`.

- Classless Inter-Domain Routing (CIDR) notation for IP ranges. For example: `192.168.1.0/24`,
  `10.0.0.0/8`.

After creating the filter, use the `is_allowed` method to check if an IP is permitted:

```Rust
// Check if an IP is allowed
if ip_filter.is_allowed("192.168.1.100") {
    // IP is permitted, continue processing
    Flow::Continue(())
} else {
    // IP is blocked, return forbidden response
    Flow::Break(Response::new(403).with_body("Forbidden"))
}
```

## IP Filter Configuration Examples

PDK provides the
[IP Filter Example policy](https://github.com/mulesoft/pdk-custom-policy-examples/tree/1.8.0/ip-filter)
to demonstrate how to implement IP-based access control in Rust code.

Within the example policy, see these code sections for additional configuration details:

- [Configure an IP filter](https://github.com/mulesoft/pdk-custom-policy-examples/blob/1.8.0/ip-filter/src/lib.rs#L41-L65)

- [Extract client IP from request headers](https://github.com/mulesoft/pdk-custom-policy-examples/blob/1.8.0/ip-filter/src/lib.rs#L18-L22)

- [Validate if an IP is permitted](https://github.com/mulesoft/pdk-custom-policy-examples/blob/1.8.0/ip-filter/src/lib.rs#L24-L34)

## See Also

- [Custom Policy Examples](https://docs.mulesoft.com/pdk/1.8/policies-pdk-policy-templates)
