> This page is for Developers.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emnify.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emnify.com/_mcp/server.

> Configure custom DNS settings with primary and secondary nameservers for device networking using the API.

You can specify a DNS configuration using the emnify REST API.
This allows you to specify `primary` and `secondary` nameservers for the DNS resolution of device networking.

DNS changes are instantly applied to any new PDP context.
Devices that are already connected with established PDP contexts continue to use the previous nameserver configuration until the next time they reconnect.

> **Note**
>
> This guide uses the [Postman API platform](https://quickstarts.postman.com/) for example purposes.
> Each time you use the emnify REST API, you must authenticate in Postman.
>
> For more information, see [How to use the REST API via Postman](https://www.emnify.com/developer-blog/postman-emnify-api) on the emnify Developer Blog.

## Create a new DNS configuration

You can create a new custom DNS in the emnify Portal under **Device Policies**.
For step-by-step instructions, see [Add a custom DNS](/portal/how-tos/configure-dns-settings#add-a-custom-dns) in the emnify Portal documentation.

Alternatively, you can use the [Create DNS Config](/developers/api/service-lookups-and-configuration/dns-post) API call.

To create a new request in Postman, click **+New** in the upper left corner.
Name the request *Create DNS Config* and add it to a new collection called *DNS*.

Then follow these steps to set up your request:

Select the **POST** HTTP method.

Set the request URL as **`https://cdn.emnify.net/api/v1/dns`**

Navigate to the **Headers** tab.
Insert `Content-Type` and `Authorization` as **Keys** and add the respective **Values** `application/json` and `Bearer TOKEN`.
Replace `TOKEN` with your [`auth_token`](/developers/auth/application-tokens) and make sure there's a non-breaking space between `Bearer` and the token value.

Go to the **Body** tab and select **raw**.
Make sure the format is set to **JSON**.
Then, to configure OpenDNS, for example, use the following:

```json
{
  "primary": "208.67.222.222",
  "secondary": "208.67.220.220",
  "ip_address_version": 4
}
```

To complete the request, click **Send**.

> **Success**
>
> A `201 CREATED` response status indicates that the DNS configuration was successfully created.

## Find the DNS configuration ID

Once you've created a new DNS configuration, you can find it using the [List DNS Configs](/developers/api/service-lookups-and-configuration/dns-get) API call.

Click **+New** in the upper left corner to create a new request in Postman.
Name the request *List DNS Configs* and add it to your *DNS* collection.

Then follow these steps to set up your request:

Select the **GET** HTTP method.

Set the request URL as `https://cdn.emnify.net/api/v1/dns`

Navigate to the **Headers** tab.
Insert `Content-Type` and `Authorization` as **Keys** and add the respective **Values** `application/json` and `Bearer TOKEN`.
Replace `TOKEN` with your [`auth_token`](/developers/auth/application-tokens) and make sure there's a non-breaking space between `Bearer` and the token value.

To complete the request, click **Send**.

> **Check**
>
> In the response body, you can find the ID of your new DNS configuration.

## Update or create a new Service Profile with the DNS configuration ID

You can use the DNS configuration ID to update an existing service profile with the [Update Service Profile](/developers/api/service-profiles/service-profile-by-profile-id-patch) API call or create a one with the [Create Service Profile](/developers/api/service-profiles/service-profile-post) API call.

Here is an example showing how to update your Service Profile with your custom DNS in Postman:

Click **+New** to create a new request.

Select the **PATCH** HTTP method.

Set the request URL as `https://cdn.emnify.net/api/v1/service_profile/{profile_id}`, replacing `{profile_id}` with the service profile ID.

Navigate to the **Headers** tab.
Insert `Content-Type` and `Authorization` as **Keys** and add the respective **Values** `application/json` and `Bearer TOKEN`.
Replace `TOKEN` with your [`auth_token`](/developers/auth/application-tokens) and make sure there's a non-breaking space between `Bearer` and the token value.

Go to the **Body** tab and select **raw**.
Make sure the format is set to **JSON**.
Then, provide a DNS object, replacing `1234` with your DNS configuration ID:

```json {3}
{
  "dns": {
    "id": 1234
  }
}
```

To complete the request, click **Send**.

> **Success**
>
> A `201 CREATED` response status indicates that the service profile was successfully updated.

## Delete a DNS configuration

You can delete a DNS configuration in the emnify Portal under **Device Policies**.
For step-by-step instructions, see [Delete a custom DNS](/portal/how-tos/configure-dns-settings#delete-a-custom-dns) in the emnify Portal documentation.

Alternatively, you can use the [Delete DNS Config](/developers/api/service-lookups-and-configuration/dns-by-id-delete) API call.

Click **+New** in the upper left corner to create a new request in Postman.
Name the request *Delete DNS Config* and add it to your *DNS* collection.

Then follow these steps to set up your request:

Select the **DELETE** HTTP method.

Set the request URL as **`https://cdn.emnify.net/api/v1/dns/{dns_id}`**, replacing `{dns_id}` with the ID of the DNS configuration you want to delete.

Navigate to the **Headers** tab.
Insert `Content-Type` and `Authorization` as **Keys** and add the respective **Values** `application/json` and `Bearer TOKEN`.
Replace `TOKEN` with your [`auth_token`](/developers/auth/application-tokens) and make sure there's a non-breaking space between `Bearer` and the token value.

To complete the request, click **Send**.

> **Success**
>
> A `204 NO CONTENT` response status indicates that the DNS configuration was successfully deleted.

> **Warning**
>
> A DNS configuration can't be deleted if it's in use by at least one service profile.