The custom domain name system (DNS) feature is suitable for scenarios such as site access acceleration. This topic describes how to configure custom DNS settings for functions in the Function Compute console.

Background information

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 in Linux to query the syntax of the resolv.conf file. If a message indicating that no manual page exists is returned, install a manual page based on your Linux distribution. For example, you can run the yum install man-pages man-db command in CentOS to install a manual page. For more information, see Linux manual page.


The custom DNS feature supports only the runtimes and custom runtimes that are provided by Function Compute.


Create a function

Configure custom DNS settings

Note If you want to use the default DNS servers of Function Compute, enter the and IP addresses in the Name Servers fields.
  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where your Kubernetes cluster is deployed.
  4. On the Services page, click the target service.
  5. On the Functions page, find the function that you want to manage and click Configure in the Actions column.
  6. In the DNS Configuration section, configure the parameters and click Save. The following table describes the parameters.
    Parameter Description Example
    Name Servers The IP addresses of the DNS servers. You can add the IP addresses of one or more DNS servers.
    Search Domain The DNS search domains. You can add one or more search domains. If the accessed domain name cannot be resolved by DNS, the search domain is appended to the domain name, and then the accessed domain name is resolved again.
    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
  7. Verify whether the custom DNS settings that you configured take effect.
    1. On the details page of the function, click the Code tab.
    2. Write code in the code editor, click Deploy, and then click Test Function.
      Sample Python 3 code:
      # -*- coding: utf-8 -*-
      import logging
      import subprocess
      def handler(event, context):
        logger = logging.getLogger()
        f = open('/etc/resolv.conf')"".join(f.readlines()))
        output = subprocess.check_output(["ping", "-c", "1", ""])
        return output
    3. On the Code tab, view the execution result. In the Response section, view the content that is generated based on the resolv.conf file. In the Log Output section, view the returned IP addresses of the domain name.