TechnitiumSoftware / DnsServer

Technitium DNS Server
https://technitium.com/dns/
GNU General Public License v3.0
4.47k stars 431 forks source link

Configure a CNAME to an entry from hosts.ics file ? #379

Closed mihai-vlc closed 2 years ago

mihai-vlc commented 2 years ago

I am using hyper v on windows 10 to manage some VMs. The VMs are connected to the default virtual switch (connection type: internal network) which creates a hosts.ics file which looks something like this:

# Copyright (c) 1993-2001 Microsoft Corp.
#
# This file has been automatically generated for use by Microsoft Internet
# Connection Sharing. It contains the mappings of IP addresses to host names
# for the home network. Please do not make changes to the HOSTS.ICS file.
# Any changes may result in a loss of connectivity between machines on the
# local network.
#

172.26.33.91 dev.mshome.net # 2022 4 1 18 8 58 43 936

The IP of the dev.mshome.net changes each time the VM is rebooted.

The end result that I would like to have is: myapp.internal -> dev.mshome.net which will then read the hosts.ics file and go to the correct VM.

Is there a way to setup a CNAME record in the DNS server that somehow takes into account that hosts file ?

I am new to all these DNS concepts so I may be looking at this from the wrong perspective. I just don't know how else I could tackle this.

ShreyasZare commented 2 years ago

Thanks for the post. I haven't worked much with hyper-v but, if it runs a DNS server on its virtual network then you can just create a conditional forwarder zone in your Technitium DNS server setup for "dev.mshome.net" and point it to the IP address of that hyper-v DNS server. You can then add a CNAME record in any of you zones that point to "dev.mshome.net" and it would work.

You will need to find out the IP address for the hyper-v DNS server though by checking what DNS server is being configured by the virtual network on your VMs. Try to query those DNS servers using nslookup command to see if they are responding as expected.

Another option is to not use the default virtual switch DHCP and simply run your own DHCP server on the network to assign IP address which then gets updated in the DNS server if you use the built-in DHCP server.

mihai-vlc commented 2 years ago

I had a second look at this today.

After reading your comment I decided to stop fighting against that hyper v default virtual switch since I don't fully understand how it works.

The VMs were created with multipass and I later learned that I need to preserve that default switch adapter so multipass can continue to communicate with the VMs.

Finally I ended up with this setup (posting it here in case it might help someone in the future):

Thank you for taking the time to reply !