Here is what I'm trying to do. I have a local Ubuntu mirror on my network, and I want requests for dk.archive.ubuntu.com
to be directed to the local machine.
I have added 10.0.0.15 dk.archive.ubuntu.com
to /etc/hosts on my lede router.
Somehow this isn't working quite as expected. See blow.
I suspect that the "alias" thing is messing with my setup, but my understanding of DNS isn't good enough to really know what is going on.
root@LEDE:/etc# host dk.archive.ubuntu.com
dk.archive.ubuntu.com has address 10.0.0.15
dk.archive.ubuntu.com is an alias for mirrors.dotsrc.org.
mirrors.dotsrc.org has IPv6 address 2001:878:346::116
dk.archive.ubuntu.com is an alias for mirrors.dotsrc.org.
There seem to be several ways to implement this kind of requirement, depending on the OS.
I was also searching for the most appropriate way and found this working rock stable for me:
This applies only to the machine on which you add the entry to the hosts file, in your case it would need to be done on the machine where you check "host dk.archive.ubuntu.com". But then, it is does not apply to other machines
Thanks for your reply, but I would like to avoid configuring on the individual machine. That way it won't break, when I take my laptop to another network.
So I would prefer the router dns server to provide the solution.
Well, with "On OpenWrt In" I meant that this is done on OpenWrt, I hope that this is your router.
The other option you mentioned with the hosts file is on each device and NOT on the router.
I am wondering if there is another way to describe that something is done on a router or on openwrt. Should I say "in the embedded system"?
Well, in general, dhcp is for an internal network "whereby a DHCP server dynamically assigns an IP address and other network configuration parameters to each device on a network so they can communicate with other IP network" (Wiki)
DNS in our use cases is used to resolve external hostnames.
It associates various information with domain names assigned to each of the participating entities. Most prominently, it translates more readily memorized domain names to the numerical IP addresses. (Wiki)
The config in /etc/config/dhcp is rather pointing to the possibility for applying settings for internal hosts.
Whereas it is also important to see if you want to resolve the hostname including or excluding the subdomains or: If you want to "assign" an internal ip to a specific "external" subdomain like scalews.withings.net only (without touching withings.net)
Yes you provided an example. Unfortunately there is no RFC for that.
It is a common practice for decades to do this with dnsmasq (addn-hosts=/etc/dnsmasq.hosts) if not in /etc/hosts on the host itself (if possible).
Are there any arguments why "editing /etc/dnsmasq.conf is not the suggested method"?
I would like to avoid using /etc/config/dhcp for internal and external host names and /etc/dnsmasq is "closer" to /etc/hosts.
I am totally open for improvements.
In that case, it took me long to find "an" appropriate place to do this config and to feel comfortable with.
There are tons of pro arguments and examples for dnsmasq.conf and only one for /etc/config/dhcp. I have tested both, they work perfectly fine.
All my settings for the image are in /files/usr and /files/etc, so that is perfectly fine.
Please find all information in my very first post at the top of this thread.
Backup as usual; backup list in Luci (/luci/admin/system/flashops/backupfiles) or backed up and added to the /files/etc/ folder for the next build
The file is persistent after creation.
Generally: Google for dnsmasq.conf addn-hosts brings lots of examples.
In general, /etc/config/dhcp is not used for "redirecting" external hosts to internal IPs. If /etc/config/dhcp take precendence over dnsmasq.conf then everything is totally fine. If you do conflicting config in both places, you should rather decide before you do that - which config is more important for you. Then you do only one of them in one of the two places. That is pretty logical, I hope also for noobs.
/etc/config/dhcp is not in conflict with any logic for external hosts since it might be used for internal hosts only.