[英]How can I use a custom DNS server in Azure App Services with Linux?
I have a .NET Core API App running in Azure App Services using Windows, but now I want to test it using Linux. 我有一个使用Windows在Azure应用服务中运行的.NET Core API应用,但现在我想使用Linux对其进行测试。 The app uses a custom DNS Zone just to map a custom hostname to a specific IP address.
该应用程序使用自定义DNS区域仅将自定义主机名映射到特定IP地址。
To implement that in my Windows App Service I used the following Application Settings as stated in this page : WEBSITE_DNS_SERVER
and WEBSITE_ALT_DNS_SERVER
. 为了在Windows App Service中实现此目的,我使用了本页中所述的以下应用程序设置:
WEBSITE_DNS_SERVER
和WEBSITE_ALT_DNS_SERVER
。 Although it looks like a workaround, it works pretty well with Windows App Services. 尽管它看起来像是一种解决方法,但它与Windows App Services配合得很好。 But in Linux it seems to have no effect and my app is not resolving the hostname as needed.
但是在Linux中,它似乎没有任何作用,我的应用程序未根据需要解析主机名。
How can I use a custom DNS server in Azure App Service with Linux or add a custom hostname like editing the hosts file? 如何在带有Linux的Azure App Service中使用自定义DNS服务器或添加自定义主机名,例如编辑主机文件?
Unlike our App Service Windows, nameresolver.exe is not available and the Application settings for "WEBSITES_ALT_DNS" and "WEBSITES_DNS" do not populate the configuration files within the container. 与我们的App Service Windows不同,nameresolver.exe不可用,并且“ WEBSITES_ALT_DNS”和“ WEBSITES_DNS”的应用程序设置不会填充容器中的配置文件。 Below are steps are troubleshooting issues for "Alpine" based images since you don't mention if you are using a Linux container or the default Linux OS.
以下是针对基于“ Alpine”的映像进行故障排除的步骤,因为您没有提到使用的是Linux容器还是默认的Linux操作系统。
Install Bind-tools- 安装Bind-tools-
Run Nslookup- 运行Nslookup-
Once bind-tools is installed, you'll see the server that is being used. 安装bind-tools后,您将看到正在使用的服务器。 If bind-tools are not installed, the DNS server will not be shown.
如果未安装绑定工具,则不会显示DNS服务器。 Example provided below.
下面提供了示例。
9031977be93a:~# nslookup google.com Server: 127.0.0.11 Address: 127.0.0.11#53 Non-authoritative answer: Name: google.com Address: 216.58.194.174 Name: google.com Address: 2607:f8b0:4005:801::200e
Update Config file- 更新配置文件-
To use a different DNS server for testing, update the /etc/resolv.conf file and update the "nameserver" to use a different DNS server. 要使用其他DNS服务器进行测试,请更新/etc/resolv.conf文件,并更新“名称服务器”以使用其他DNS服务器。 In this example, we're using Googles DNS.
在此示例中,我们使用Google的DNS。
search reddog.microsoft.com nameserver 127.0.0.11 options timeout:1 attempts:5 ndots:0cd /etc 搜索reddog.microsoft.com名称服务器127.0.0.11选项超时:1次尝试:5次ndots:0cd / etc
search reddog.microsoft.com nameserver 8.8.8.8 options timeout:1 attempts:5 ndots:0 搜索reddog.microsoft.com名称服务器8.8.8.8选项超时:1次尝试:5次ndots:0
9031977be93a:~# nslookup google.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: google.com Address: 216.58.194.174 Name: google.com Address: 2607:f8b0:4005:804::200e
Hardcoding Hostname- 硬编码主机名-
You can also hardcode the IP address for the hostname in question for testing. 您也可以对有问题的主机名的IP地址进行硬编码以进行测试。 To do so, you'll need to update the following file.
为此,您需要更新以下文件。
127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.20.0.2 9031977be93a 10.10.10.10 www.polytechniks.com
9031977be93a:~# ping www.polytechniks.com PING www.polytechniks.com (10.10.10.10): 56 data bytes --- www.polytechniks.com ping statistics --- 8 packets transmitted, 0 packets received, 100% packet loss 9031977be93a:~# traceroute www.polytechniks.com traceroute to www.polytechniks.com (10.10.10.10), 30 hops max, 46 byte packets 1 172.20.0.1 (172.20.0.1) 0.005 ms 0.004 ms 0.004 ms
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.