简体   繁体   English

如何在带有Linux的Azure App Services中使用自定义DNS服务器?

[英]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_SERVERWEBSITE_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-

  1. apk update APK更新
  2. apk add bind-tools apk添加绑定工具

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。

  1. vi /etc/resolv.conf vi /etc/resolv.conf
  2. By default, the following will be in the resolv.conf file. 默认情况下,以下内容将位于resolv.conf文件中。

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

  1. If you're not familiar with "vi", press "i" on your keyboard to begin editing the file. 如果您不熟悉“ vi”,请按键盘上的“ i”以开始编辑文件。
  2. Once you're done, press "esc" and ":wq!" 完成后,按“ esc”和“:wq!”。 then enter. 然后输入。

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

  1. Running Nslookup again, you'll see the new nameserver being used. 再次运行Nslookup,您将看到正在使用的新名称服务器。

 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. 为此,您需要更新以下文件。

  1. vi /etc/hosts vi / etc / hosts
  2. Add the IP address that you would like the DNS to point to. 添加您想要DNS指向的IP地址。 In this example, I'm changing the IP for my custom domain. 在此示例中,我将更改自定义域的IP。

 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 

  1. Save the changes and use "ping" or "traceroute" to see the IP being used. 保存更改并使用“ ping”或“ traceroute”查看正在使用的IP。 NOTE: Nslookup does NOT use the /etc/hosts file so you will still see the IP address associated with the DNS. 注意:Nslookup不使用/ etc / hosts文件,因此您仍然会看到与DNS关联的IP地址。

 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.

相关问题 如何通过 ssh 进入 Azure 上的“Web App On Linux”docker 容器? - How can I ssh into “Web App On Linux” docker container on Azure? 如何为资源管理器VM使用Azure提供的DNS? - How can I use Azure-provided DNS for Resource Manager VMs? 如何在 Azure 门户中为 Azure Linux Functions 使用自定义映像? - How to use custom image for Azure Linux Functions in Azure Portal? 我可以使用puppet停止linux服务器上的服务吗? - Can I use puppet to stop services on linux servers? 我可以坚持使用 nginx 中的 server_name 指令,还是我还需要在 linux 中设置 DNS? - Can I stick with server_name directive from nginx or do I still need to set DNS in linux? 服务器 Linux DNS - Server Linux DNS 我怎样才能让python程序检查linux服务 - How can i make the python program to check linux services 我可以使用 Azure Function 来自动执行 linux 任务吗 - Can I use Azure Function to automate linux tasks 如何在 linux 上实现自定义 iNode? - How can I implement a custom iNode on linux? 使用Google DNS服务作为内部linux BIND9 DNS服务器的辅助/从属 - Use Google DNS service as a secondary/slave to an internal linux BIND9 DNS server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM