Configure DNS settings
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.
This guide uses the Postman API platform 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 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 in the emnify Portal documentation.
Alternatively, you can use the Create DNS Config 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:
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 and make sure there’s a non-breaking space between Bearer and the token value.
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 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:
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 and make sure there’s a non-breaking space between Bearer and the token value.
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 API call or create a one with the Create Service Profile API call.
Here is an example showing how to update your Service Profile with your custom DNS in Postman:
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 and make sure there’s a non-breaking space between Bearer and the token value.
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 in the emnify Portal documentation.
Alternatively, you can use the Delete DNS Config 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:
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 and make sure there’s a non-breaking space between Bearer and the token value.
A 204 NO CONTENT response status indicates that the DNS configuration was successfully deleted.
A DNS configuration can’t be deleted if it’s in use by at least one service profile.