Skip to navigation
Device policiesService policiesSet up the DNS firewall

Set up the DNS firewall

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

The DNS firewall controls which domain names your devices can resolve. You write rules that allow or deny domain names, and the emnify DNS resolver applies them when a device looks up a name. Use it to keep devices away from domains they don’t need, so a compromised device can’t reach an unknown server by name.

The DNS firewall filters DNS lookups only. It doesn’t block traffic to an IP address that a device reaches without a DNS lookup. To filter traffic by IP address, protocol, and port, set up the IP firewall.

Prerequisites

  • The DNS firewall is a subscription for your organization. To request access, contact emnify support.
  • Your devices must use the emnify DNS servers. You can’t enable the DNS firewall on a service policy that has a custom DNS server.

How the DNS firewall works

You configure the DNS firewall with two objects:

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

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

Choose a mode

The mode decides what happens to a domain name that no rule matches:

ModeNames no rule matchesUse it when
AllowlistDeniedYour devices only need a known list of domains
BlocklistAllowedYou want to block specific domains and allow everything else

In allowlist mode, your devices can resolve only the names that your rules allow. Before you enable the DNS firewall, make sure your rules cover every domain your devices need, such as your backend, time servers, and firmware update servers.

How rules are evaluated

Within a profile, the most specific rule that matches a name decides whether it’s allowed or denied:

  • A rule for the exact name wins over a wildcard rule.
  • Among wildcard rules, the one for the longest domain wins. For example, *.api.example.com wins over *.example.com for eu.api.example.com.

The order of the rules in the file doesn’t matter.

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

  • If any profile denies the name, it’s denied, even if another profile allows it.
  • If no profile denies the name and at least one allows it, it’s allowed, in both modes.
  • If no rule in any profile matches, the mode decides.

When a name is denied, the DNS resolver answers that the domain doesn’t exist (NXDOMAIN). The device gets no IP address for the name, so it can’t connect to it by name.

Write the rules

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

ACTION DOMAIN [# COMMENT]
FieldRequiredValues
ACTIONYesALLOW or DENY
DOMAINYesA domain name, such as api.example.com, or a wildcard, such as *.example.com. A wildcard can only start with *.
COMMENTNoFree text after #, at the end of a rule or on its own line

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

A wildcard matches every subdomain of a domain, but not the domain itself. For example, *.example.com matches api.example.com and eu.api.example.com, but not example.com. To match the domain and its subdomains, add a rule for each.

This example is for allowlist mode. It allows your backend and its subdomains, an MQTT broker, and a time server, and denies everything else:

# Allowlist mode: devices can resolve only these names
ALLOW example.com
ALLOW *.example.com # Backend and its subdomains
ALLOW mqtt.example.net # MQTT broker
ALLOW time.example.org # Time server

This example is for blocklist mode. It denies one domain with all its subdomains, and one single name, and allows everything else:

# Blocklist mode: devices can resolve every name except these
DENY example.net
DENY *.example.net
DENY tracker.example.org

When you write rules, keep in mind:

  • A deny in any profile is final. A DENY rule in one profile blocks the name for the whole service policy, even if another profile allows it.
  • Two rules for the same domain can’t have different actions. The Portal rejects the profile, because neither rule is more specific than the other. A second rule with the same domain and action is redundant, and the Portal shows a warning.
  • Allow every name that your devices look up. Many services use more than one domain name, for example for regional endpoints or a content delivery network. In allowlist mode, a device can’t resolve a name you didn’t allow, even if it belongs to the same service.
  • Expect cached answers. Devices keep DNS answers for a while. After you deny a name, a device can use an answer it already has until that answer expires. To apply the change sooner, reset the connectivity of the devices.

Create a DNS firewall profile

1

In Device Policies, find DNS 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.

4

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

5

Replace the default name with a name for the profile.

6

Optionally, add a description.

7

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.

8

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

Every line in the example profile is a comment, so the file has no rules. If you upload it unchanged to a service policy in allowlist mode, the DNS firewall denies every name after you enable it.

Change a DNS firewall profile

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

1

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

2

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

3

To change the rules, click the download icon next to the rules file to get the current rules.

4

Edit the file.

5

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

6

Click Save.

Assign profiles and enable the DNS firewall

You can’t turn on the DNS firewall on a service policy without an assigned profile, or on a service policy that has a custom DNS server. While the DNS firewall is on, you can’t remove the last assigned profile.

1

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

2

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

3

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

4

In Mode, select Allowlist or Blocklist.

5

Click Close.

6

Turn on the Enable DNS Firewall switch. The DNS resolver starts to apply the rules for every device with this service policy.

Disable the DNS firewall

1

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

2

In Security, turn off the Enable DNS Firewall switch. The assigned profiles and the mode stay on the service policy, but the DNS resolver stops applying them.

Track configuration changes

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

Manage the DNS firewall with the emnify REST API

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

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