You can use Custom DNS for scenarios such as accelerating site access.
Configuring custom DNS overwrites the/etc/resolv.conffile on the function instance. To learn about the resolv.conf format, runman 5 resolveron a Linux system, or see the Linux manual page.
Prerequisites
Before you begin, ensure that you have:
A function created in Function Compute (Custom Image functions are not supported; GPU-accelerated functions are not supported)
Configure DNS settings
Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Function.
In the top navigation bar, select a region. On the Function page, click the target function.
On the function details page, click the Configuration tab. To the right of Advanced Settings, click Modify.
In the Advanced Settings panel, locate the DNS section and configure the following parameters:
Parameter Description Example Name servers IP addresses of the DNS servers. Add multiple addresses as needed. To use the default Function Compute DNS servers, add 100.100.2.136and100.100.2.138.223.5.5.5,223.6.6.6Search domain DNS search domains. Add multiple domains as needed. When a domain name fails to resolve, the system appends each search domain in order and retries the query. example.comDNS options Additional resolver options in key:valueformat. The key is required.attempts:1Click Deploy.
Verify the configuration
After deploying, confirm that your custom DNS settings are active by running a test function.
On the function details page, click the Code tab.
In the code editor, paste the following sample code:
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 outputClick Deploy, then click Test Function.
Review the results:
Response: view the content generated for resolv.conf.
Log Output: view the IP address of the returned domain name.