All Products
Search
Document Center

Function Compute:Configure custom DNS

Last Updated:Dec 08, 2025

You can configure custom Domain Name System (DNS) to implement specific features, such as access acceleration. This topic describes how to configure a custom DNS for a function in the Function Compute console.

Background

The resolv.conf file is a system configuration file. After you configure custom DNS settings, the original resolv.conf file is overwritten. You can run the man 5 resolver command on a Linux machine to query the format and settings of the resolv.conf file. If no man pages (short for reference manual pages) are returned, use the current Linux distribution for installation. For more information, visit Linux manual page.

Limits

The custom DNS feature supports only the built-in runtimes of Function Compute and custom runtimes.

Before you start

Create a function

Configure DNS settings

Note

If you want to use the default DNS server in Function Compute, specify 100.100.2.136 and 100.100.2.138 as the default IP addresses in the Name Servers field.

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  3. On the function details page, click the Configurations tab.

  4. In the left-side navigation pane, click the DNS tab. On the DNS tab, click Modify. In the DNS panel, configure the following parameters as prompted and click OK.

    Parameter

    Description

    Example

    Name Servers

    The IP address of the DNS server. You can specify one or more IP addresses.

    • 223.5.5.5

    • 223.6.6.6

    Search Domain

    The search domain of the DNS server. You can specify one or more search domains. If the DNS server cannot resolve a domain name, search domains are appended to the domain name, and then the DNS server resolves the domain name again.

    example.com

    DNS Options

    The configuration items in the resolv.conf file. Each item corresponds to a key-value pair in the key:value format, in which the key is required.

    attempts:1

  5. Verify whether the custom DNS settings that you configured take effect.

    1. On the function details page, click the Code tab.

    2. Write code in the code editor, click Deploy, and then click Test Function.

      Sample code (Python 3):

      # -*- coding: utf-8 -*-
      import logging
      import subprocess
      
      def handler(event, context):
        logger = logging.getLogger()
        f = open('/etc/resolv.conf')
        logger.info("".join(f.readlines()))
        f.close()
        output = subprocess.check_output(["ping", "-c", "1", "www.aliyun.com"])
        return output
    3. On the Code tab, view the execution result. In the Response section, view the corresponding content generated by resolv.conf. In the Log Output section, view the IP address of the returned domain name.