Skip to navigation
Device policiesService policiesSet up the IP firewall

Set up the IP firewall

Beta

Your role needs permission to manage IP firewall profiles and to assign them to service policies.

The IP firewall controls which destinations your devices can reach. You write rules that allow or deny traffic by IP address, protocol, and port, and the emnify network enforces them before the traffic leaves the network. Use it to restrict devices to the backends they need, so a compromised or misconfigured device can’t reach anything else.

The IP firewall filters outbound traffic only, which is traffic that your devices send.

Prerequisites

The IP firewall is a subscription for your organization. To request access, contact emnify support.

If the subscription ends, your IP firewall profiles stay in your organization, but the network stops enforcing them until you subscribe again.

How the IP firewall works

You configure the IP firewall with two objects:

  • An IP firewall profile is a named list of rules. You can reuse one profile on several service policies.
  • A service policy applies IP firewall profiles to its devices. You can assign up to 10 profiles to one service policy, and every device with that service policy uses them.

The IP firewall applies to a device only when its service policy has at least one IP firewall profile assigned and the IP firewall is enabled on that service policy. Otherwise, the device’s traffic isn’t filtered.

How rules are evaluated

The network checks the rules in a profile from top to bottom. The first rule that matches the traffic decides whether it’s allowed or denied, and the rules after it are ignored.

When a service policy has several IP firewall profiles, the network checks each profile on its own:

  • If any profile denies the traffic, it’s denied, even if another profile allows it.
  • If no profile denies the traffic and at least one allows it, it’s allowed.
  • If no rule in any profile matches, the traffic is denied.

The network drops denied traffic without sending a response to the device. Applications on the device see a connection timeout, not a rejected connection.

Traffic that no rule matches is denied. Before you enable the IP firewall, make sure your rules allow everything your devices need, including DNS. Otherwise, your devices can’t resolve hostnames.

Write the rules

An IP firewall profile is a plain text file with one rule per line. Each rule has this format:

ACTION PROTOCOL DIRECTION ADDRESS... [PORTS:...] [# COMMENT]
FieldRequiredValues
ACTIONYesALLOW or DENY
PROTOCOLYesTCP, UDP, ICMP, or ANY
DIRECTIONYesOUT
ADDRESSYesThe destination, as one or more of IP:<address> for a single IPv4 address or CIDR:<address>/<prefix> for a range, or ANY for every destination. Separate several destinations with spaces
PORTSNoPORTS:443 for one port, PORTS:80,443 for several, PORTS:10000-10100 for a range, or PORTS:ANY. Applies to TCP and UDP only. Without it, the rule matches every port
COMMENTNoFree text after #, at the end of a rule or on its own line

Keywords aren’t case-sensitive, and empty lines are ignored. A profile can have up to 100 rules, an organization can have up to 100 IP firewall profiles, and a service policy can have up to 10 of them assigned.

This example allows DNS, MQTT to one broker, and HTTPS to a range of cloud APIs. It needs no final deny rule, because the IP firewall denies traffic that no rule matches:

ALLOW UDP OUT IP:8.8.8.8 IP:8.8.4.4 PORTS:53 # DNS
ALLOW TCP OUT IP:203.0.113.10 PORTS:8883 # MQTT to the broker
ALLOW TCP OUT CIDR:52.95.0.0/16 PORTS:443 # HTTPS to cloud APIs

When you write rules, keep in mind:

  • Put specific rules before broad ones. A broad rule such as DENY TCP OUT ANY PORTS:443 placed first matches all HTTPS traffic, so a later rule that allows one HTTPS backend never applies.
  • Allow your DNS servers. By default, emnify routes DNS queries to Google’s public DNS at 8.8.8.8 and 8.8.4.4. If you use your own DNS servers, allow those addresses instead.
  • Allow your Cloud Connect ranges. The IP firewall also filters traffic to private addresses. If your devices reach your backend through Cloud Connect, add a rule such as ALLOW TCP OUT CIDR:<your-cloud-connect-range> PORTS:ANY.
  • Allow device-to-device traffic. The IP firewall also filters traffic between your devices. If you enable device-to-device communication, add a rule that allows your devices’ IP address range.
  • Avoid ALLOW ANY OUT ANY. It allows all outbound traffic, so the profile doesn’t restrict anything.
  • Don’t add a catch-all DENY ANY OUT ANY. A deny in any profile is final, so a catch-all deny in one profile blocks everything that the other profiles on the same service policy allow. Traffic that no rule matches is already denied.

Create an IP firewall profile

1

In Device Policies, find IP Firewall profiles in the Security Policies section.

2

Click Actions > Download example profile. The file explains the rule format and contains example rules as comments.

3

Edit the file and add your rules. Every line in the example profile is a comment, so the file has no rules. If you upload it unchanged, the profile denies all outbound traffic after you enable the IP firewall.

4

Click Actions > New IP Firewall Profile. The Add IP firewall profile dialog opens.

5

Replace the default name with a name for the profile. Optionally, add a description.

6

In Rules file, upload your file: drag it into the box, or click the link in the box and select it. The file must be a .txt file.

7

Click Save. The Portal validates the rules and shows any problems before it saves the profile.

Change an IP firewall profile

Changes to a profile apply to every service policy it’s assigned to.

1

In IP Firewall profiles, open the options menu in the profile’s row and select Profile details. The IP Firewall profile details dialog opens.

2

To change the name or description, select the edit icon next to it and enter the new text.

3

To change the rules, select the download icon next to the rules file to get the current rules, and edit the file.

4

Select the replace icon next to the rules file, and select your updated file.

5

Click Save.

Assign profiles and enable the IP firewall

1

In Service Policies, choose the policy you want to update and expand the policy details.

2

In Security, select the edit icon in the Enable IP Firewall row. If no profile is assigned yet, you can also click Attach profiles. The IP firewall profiles dialog opens.

3

In Choose profile, select an IP firewall profile, and select the check mark to add it. To add more profiles, repeat this step.

4

Click Close.

5

Turn on the Enable IP Firewall switch. The network starts to enforce the rules for every device with this service policy.

You can’t turn on the IP firewall on a service policy without an assigned profile. While the IP firewall is on, you can’t remove the last assigned profile.

Disable the IP firewall

1

In Service Policies, choose the policy you want to update and expand the policy details.

2

In Security, turn off the Enable IP Firewall switch. The assigned profiles stay on the service policy, but the network stops enforcing them.

Track configuration changes

Assigning or removing an IP firewall profile and enabling or disabling the IP firewall each create a Policy management event. Use these events to audit when the configuration changed.

Manage the IP firewall with the emnify REST API

You can also manage IP firewall profiles and their assignment with the emnify REST API. Use the dry_run parameter to validate rules without saving them.

For details, see Create an IP firewall profile and Replace IP firewall profiles on a service profile in the API reference.