Set up the IP firewall
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:
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:
When you write rules, keep in mind:
- Put specific rules before broad ones.
A broad rule such as
DENY TCP OUT ANY PORTS:443placed 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.8and8.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
In Device Policies, find IP Firewall profiles in the Security Policies section.
Click Actions > Download example profile. The file explains the rule format and contains example rules as comments.
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.
Change an IP firewall profile
Changes to a profile apply to every service policy it’s assigned to.
In IP Firewall profiles, open the options menu in the profile’s row and select Profile details. The IP Firewall profile details dialog opens.
Assign profiles and enable the IP firewall
In Service Policies, choose the policy you want to update and expand the policy details.
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.
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
In Service Policies, choose the policy you want to update and expand the policy details.
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.