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 more information, see Linux manual page.

Limits

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

Prerequisites

Create a function

Configure custom DNS settings

Note If you want to use the default DNS servers of Function Compute, enter the 100.100.2.136 and 100.100.2.138 IP addresses in the Name Servers fields.
  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services & Functions.
  3. In the top navigation bar, select a region.
  4. On the Services page, click the desired service.
  5. On the Functions page, find the function that you modify 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.
    dns-edit
    ParameterDescriptionExample
    Name ServersThe IP addresses of the DNS servers. You can add the IP addresses of one or more DNS servers.
    • 223.5.5.5
    • 223.6.6.6
    Search DomainThe 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. mydomain.com
    DNS OptionsThe 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')
        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 content that is generated based on the resolv.conf file. In the Log Output section, view the returned IP addresses of the domain name.
      result