Skip to main content

DNS-over-HTTPS setup (DoH domain)

We have 2 ways to create a DoH domain:

1. Using your account dashboard
  • Follow the instructions from our guide here to create a DoH URL link.
  • Transform your DoH URL link into a DoH domain.

Simply place the token number before the doh.safedns.com domain
Example: DoH URL: https://doh.safedns.com/847593758 ➡️ DoH domain: 847593758.doh.safedns.com

2. Using Python code

Using Python code allows you to quickly create DoH domains for all your policy profiles.

  1. For Reseller accounts, it is possible to use our Subscriptions API guide to automatically create all the necessary policy profiles.
  2. End-user accounts can create policies manually using the SafeDNS Dashboard interface
  3. Once the policies are created, run the Python code to generate the corresponding DoH domains.

Here is the code you need to run in an environment that supports Python:

import requests

def get_token(login, password):
 
   api_url = 'https://safedns.com/api/token/by-password/'
   try:
       response = requests.post(api_url, data={'username': login, 'password': password}, headers={'Content-Type': 'application/x-www-form-urlencoded'})
       response.raise_for_status() 
       data = response.json()
       return data.get('access') 
   except requests.exceptions.RequestException:
       return None

def generate_links(tokens):
 
   return [f"{token}.doh.safedns.com" for token in tokens if token is not None]

username = 'your_username'  # Add your actual username here
password = 'your_password'  # Add your actual password here

access_token = get_token(username, password)

if access_token:
   api_url = "https://safedns.com/dashboard/rest_api/v1/users/111841/profiles/?page=1&page_size=1000" #Replace the ID after /users/ with your actual user_id
   try:
       response = requests.get(api_url, headers={'Authorization': f'Bearer {access_token}'})
       response.raise_for_status() 
       data = response.json() 
      
       tokens = [item['token'] for item in data.get('results', []) if 'token' in item and item['token'] is not None]

       result_links = generate_links(tokens)
      
       for link in result_links:
           print(link)
   except requests.exceptions.RequestException:
       print("Error fetching data.")
else:
   print("Failed to obtain access token.")
Example of how to run the code in Google Colab:
  1. Open Google Colab.
  2. Select New Notebook.
  3. Insert the code.

    image-1727080473278.png

  4. Modify lines 18, 19, and 24 in the code:
    • Line 18: Enter your username.
    • Line 19: Enter your password.
    • Line 24: Enter your User ID (please contact technical support to obtain your User ID).
  5. Run the code

    Screenshot 2024-09-23 at 11.36.25.png

  6. After executing the code, the output will display a list of DoH domains for all your created policies.

Setting up DNS-over-HTTPS on Android

To configure DNS-over-HTTPS (DoH) on Android, follow these steps:

1. Navigate to Settings > Network & internet. (Note: on some devices - More connectivity options).
2. Select Advanced > Private DNS. (Note: On some devices it is under Advanced or More options).
photo_2024-09-23 11.51.17.jpeg
3. Select the Private DNS provider hostname option.
photo_2024-09-23 11.51.13.jpeg

4. Add SafeDNS DoH domain - (Example: 837527453.doh.safedns.com) and select Save.
photo_2024-09-23 11.51.20.jpeg